fixed multiplication asymmetry
.NET Test / .NET tests (push) Failing after 1m32s

This commit is contained in:
2026-09-19 20:02:33 +04:00
parent 620faca7eb
commit 34076c2466
3 changed files with 105 additions and 6 deletions
@@ -81,7 +81,8 @@ public class ArithmeticRangeTests
public void FiniteKernelsPreservePreviousComponentBits(string operation)
{
// Differential characterization, not an independent accuracy oracle.
// Freeze the previous four-TwoSum/FMA expressions and public normalization;
// Freeze the previous four-TwoSum/FMA expressions and public normalization,
// with multiplication evaluated in its deterministic operand order;
// independent exact/rational accuracy cases remain in the arithmetic suites.
List<DoubleDouble> values = [new(0.0), new(-0.0)];
int[] exponents = [-1074, -1022, -901, -900, -899, -451, -450, -1, 0, 1,
@@ -154,10 +155,18 @@ public class ArithmeticRangeTests
{
continue;
}
(double product, double error) = PreciseMathHelper.TwoMultiply(left.High, right.High);
error = Math.FusedMultiplyAdd(left.High, right.Low, error);
error = Math.FusedMultiplyAdd(left.Low, right.High, error);
error = Math.FusedMultiplyAdd(left.Low, right.Low, error);
// Operand ordering intentionally changes the old unordered
// result bits, not the FMA kernel or its normalization.
DoubleDouble first = left;
DoubleDouble second = right;
if (first.High > second.High || (first.High == second.High && first.Low > second.Low))
{
(first, second) = (second, first);
}
(double product, double error) = PreciseMathHelper.TwoMultiply(first.High, second.High);
error = Math.FusedMultiplyAdd(first.High, second.Low, error);
error = Math.FusedMultiplyAdd(first.Low, second.High, error);
error = Math.FusedMultiplyAdd(first.Low, second.Low, error);
Math.Abs(error).ShouldBeLessThan(Math.Abs(product));
expected = DoubleDouble.FromComponents(product, error);
actual = left * right;