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
@@ -6,17 +6,17 @@ public class PreciseMathPowTests
public void NegativePowerDoesNotOverflowBeforeReciprocation()
{
// Legacy review: Pow(2, -1024) overflowed before taking the reciprocal.
DoubleDouble actual = DDMath.Pow(new DoubleDouble(2.0), -1024);
DoubleDouble actual = DoubleDouble.Pow(new DoubleDouble(2.0), -1024);
AssertBits(actual, Math.ScaleB(1.0, -1024), 0.0);
}
[Fact]
public void MinimumIntegerExponentDoesNotOverflowItsMagnitude()
{
AssertBits(DDMath.Pow(DoubleDouble.One, int.MinValue), 1.0, 0.0);
AssertBits(DDMath.Pow(DoubleDouble.NegativeOne, int.MinValue), 1.0, 0.0);
AssertBits(DDMath.Pow(new DoubleDouble(2.0), int.MinValue), 0.0, 0.0);
AssertBits(DDMath.Pow(new DoubleDouble(0.5), int.MinValue), double.PositiveInfinity, 0.0);
AssertBits(DoubleDouble.Pow(DoubleDouble.One, int.MinValue), 1.0, 0.0);
AssertBits(DoubleDouble.Pow(DoubleDouble.NegativeOne, int.MinValue), 1.0, 0.0);
AssertBits(DoubleDouble.Pow(new DoubleDouble(2.0), int.MinValue), 0.0, 0.0);
AssertBits(DoubleDouble.Pow(new DoubleDouble(0.5), int.MinValue), double.PositiveInfinity, 0.0);
}
[Fact]
@@ -25,7 +25,7 @@ public class PreciseMathPowTests
foreach (double sign in new[] { -1.0, 1.0 })
{
DoubleDouble input = DoubleDouble.FromComponents(sign * double.MaxValue, sign * double.Epsilon);
AssertBits(DDMath.Pow(input, 1), input.High, input.Low);
AssertBits(DoubleDouble.Pow(input, 1), input.High, input.Low);
}
}
@@ -42,7 +42,7 @@ public class PreciseMathPowTests
// Every int converts exactly to double. BCL is an independent
// special-value/sign oracle, not the finite precision oracle.
double expected = Math.Pow(input, exponent);
AssertBits(DDMath.Pow(new DoubleDouble(input), exponent),
AssertBits(DoubleDouble.Pow(new DoubleDouble(input), exponent),
double.IsNaN(expected) ? double.NaN : expected, 0.0);
}
}
@@ -63,7 +63,7 @@ public class PreciseMathPowTests
foreach (double sign in new[] { -1.0, 1.0 })
{
double expected = sign < 0.0 && (power & 1) != 0 ? -magnitude : magnitude;
AssertBits(DDMath.Pow(new DoubleDouble(sign * Math.ScaleB(1.0, inputExponent)), power),
AssertBits(DoubleDouble.Pow(new DoubleDouble(sign * Math.ScaleB(1.0, inputExponent)), power),
expected, 0.0);
}
}
@@ -118,13 +118,13 @@ public class PreciseMathPowTests
AssertExactPowerBound(input, -1);
if (scale == -500 || scale == 500)
{
DoubleDouble actual = DDMath.Pow(input, -2);
DoubleDouble actual = DoubleDouble.Pow(input, -2);
actual.Low.ShouldNotBe(0.0);
AssertExactPowerBound(input, -2);
}
if (scale < 0)
{
DDMath.Pow(input, -1).Low.ShouldNotBe(0.0);
DoubleDouble.Pow(input, -1).Low.ShouldNotBe(0.0);
}
}
}
@@ -141,11 +141,11 @@ public class PreciseMathPowTests
foreach (double sign in new[] { -1.0, 1.0 })
{
DoubleDouble tiny = DoubleDouble.FromComponents(Math.ScaleB(1.0, -500), sign * double.Epsilon);
AssertBits(DDMath.Pow(tiny, -1), Math.ScaleB(1.0, 500), -sign * Math.ScaleB(1.0, -74));
AssertBits(DoubleDouble.Pow(tiny, -1), Math.ScaleB(1.0, 500), -sign * Math.ScaleB(1.0, -74));
DoubleDouble huge = DoubleDouble.FromComponents(Math.ScaleB(1.0, 500), sign * Math.ScaleB(1.0, -74));
AssertBits(DDMath.Pow(huge, -1), Math.ScaleB(1.0, -500), -sign * double.Epsilon);
AssertBits(DoubleDouble.Pow(huge, -1), Math.ScaleB(1.0, -500), -sign * double.Epsilon);
DoubleDouble tinySquare = DoubleDouble.FromComponents(Math.ScaleB(1.0, -250), sign * double.Epsilon);
AssertBits(DDMath.Pow(tinySquare, -2), Math.ScaleB(1.0, 500), -sign * Math.ScaleB(1.0, -323));
AssertBits(DoubleDouble.Pow(tinySquare, -2), Math.ScaleB(1.0, 500), -sign * Math.ScaleB(1.0, -323));
}
}
@@ -165,7 +165,7 @@ public class PreciseMathPowTests
{
DoubleDouble input = DoubleDouble.FromComponents(sign * Math.ScaleB(1.0, scale),
sign * lowSign * Math.ScaleB(1.0, scale - 54));
AssertBits(DDMath.Pow(input, exponent), sign * (aboveTie ? double.Epsilon : 0.0), 0.0);
AssertBits(DoubleDouble.Pow(input, exponent), sign * (aboveTie ? double.Epsilon : 0.0), 0.0);
}
}
}
@@ -183,7 +183,7 @@ public class PreciseMathPowTests
AssertExactPowerBound(finite, exponent);
DoubleDouble overflowing = DoubleDouble.FromComponents(Math.ScaleB(1.0, scale),
lowSign * Math.ScaleB(1.0, scale - 57));
AssertBits(DDMath.Pow(overflowing, exponent), double.PositiveInfinity, 0.0);
AssertBits(DoubleDouble.Pow(overflowing, exponent), double.PositiveInfinity, 0.0);
}
}
@@ -208,7 +208,7 @@ public class PreciseMathPowTests
foreach (double sign in new[] { -1.0, 1.0 })
{
DoubleDouble input = DoubleDouble.FromComponents(sign * high, sign * low);
DoubleDouble actual = DDMath.Pow(input, exponent);
DoubleDouble actual = DoubleDouble.Pow(input, exponent);
actual.Low.ShouldNotBe(0.0);
int resultSign = sign < 0.0 && (exponent & 1) != 0 ? -1 : 1;
// Check both interval endpoints so the reference uncertainty is not
@@ -239,7 +239,7 @@ public class PreciseMathPowTests
{
(numerator, denominator) = (denominator * numerator.Sign, BigInteger.Abs(numerator));
}
AssertRationalBound(DDMath.Pow(input, exponent), numerator, denominator, exponent,
AssertRationalBound(DoubleDouble.Pow(input, exponent), numerator, denominator, exponent,
$"({input.High:R}, {input.Low:R})^{exponent}");
}