operators refactoring
.NET Test / .NET tests (push) Successful in 2m11s

This commit is contained in:
2026-09-24 00:39:59 +04:00
parent 3de9457fdc
commit ac93744579
26 changed files with 651 additions and 334 deletions
@@ -10,7 +10,7 @@ public class PreciseMathSqrtTests
[InlineData(2.25, 1.5)]
public void ExactBinarySquaresHaveExactRoots(double square, double root)
{
DoubleDouble actual = DDMath.Sqrt(new DoubleDouble(square));
DoubleDouble actual = DoubleDouble.Sqrt(new DoubleDouble(square));
actual.High.ShouldBe(root);
BitConverter.DoubleToInt64Bits(actual.Low).ShouldBe(0L);
}
@@ -21,7 +21,7 @@ public class PreciseMathSqrtTests
// sqrt(2^(2k)) = 2^k exactly, including the minimum subnormal input.
for (int exponent = -1074; exponent <= 1022; exponent += 2)
{
DoubleDouble actual = DDMath.Sqrt(new DoubleDouble(Math.ScaleB(1.0, exponent)));
DoubleDouble actual = DoubleDouble.Sqrt(new DoubleDouble(Math.ScaleB(1.0, exponent)));
actual.High.ShouldBe(Math.ScaleB(1.0, exponent / 2));
BitConverter.DoubleToInt64Bits(actual.Low).ShouldBe(0L);
}
@@ -36,7 +36,7 @@ public class PreciseMathSqrtTests
public void IrrationalRootsRetainMoreThanBinary64Precision(double value)
{
DoubleDouble input = new(value);
DoubleDouble actual = DDMath.Sqrt(input);
DoubleDouble actual = DoubleDouble.Sqrt(input);
actual.Low.ShouldNotBe(0.0);
AssertSqrtBound(input, actual);
}
@@ -47,7 +47,7 @@ public class PreciseMathSqrtTests
foreach (double low in new[] { Math.ScaleB(1.0, -54), -Math.ScaleB(1.0, -54) })
{
DoubleDouble input = DoubleDouble.FromComponents(1.0, low);
DoubleDouble actual = DDMath.Sqrt(input);
DoubleDouble actual = DoubleDouble.Sqrt(input);
actual.High.ShouldBe(1.0);
(Math.Sign(actual.Low) == Math.Sign(low)).ShouldBeTrue();
AssertSqrtBound(input, actual);
@@ -61,7 +61,7 @@ public class PreciseMathSqrtTests
double.NaN, -1.0, -double.Epsilon, double.MinValue];
foreach (double value in values)
{
DoubleDouble actual = DDMath.Sqrt(new DoubleDouble(value));
DoubleDouble actual = DoubleDouble.Sqrt(new DoubleDouble(value));
double expected = Math.Sqrt(value);
// Construction canonicalizes all NaNs to double.NaN, including
// domain errors; zeros must instead be compared by their sign bits.
@@ -72,7 +72,7 @@ public class PreciseMathSqrtTests
}
DoubleDouble negative = DoubleDouble.FromComponents(-1.0, Math.ScaleB(1.0, -54));
DoubleDouble.IsNaN(DDMath.Sqrt(negative)).ShouldBeTrue();
DoubleDouble.IsNaN(DoubleDouble.Sqrt(negative)).ShouldBeTrue();
}
[Fact]
@@ -92,7 +92,7 @@ public class PreciseMathSqrtTests
if (boundary > 0.0)
{
DoubleDouble input = new(boundary);
AssertSqrtBound(input, DDMath.Sqrt(input));
AssertSqrtBound(input, DoubleDouble.Sqrt(input));
}
}
foreach (double residual in new[] { 0.0, low, -low, double.Epsilon, -double.Epsilon })
@@ -100,7 +100,7 @@ public class PreciseMathSqrtTests
DoubleDouble input = DoubleDouble.FromComponents(high, residual);
if (input.High > 0.0)
{
AssertSqrtBound(input, DDMath.Sqrt(input));
AssertSqrtBound(input, DoubleDouble.Sqrt(input));
}
}
}
@@ -120,7 +120,7 @@ public class PreciseMathSqrtTests
DoubleDouble.FromComponents(4.0, -Math.ScaleB(1.0, -52))];
foreach (DoubleDouble input in boundaries)
{
AssertSqrtBound(input, DDMath.Sqrt(input));
AssertSqrtBound(input, DoubleDouble.Sqrt(input));
}
}
@@ -142,7 +142,7 @@ public class PreciseMathSqrtTests
DoubleDouble input = DoubleDouble.FromComponents(Math.ScaleB(high, exponent), Math.ScaleB(low, exponent));
if (DoubleDouble.IsFinite(input) && input.High > 0.0)
{
AssertSqrtBound(input, DDMath.Sqrt(input));
AssertSqrtBound(input, DoubleDouble.Sqrt(input));
}
}
}
@@ -156,9 +156,9 @@ public class PreciseMathSqrtTests
foreach (double low in new[] { double.Epsilon, 1e-308, 2.0, double.MaxValue })
{
DoubleDouble input = DoubleDouble.FromComponents(0.0, low);
AssertSqrtBound(input, DDMath.Sqrt(input));
AssertSqrtBound(input, DoubleDouble.Sqrt(input));
}
DoubleDouble.IsNaN(DDMath.Sqrt(DoubleDouble.FromComponents(0.0, -1.0))).ShouldBeTrue();
DoubleDouble.IsNaN(DoubleDouble.Sqrt(DoubleDouble.FromComponents(0.0, -1.0))).ShouldBeTrue();
}
[Fact]
@@ -177,7 +177,7 @@ public class PreciseMathSqrtTests
DoubleDouble input = DoubleDouble.FromComponents(high, low);
if (DoubleDouble.IsFinite(input) && input.High > 0.0)
{
AssertSqrtBound(input, DDMath.Sqrt(input));
AssertSqrtBound(input, DoubleDouble.Sqrt(input));
}
}
}
@@ -194,7 +194,7 @@ public class PreciseMathSqrtTests
foreach (double sign in new[] { -1.0, 1.0 })
{
double low = Math.ScaleB(sign, exponent);
DoubleDouble actual = DDMath.Sqrt(DoubleDouble.FromComponents(1.0, low));
DoubleDouble actual = DoubleDouble.Sqrt(DoubleDouble.FromComponents(1.0, low));
actual.High.ShouldBe(1.0);
actual.Low.ShouldBe(Math.ScaleB(sign, exponent - 1));
DoubleDouble.IsCanonical(actual).ShouldBeTrue();
@@ -358,9 +358,6 @@ public class PreciseMathSqrtTests
DoubleDouble actual = DoubleDouble.Sqrt(input);
actual.High.ShouldBe(high);
BitConverter.DoubleToInt64Bits(actual.Low).ShouldBe(BitConverter.DoubleToInt64Bits(low));
DoubleDouble facade = DDMath.Sqrt(input);
BitConverter.DoubleToInt64Bits(facade.High).ShouldBe(BitConverter.DoubleToInt64Bits(actual.High));
BitConverter.DoubleToInt64Bits(facade.Low).ShouldBe(BitConverter.DoubleToInt64Bits(actual.Low));
AssertSqrtBound(input, actual);
}