From 5f8b9135cc2de52369a509792db578156368932f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 19 Nov 2023 21:26:28 +1300 Subject: [PATCH] Fix director_classes testcase failures on x86 Adjust the floating point constants to be 1.125 and 2.25 (which can be exactly represented in base-2 floating point) instead of 1.1 and 2.2 (which can't). This avoids problems on platforms where floating point calculations suffer from excess precision, the most commonly used of which is x86 when using 387 FP instructions. --- .../test-suite/csharp/director_classes_runme.cs | 16 ++++++++-------- Examples/test-suite/d/director_classes_runme.2.d | 16 ++++++++-------- Examples/test-suite/director_classes.i | 8 ++++---- .../test-suite/java/director_classes_runme.java | 16 ++++++++-------- .../test-suite/php/director_classes_runme.php | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Examples/test-suite/csharp/director_classes_runme.cs b/Examples/test-suite/csharp/director_classes_runme.cs index cea4949c6..25bb35968 100644 --- a/Examples/test-suite/csharp/director_classes_runme.cs +++ b/Examples/test-suite/csharp/director_classes_runme.cs @@ -21,8 +21,8 @@ Base - FullyOverloaded(int 10) Base - FullyOverloaded(bool 1) Base - SemiOverloaded(int -678) Base - SemiOverloaded(bool 1) -Base - DefaultParms(10, 2.2) -Base - DefaultParms(10, 1.1) +Base - DefaultParms(10, 2.25) +Base - DefaultParms(10, 1.125) -------------------------------- Derived - Val(444.555) Derived - Ref(444.555) @@ -32,8 +32,8 @@ Derived - FullyOverloaded(int 10) Derived - FullyOverloaded(bool 1) Derived - SemiOverloaded(int -678) Base - SemiOverloaded(bool 1) -Derived - DefaultParms(10, 2.2) -Derived - DefaultParms(10, 1.1) +Derived - DefaultParms(10, 2.25) +Derived - DefaultParms(10, 1.125) -------------------------------- CSharpDerived - Val(444.555) CSharpDerived - Ref(444.555) @@ -43,8 +43,8 @@ CSharpDerived - FullyOverloaded(int 10) CSharpDerived - FullyOverloaded(bool True) CSharpDerived - SemiOverloaded(-678) Base - SemiOverloaded(bool 1) -CSharpDerived - DefaultParms(10, 2.2) -CSharpDerived - DefaultParms(10, 1.1) +CSharpDerived - DefaultParms(10, 2.25) +CSharpDerived - DefaultParms(10, 1.125) ------------ Finish ------------ */ @@ -113,7 +113,7 @@ public class runme if (myCaller.SemiOverloadedCall(true) != "Base" + "::SemiOverloaded(bool)") throw new Exception("failed"); // Default parameters methods test - if (NAMESPACE + myCaller.DefaultParmsCall(10, 2.2) != myBase.GetType() + "::DefaultParms(int, double)") throw new Exception("failed"); + if (NAMESPACE + myCaller.DefaultParmsCall(10, 2.25) != myBase.GetType() + "::DefaultParms(int, double)") throw new Exception("failed"); if (myBase.GetType() == typeof(CSharpDerived)) { // special handling for C# derived classes, there is no way to do this any other way if (NAMESPACE + myCaller.DefaultParmsCall(10) != myBase.GetType() + "::DefaultParms(int, double)") throw new Exception("failed"); } else { @@ -182,7 +182,7 @@ public class CSharpDerived : Base public override String DefaultParms(int x) { if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - DefaultParms({0})", x); - return DefaultParms(x, 1.1/*use C++ default here*/); + return DefaultParms(x, 1.125/*use C++ default here*/); } } diff --git a/Examples/test-suite/d/director_classes_runme.2.d b/Examples/test-suite/d/director_classes_runme.2.d index b16fa5461..5e9588b31 100644 --- a/Examples/test-suite/d/director_classes_runme.2.d +++ b/Examples/test-suite/d/director_classes_runme.2.d @@ -23,8 +23,8 @@ * Base - FullyOverloaded(bool 1) * Base - SemiOverloaded(int -678) * Base - SemiOverloaded(bool 1) - * Base - DefaultParms(10, 2.2) - * Base - DefaultParms(10, 1.1) + * Base - DefaultParms(10, 2.25) + * Base - DefaultParms(10, 1.125) * -------------------------------- * Derived - Val(444.555) * Derived - Ref(444.555) @@ -34,8 +34,8 @@ * Derived - FullyOverloaded(bool 1) * Derived - SemiOverloaded(int -678) * Base - SemiOverloaded(bool 1) - * Derived - DefaultParms(10, 2.2) - * Derived - DefaultParms(10, 1.1) + * Derived - DefaultParms(10, 2.25) + * Derived - DefaultParms(10, 1.125) * -------------------------------- * DDerived - Val(444.555) * DDerived - Ref(444.555) @@ -45,8 +45,8 @@ * DDerived - FullyOverloaded(bool true) * DDerived - SemiOverloaded(-678) * Base - SemiOverloaded(bool 1) - * DDerived - DefaultParms(10, 2.2) - * DDerived - DefaultParms(10, 1.1) + * DDerived - DefaultParms(10, 2.25) + * DDerived - DefaultParms(10, 1.125) * ------------ Finish ------------ */ module director_classes_runme; @@ -111,7 +111,7 @@ void makeCalls(Caller myCaller, Base myBase) { enforce(myCaller.SemiOverloadedCall(true) == "Base" ~ "::SemiOverloaded(bool)", "[7] failed"); // Default parameters methods test - enforce(myCaller.DefaultParmsCall(10, 2.2) == myBaseType ~ "::DefaultParms(int, double)", "[8] failed"); + enforce(myCaller.DefaultParmsCall(10, 2.25) == myBaseType ~ "::DefaultParms(int, double)", "[8] failed"); if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no other way to do this enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int, double)", "[9] failed"); } else { @@ -173,6 +173,6 @@ public class DDerived : Base { // only here to ensure consistent behavior for calls from C++ and D code. public override string DefaultParms(int x) { if (PrintDebug) writefln("DDerived - DefaultParms(%s)", x); - return DefaultParms(x, 1.1/*use C++ default here*/); + return DefaultParms(x, 1.125/*use C++ default here*/); } } diff --git a/Examples/test-suite/director_classes.i b/Examples/test-suite/director_classes.i index 52342bfc8..f8c4e68e2 100644 --- a/Examples/test-suite/director_classes.i +++ b/Examples/test-suite/director_classes.i @@ -56,10 +56,10 @@ public: virtual std::string SemiOverloaded(int x) { if (PrintDebug) std::cout << "Base - SemiOverloaded(int " << x << ")" << std::endl; return "Base::SemiOverloaded(int)"; } virtual std::string SemiOverloaded(bool x) { if (PrintDebug) std::cout << "Base - SemiOverloaded(bool " << x << ")" << std::endl; return "Base::SemiOverloaded(bool)"; } - virtual std::string DefaultParms(int x, double y = 1.1) { + virtual std::string DefaultParms(int x, double y = 1.125) { if (PrintDebug) std::cout << "Base - DefaultParms(" << x << ", " << y << ")" << std::endl; std::string ret("Base::DefaultParms(int"); - if (y!=1.1) + if (y!=1.125) ret = ret + std::string(", double"); ret = ret + std::string(")"); return ret; @@ -82,10 +82,10 @@ public: virtual std::string SemiOverloaded(int x) { if (PrintDebug) std::cout << "Derived - SemiOverloaded(int " << x << ")" << std::endl; return "Derived::SemiOverloaded(int)"; } // No SemiOverloaded(bool x) - virtual std::string DefaultParms(int x, double y = 1.1) { + virtual std::string DefaultParms(int x, double y = 1.125) { if (PrintDebug) std::cout << "Derived - DefaultParms(" << x << ", " << y << ")" << std::endl; std::string ret("Derived::DefaultParms(int"); - if (y!=1.1) + if (y!=1.125) ret = ret + std::string(", double"); ret = ret + std::string(")"); return ret; diff --git a/Examples/test-suite/java/director_classes_runme.java b/Examples/test-suite/java/director_classes_runme.java index 9ee6302de..292cded7f 100644 --- a/Examples/test-suite/java/director_classes_runme.java +++ b/Examples/test-suite/java/director_classes_runme.java @@ -21,8 +21,8 @@ Base - FullyOverloaded(int 10) Base - FullyOverloaded(bool 1) Base - SemiOverloaded(int -678) Base - SemiOverloaded(bool 1) -Base - DefaultParms(10, 2.2) -Base - DefaultParms(10, 1.1) +Base - DefaultParms(10, 2.25) +Base - DefaultParms(10, 1.125) -------------------------------- Derived - Val(444.555) Derived - Ref(444.555) @@ -32,8 +32,8 @@ Derived - FullyOverloaded(int 10) Derived - FullyOverloaded(bool 1) Derived - SemiOverloaded(int -678) Base - SemiOverloaded(bool 1) -Derived - DefaultParms(10, 2.2) -Derived - DefaultParms(10, 1.1) +Derived - DefaultParms(10, 2.25) +Derived - DefaultParms(10, 1.125) -------------------------------- JavaDerived - Val(444.555) JavaDerived - Ref(444.555) @@ -43,8 +43,8 @@ JavaDerived - FullyOverloaded(int 10) JavaDerived - FullyOverloaded(bool True) JavaDerived - SemiOverloaded(-678) Base - SemiOverloaded(bool 1) -JavaDerived - DefaultParms(10, 2.2) -JavaDerived - DefaultParms(10, 1.1) +JavaDerived - DefaultParms(10, 2.25) +JavaDerived - DefaultParms(10, 1.125) ------------ Finish ------------ */ @@ -128,7 +128,7 @@ public class director_classes_runme { if (!myCaller.SemiOverloadedCall(true).equals("Base" + "::SemiOverloaded(bool)")) throw new RuntimeException("failed"); // Default parameters methods test - if (!(myCaller.DefaultParmsCall(10, 2.2)).equals(baseSimpleName + "::DefaultParms(int, double)")) throw new RuntimeException("failed"); + if (!(myCaller.DefaultParmsCall(10, 2.25)).equals(baseSimpleName + "::DefaultParms(int, double)")) throw new RuntimeException("failed"); if (myBase instanceof JavaDerived) { // special handling for Java derived classes, there is no way to do this any other way if (!myCaller.DefaultParmsCall(10).equals(baseSimpleName + "::DefaultParms(int, double)")) throw new RuntimeException("failed"); } else { @@ -210,7 +210,7 @@ class JavaDerived extends Base public String DefaultParms(int x) { if (director_classes.getPrintDebug()) System.out.println("JavaDerived - DefaultParms(" + x + ")"); - return DefaultParms(x, 1.1/*use C++ default here*/); + return DefaultParms(x, 1.125/*use C++ default here*/); } } diff --git a/Examples/test-suite/php/director_classes_runme.php b/Examples/test-suite/php/director_classes_runme.php index 170e10f26..c25d85d17 100644 --- a/Examples/test-suite/php/director_classes_runme.php +++ b/Examples/test-suite/php/director_classes_runme.php @@ -31,7 +31,7 @@ if (PHP_MAJOR_VERSION < 8) { $rv = preg_replace('/Base/', 'PHPDerived', $rv); return $rv; } - function DefaultParms($x, $y = 1.1) { + function DefaultParms($x, $y = 1.125) { $rv = parent::DefaultParms($x, $y); $rv = preg_replace('/Base/', 'PHPDerived', $rv); return $rv; -- 2.43.0