30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
namespace Just.PreciseMath.Tests;
|
|
|
|
public class DoubleDoubleRootFunctionsTests
|
|
{
|
|
[Fact]
|
|
public void RootsAreCanonicalAndSqrtMatchesGenericDispatchBits()
|
|
{
|
|
DoubleDouble[] values = [DoubleDouble.Zero, DoubleDouble.NegativeZero,
|
|
DoubleDouble.NaN, DoubleDouble.PositiveInfinity, DoubleDouble.NegativeInfinity,
|
|
new(-1.0), new(double.Epsilon), new(2.0), new(double.MaxValue),
|
|
DoubleDouble.FromComponents(1.0, Math.ScaleB(1.0, -1000))];
|
|
foreach (DoubleDouble value in values)
|
|
{
|
|
AssertBits(DoubleDouble.Sqrt(value), GenericSqrt(value));
|
|
DoubleDouble.IsCanonical(DoubleDouble.InvSqrt(value)).ShouldBeTrue();
|
|
}
|
|
}
|
|
|
|
private static T GenericSqrt<T>(T value) where T : IRootFunctions<T>
|
|
{
|
|
return T.Sqrt(value);
|
|
}
|
|
|
|
private static void AssertBits(DoubleDouble expected, DoubleDouble actual)
|
|
{
|
|
BitConverter.DoubleToInt64Bits(actual.High).ShouldBe(BitConverter.DoubleToInt64Bits(expected.High));
|
|
BitConverter.DoubleToInt64Bits(actual.Low).ShouldBe(BitConverter.DoubleToInt64Bits(expected.Low));
|
|
}
|
|
}
|