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 69b7158..dc7523f 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 93a2250..5e68f9d 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 47aa7b4..988a59c 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 e278486..af74185 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 428f9f8..3bff55d 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]