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
@@ -2,6 +2,55 @@ namespace Just.PreciseMath.Tests;
public class DoubleDoubleArithmeticTests
{
[Theory]
[InlineData("+")]
[InlineData("-")]
[InlineData("*")]
[InlineData("/")]
public void NamedArithmeticMatchesOperatorComponentBits(string operation)
{
// Compatibility, not an accuracy oracle. The existing rational tests
// independently validate the kernels reached through these operators.
DoubleDouble[] values = MultiplicationCommutativityCases();
foreach (DoubleDouble left in values)
{
foreach (DoubleDouble right in values)
{
(DoubleDouble actual, DoubleDouble expected)[] pairs = operation switch
{
"+" => [(DoubleDouble.Add(left, right), left + right),
(DoubleDouble.Add(left, right.High), left + right.High),
(DoubleDouble.Add(left.High, right), left.High + right)],
"-" => [(DoubleDouble.Subtract(left, right), left - right),
(DoubleDouble.Subtract(left, right.High), left - right.High),
(DoubleDouble.Subtract(left.High, right), left.High - right)],
"*" => [(DoubleDouble.Multiply(left, right), left * right),
(DoubleDouble.Multiply(left, right.High), left * right.High),
(DoubleDouble.Multiply(left.High, right), left.High * right)],
"/" => [(DoubleDouble.Divide(left, right), left / right),
(DoubleDouble.Divide(left, right.High), left / right.High),
(DoubleDouble.Divide(left.High, right), left.High / right)],
_ => throw new ArgumentOutOfRangeException(nameof(operation))
};
foreach ((DoubleDouble actual, DoubleDouble expected) in pairs)
{
CheckBoundary(actual, expected.High, expected.Low);
}
}
}
}
[Fact]
public void NamedUnaryArithmeticMatchesOperatorComponentBits()
{
foreach (DoubleDouble value in MultiplicationCommutativityCases())
{
CheckBoundary(DoubleDouble.Plus(value), value.High, value.Low);
DoubleDouble negated = -value;
CheckBoundary(DoubleDouble.Negate(value), negated.High, negated.Low);
}
}
[Theory]
[InlineData(6.0, 2.0, 8.0, 4.0, 12.0, 3.0)]
[InlineData(-6.0, 2.0, -4.0, -8.0, -12.0, -3.0)]
@@ -1050,7 +1099,7 @@ public class DoubleDoubleArithmeticTests
foreach (double sign in new[] { -1.0, 1.0 })
{
CheckBoundary(DoubleDouble.Square(sign * below), Math.BitDecrement(highSquared), Math.ScaleB(1.0, (2 * exponent) - 108));
CheckBoundary(DDMath.Square(sign * above), Math.BitIncrement(highSquared), Math.ScaleB(1.0, (2 * exponent) - 106));
CheckBoundary(DoubleDouble.Square(sign * above), Math.BitIncrement(highSquared), Math.ScaleB(1.0, (2 * exponent) - 106));
}
}
@@ -1060,7 +1109,6 @@ public class DoubleDoubleArithmeticTests
foreach (double value in new[] { 0.0, -0.0, double.NaN, double.PositiveInfinity, double.NegativeInfinity })
{
CheckBits(DoubleDouble.Square(new DoubleDouble(value)), value * value);
CheckBits(DDMath.Square(new DoubleDouble(value)), value * value);
}
for (int exponent = -1074; exponent <= 1023; exponent++)
{
@@ -1139,7 +1187,6 @@ public class DoubleDoubleArithmeticTests
DoubleDouble.IsZero(actual).ShouldBe((numerator << 1) <= denominator);
}
CheckBoundary(DoubleDouble.Square(-value), actual.High, actual.Low);
CheckBoundary(DDMath.Square(value), actual.High, actual.Low);
}
private static DoubleDouble[] MultiplicationCommutativityCases()