From fd68d1c65622e09b2c8d8a81fe88d98cf386b48e Mon Sep 17 00:00:00 2001 From: Anthony Lloyd Date: Thu, 30 Nov 2023 22:02:55 +0000 Subject: [PATCH] doubles performance --- CsCheck/Check.cs | 3 ++- Tests/FloatingPointTests.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CsCheck/Check.cs b/CsCheck/Check.cs index ad44f54..05a18db 100644 --- a/CsCheck/Check.cs +++ b/CsCheck/Check.cs @@ -3222,7 +3222,8 @@ public override string ToString() spinLock.Enter(ref lockTaken); if (!processing) { - var result = $"{Median.Median * 100.0:#0.00}%[{Median.Q1 * 100.0:#0.00}%..{Median.Q3 * 100.0:#0.00}%] {(Median.Median >= 0.0 ? "faster" : "slower")}"; + var times = 1 / (1 - Math.Abs(Median.Median)); + var result = $"{Median.Median * 100.0:#0.00}%[{Median.Q1 * 100.0:#0.00}%..{Median.Q3 * 100.0:#0.00}%] {times:#0.00}x {(Median.Median >= 0.0 ? "faster" : "slower")}"; if (double.IsNaN(Median.Median)) result = $"Time resolution too small try using repeat.\n{result}"; else if ((Median.Median >= 0.0) != (Faster > Slower)) result = $"Inconsistent result try using repeat or increasing sigma.\n{result}"; result = $"{result}, sigma={Math.Sqrt(SigmaSquared):#0.0} ({Faster:#,0} vs {Slower:#,0})"; diff --git a/Tests/FloatingPointTests.cs b/Tests/FloatingPointTests.cs index dc20164..4ff4b46 100644 --- a/Tests/FloatingPointTests.cs +++ b/Tests/FloatingPointTests.cs @@ -30,6 +30,16 @@ public void DoubleSupportsRoundtripPrecisionTo15() }, writeLine: output.WriteLine); } + [Fact] + public void X() + { + var quantity = 1000; + var price = 99.99; + var fxRate = 1.2345; + var localValue = MathX.TwoMul(quantity, price, out double lo1); + var usdValue = MathX.TwoMul(localValue, fxRate, out double lo2); + } + private static void DoubleSumPrecision(int significantFigures, int maxLength) { const double scaling = 0.01;