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,10 +10,10 @@ public class PreciseMathRealPowSpecialTests
DoubleDouble.FromComponents(double.MaxValue, double.Epsilon)];
foreach (DoubleDouble value in values)
{
AssertBits(DDMath.Pow(value, 0.0), DoubleDouble.One);
AssertBits(DDMath.Pow(value, new DoubleDouble(-0.0)), DoubleDouble.One);
AssertBits(DDMath.Pow(value, 1.0), value);
AssertBits(DDMath.Pow(value, DoubleDouble.One), value);
AssertBits(DoubleDouble.Pow(value, 0.0), DoubleDouble.One);
AssertBits(DoubleDouble.Pow(value, new DoubleDouble(-0.0)), DoubleDouble.One);
AssertBits(DoubleDouble.Pow(value, 1.0), value);
AssertBits(DoubleDouble.Pow(value, DoubleDouble.One), value);
}
}
@@ -37,8 +37,8 @@ public class PreciseMathRealPowSpecialTests
continue;
}
DoubleDouble input = new(value);
AssertBits(DDMath.Pow(input, exponent), new DoubleDouble(expected));
AssertBits(DDMath.Pow(input, new DoubleDouble(exponent)), new DoubleDouble(expected));
AssertBits(DoubleDouble.Pow(input, exponent), new DoubleDouble(expected));
AssertBits(DoubleDouble.Pow(input, new DoubleDouble(exponent)), new DoubleDouble(expected));
}
}
}
@@ -53,27 +53,27 @@ public class PreciseMathRealPowSpecialTests
DoubleDouble odd = DoubleDouble.FromComponents(direction * high, 1.0);
DoubleDouble even = DoubleDouble.FromComponents(direction * high, 2.0);
DoubleDouble fractional = DoubleDouble.FromComponents(direction * high, 0.5);
AssertBits(DDMath.Pow(DoubleDouble.NegativeOne, odd), DoubleDouble.NegativeOne);
AssertBits(DDMath.Pow(DoubleDouble.NegativeOne, even), DoubleDouble.One);
AssertBits(DDMath.Pow(DoubleDouble.NegativeOne, fractional), DoubleDouble.NaN);
AssertBits(DDMath.Pow(new DoubleDouble(-2.0), odd),
AssertBits(DoubleDouble.Pow(DoubleDouble.NegativeOne, odd), DoubleDouble.NegativeOne);
AssertBits(DoubleDouble.Pow(DoubleDouble.NegativeOne, even), DoubleDouble.One);
AssertBits(DoubleDouble.Pow(DoubleDouble.NegativeOne, fractional), DoubleDouble.NaN);
AssertBits(DoubleDouble.Pow(new DoubleDouble(-2.0), odd),
new DoubleDouble(direction > 0.0 ? double.NegativeInfinity : -0.0));
AssertBits(DDMath.Pow(new DoubleDouble(-0.5), odd),
AssertBits(DoubleDouble.Pow(new DoubleDouble(-0.5), odd),
new DoubleDouble(direction > 0.0 ? -0.0 : double.NegativeInfinity));
AssertBits(DDMath.Pow(new DoubleDouble(-2.0), even),
AssertBits(DoubleDouble.Pow(new DoubleDouble(-2.0), even),
new DoubleDouble(direction > 0.0 ? double.PositiveInfinity : 0.0));
AssertBits(DDMath.Pow(new DoubleDouble(-0.0), odd),
AssertBits(DoubleDouble.Pow(new DoubleDouble(-0.0), odd),
new DoubleDouble(direction > 0.0 ? -0.0 : double.NegativeInfinity));
AssertBits(DDMath.Pow(new DoubleDouble(double.NegativeInfinity), odd),
AssertBits(DoubleDouble.Pow(new DoubleDouble(double.NegativeInfinity), odd),
new DoubleDouble(direction > 0.0 ? double.NegativeInfinity : -0.0));
AssertBits(DDMath.Pow(new DoubleDouble(-0.0), fractional),
AssertBits(DoubleDouble.Pow(new DoubleDouble(-0.0), fractional),
new DoubleDouble(direction > 0.0 ? 0.0 : double.PositiveInfinity));
AssertBits(DDMath.Pow(new DoubleDouble(double.NegativeInfinity), fractional),
AssertBits(DoubleDouble.Pow(new DoubleDouble(double.NegativeInfinity), fractional),
new DoubleDouble(direction > 0.0 ? double.PositiveInfinity : 0.0));
}
}
DoubleDouble belowInteger = DoubleDouble.FromComponents(3.0, -double.Epsilon);
AssertBits(DDMath.Pow(new DoubleDouble(-2.0), belowInteger), DoubleDouble.NaN);
AssertBits(DoubleDouble.Pow(new DoubleDouble(-2.0), belowInteger), DoubleDouble.NaN);
}
[Fact]
@@ -84,9 +84,9 @@ public class PreciseMathRealPowSpecialTests
foreach (double sign in new[] { -1.0, 1.0 })
{
DoubleDouble value = DoubleDouble.FromComponents(sign, sign * low);
AssertBits(DDMath.Pow(value, double.PositiveInfinity),
AssertBits(DoubleDouble.Pow(value, double.PositiveInfinity),
new DoubleDouble(low > 0.0 ? double.PositiveInfinity : 0.0));
AssertBits(DDMath.Pow(value, new DoubleDouble(double.NegativeInfinity)),
AssertBits(DoubleDouble.Pow(value, new DoubleDouble(double.NegativeInfinity)),
new DoubleDouble(low < 0.0 ? double.PositiveInfinity : 0.0));
}
}
@@ -102,11 +102,11 @@ public class PreciseMathRealPowSpecialTests
{
foreach (int exponent in exponents)
{
DoubleDouble expected = DDMath.Pow(value, exponent);
DoubleDouble expected = DoubleDouble.Pow(value, exponent);
// Dispatch consistency, not an accuracy oracle: the integer suite
// separately checks these algorithms against independent references.
AssertBits(DDMath.Pow(value, (double)exponent), expected);
AssertBits(DDMath.Pow(value, new DoubleDouble(exponent)), expected);
AssertBits(DoubleDouble.Pow(value, (double)exponent), expected);
AssertBits(DoubleDouble.Pow(value, new DoubleDouble(exponent)), expected);
}
}
}
@@ -116,8 +116,8 @@ public class PreciseMathRealPowSpecialTests
{
// Independently rounded sqrt(2) binary64 components; also used by the
// constant-reference generator. Compare components, not high+low in double.
foreach (DoubleDouble actual in new[] { DDMath.Pow(new DoubleDouble(2.0), 0.5),
DDMath.Pow(new DoubleDouble(2.0), new DoubleDouble(0.5)) })
foreach (DoubleDouble actual in new[] { DoubleDouble.Pow(new DoubleDouble(2.0), 0.5),
DoubleDouble.Pow(new DoubleDouble(2.0), new DoubleDouble(0.5)) })
{
actual.High.ShouldBe(1.4142135623730951);
Math.Abs(actual.Low - -9.667293313452913e-17).ShouldBeLessThan(Math.ScaleB(1.0, -90));
@@ -132,8 +132,8 @@ public class PreciseMathRealPowSpecialTests
{
// 4^-537.25 = 2^-1074.5 lies above the half-epsilon threshold;
// 4^-537.75 = 2^-1075.5 lies below it. These are well separated from ties.
foreach (DoubleDouble actual in new[] { DDMath.Pow(new DoubleDouble(4.0), exponent),
DDMath.Pow(new DoubleDouble(4.0), new DoubleDouble(exponent)) })
foreach (DoubleDouble actual in new[] { DoubleDouble.Pow(new DoubleDouble(4.0), exponent),
DoubleDouble.Pow(new DoubleDouble(4.0), new DoubleDouble(exponent)) })
{
BitConverter.DoubleToInt64Bits(actual.High).ShouldBe(expectedBits);
BitConverter.DoubleToInt64Bits(actual.Low).ShouldBe(0L);
@@ -149,8 +149,8 @@ public class PreciseMathRealPowSpecialTests
{
bool grows = (value > 1.0) == (exponent > 0.0);
DoubleDouble expected = new(grows ? double.PositiveInfinity : 0.0);
AssertBits(DDMath.Pow(new DoubleDouble(value), exponent), expected);
AssertBits(DDMath.Pow(new DoubleDouble(value), new DoubleDouble(exponent)), expected);
AssertBits(DoubleDouble.Pow(new DoubleDouble(value), exponent), expected);
AssertBits(DoubleDouble.Pow(new DoubleDouble(value), new DoubleDouble(exponent)), expected);
}
}
}