mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-12 23:55:41 +00:00
Compare commits
1 Commits
31eeaec94e
...
8ee2499961
Author | SHA1 | Date | |
---|---|---|---|
|
8ee2499961 |
@ -1,32 +0,0 @@
|
|||||||
#if NET7_0_OR_GREATER
|
|
||||||
using NUnit.Framework;
|
|
||||||
using X10D.Math;
|
|
||||||
|
|
||||||
namespace X10D.Tests.Numerics;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class NumberTests
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Sign_ShouldReturn1_GivenPositiveNumber()
|
|
||||||
{
|
|
||||||
Assert.That(NumberExtensions.Sign(2), Is.Positive);
|
|
||||||
Assert.That(NumberExtensions.Sign(2), Is.EqualTo(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Sign_Should0_GivenZero()
|
|
||||||
{
|
|
||||||
Assert.That(NumberExtensions.Sign(0), Is.Not.Positive);
|
|
||||||
Assert.That(NumberExtensions.Sign(0), Is.Not.Negative);
|
|
||||||
Assert.That(NumberExtensions.Sign(0), Is.EqualTo(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Sign_ShouldReturnNegative1_GivenNegativeNumber()
|
|
||||||
{
|
|
||||||
Assert.That(NumberExtensions.Sign(-2), Is.Negative);
|
|
||||||
Assert.That(NumberExtensions.Sign(-2), Is.EqualTo(-1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||||||
#if NET7_0_OR_GREATER
|
#if NET7_0_OR_GREATER
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -49,28 +48,6 @@ public static class BinaryIntegerExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UnpackInternal(value, destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
|
||||||
private static void UnpackInternal_Fallback<TInteger>(this TInteger value, Span<bool> destination)
|
|
||||||
where TInteger : unmanaged, IBinaryInteger<TInteger>
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
int bitCount = sizeof(TInteger) * 8;
|
|
||||||
for (var index = 0; index < bitCount; index++)
|
|
||||||
{
|
|
||||||
destination[index] = (value & (TInteger.One << index)) != TInteger.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ExcludeFromCodeCoverage]
|
|
||||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
|
||||||
private static void UnpackInternal<TInteger>(TInteger value, Span<bool> destination)
|
|
||||||
where TInteger : unmanaged, IBinaryInteger<TInteger>
|
|
||||||
{
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case byte valueByte when Sse3.IsSupported:
|
case byte valueByte when Sse3.IsSupported:
|
||||||
@ -94,5 +71,19 @@ public static class BinaryIntegerExtensions
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||||
|
internal static void UnpackInternal_Fallback<TInteger>(this TInteger value, Span<bool> destination)
|
||||||
|
where TInteger : unmanaged, IBinaryInteger<TInteger>
|
||||||
|
{
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
int bitCount = sizeof(TInteger) * 8;
|
||||||
|
for (var index = 0; index < bitCount; index++)
|
||||||
|
{
|
||||||
|
destination[index] = (value & (TInteger.One << index)) != TInteger.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user