Cleanup on the new Math APIs (#20993)
authorTanner Gooding <tagoo@outlook.com>
Wed, 14 Nov 2018 15:20:49 +0000 (07:20 -0800)
committerGitHub <noreply@github.com>
Wed, 14 Nov 2018 15:20:49 +0000 (07:20 -0800)
* Updating the cached HAVE_COMPATIBLE_ILOGB0_EXITCODE and HAVE_COMPATIBLE_ILOGBNAN_EXITCODE to 1

* Fixing MaxMagnitude and MinMagnitude to correctly handle the case when ax and ay are equal

cross/android/arm/tryrun.cmake
cross/android/arm64/tryrun.cmake
cross/tryrun.cmake
src/System.Private.CoreLib/shared/System/Math.cs
src/System.Private.CoreLib/shared/System/MathF.cs

index 69b7158b4e557b4fc9062dc106962cf99b1cb51c..dc7523fc2e93783bb6955e6ef115460dffd3fd85 100644 (file)
@@ -7,11 +7,11 @@ SET( HAVE_COMPATIBLE_EXP_EXITCODE
      CACHE STRING "Result from TRY_RUN" FORCE)
 
 SET( HAVE_COMPATIBLE_ILOGB0_EXITCODE 
-     0
+     1
      CACHE STRING "Result from TRY_RUN" FORCE)
 
 SET( HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 
-     0
+     1
      CACHE STRING "Result from TRY_RUN" FORCE)
 
 SET( REALPATH_SUPPORTS_NONEXISTENT_FILES_EXITCODE 
index 93a225009d1320436adacf0e2cd67b7e8e2e9965..5e68f9d70ab58bd92629be55410f810344b3c62a 100644 (file)
@@ -3,11 +3,11 @@ SET( HAVE_COMPATIBLE_EXP_EXITCODE
      CACHE STRING "Result from TRY_RUN" FORCE)
 
 SET( HAVE_COMPATIBLE_ILOGB0_EXITCODE 
-     0
+     1
      CACHE STRING "Result from TRY_RUN" FORCE)
 
 SET( HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 
-     0
+     1
      CACHE STRING "Result from TRY_RUN" FORCE)
 
 SET( REALPATH_SUPPORTS_NONEXISTENT_FILES_EXITCODE 
index 47aa7b4ba7cf57871d964ee1db5c152fd0433b46..988a59c5f6b98cc2f7ecba68bce4efcc7a1c5a36 100644 (file)
@@ -23,8 +23,8 @@ if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$")
   set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 0)
   set_cache_value(HAVE_COMPATIBLE_ASIN_EXITCODE 0)
   set_cache_value(HAVE_COMPATIBLE_ATAN2_EXITCODE 0)
-  set_cache_value(HAVE_COMPATIBLE_ILOGB0_EXITCODE 0)
-  set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 0)
+  set_cache_value(HAVE_COMPATIBLE_ILOGB0_EXITCODE 1)
+  set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 1)
   set_cache_value(HAVE_COMPATIBLE_LOG10_EXITCODE 0)
   set_cache_value(HAVE_COMPATIBLE_LOG_EXITCODE 0)
   set_cache_value(HAVE_COMPATIBLE_POW_EXITCODE 0)
index e2784867757f7f1993b08c05be60fe91d846ff90..af74185a886500a3cf3c6ad585ae3f6045331ce3 100644 (file)
@@ -658,15 +658,18 @@ namespace System
             }
 
             // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
-            // * Doing (x < y) first could get transformed into (y >= x) by the JIT which would
+            // * Doing (ax < ay) first could get transformed into (ay >= ax) by the JIT which would
             //   then return an incorrect value
 
-            if (x == y)
+            double ax = Abs(x);
+            double ay = Abs(y);
+
+            if (ax == ay)
             {
                 return double.IsNegative(x) ? y : x;
             }
 
-            return (Abs(x) < Abs(y)) ? y : x;
+            return (ax < ay) ? y : x;
         }
 
         [NonVersionable]
@@ -803,15 +806,18 @@ namespace System
             }
 
             // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
-            // * Doing (x < y) first could get transformed into (y >= x) by the JIT which would
+            // * Doing (ax < ay) first could get transformed into (ay >= ax) by the JIT which would
             //   then return an incorrect value
 
-            if (x == y)
+            double ax = Abs(x);
+            double ay = Abs(y);
+
+            if (ax == ay)
             {
                 return double.IsNegative(x) ? x : y;
             }
 
-            return (Abs(x) < Abs(y)) ? x : y;
+            return (ax < ay) ? x : y;
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
index 428f9f88beb47af1a44b5960f1de1ac6800aa896..3bff55daebfe5fd2eefa831d763457a991942f00 100644 (file)
@@ -206,15 +206,18 @@ namespace System
             }
 
             // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
-            // * Doing (x < y) first could get transformed into (y >= x) by the JIT which would
+            // * Doing (ax < ay) first could get transformed into (ay >= ax) by the JIT which would
             //   then return an incorrect value
 
-            if (x == y)
+            float ax = Abs(x);
+            float ay = Abs(y);
+
+            if (ax == ay)
             {
                 return float.IsNegative(x) ? y : x;
             }
 
-            return (Abs(x) < Abs(y)) ? y : x;
+            return (ax < ay) ? y : x;
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -241,15 +244,18 @@ namespace System
             }
 
             // We do this comparison first and separately to handle the -0.0 to +0.0 comparision
-            // * Doing (x < y) first could get transformed into (y >= x) by the JIT which would
+            // * Doing (ax < ay) first could get transformed into (ay >= ax) by the JIT which would
             //   then return an incorrect value
 
-            if (x == y)
+            float ax = Abs(x);
+            float ay = Abs(y);
+
+            if (ax == ay)
             {
                 return float.IsNegative(x) ? x : y;
             }
 
-            return (Abs(x) < Abs(y)) ? x : y;
+            return (ax < ay) ? x : y;
         }
 
         [Intrinsic]