Merge pull request #1225 from strawd/bug22307
[mono.git] / mono / metadata / sysmath.c
index 47cbcfd599f3281305c628b8e82f994c2dd3bb02..eadb052ccd16c46a72927fb13c0b8fe0dccda8cc 100644 (file)
@@ -263,6 +263,22 @@ ves_icall_System_Math_Pow (gdouble x, gdouble y)
        if (result == MInfinity.d && x < 0.0 && isfinite (x) && ceil (y / 2) == floor (y / 2))
                result = PInfinity.d;
 
+#if defined (__linux__) && SIZEOF_VOID_P == 4
+       /* On Linux 32bits, some tests erroneously return NaN */
+       if (isnan (result)) {
+               if (isminusone (x) && (y > 9007199254740991.0 || y < -9007199254740991.0)) {
+                       /* Math.Pow (-1, Double.MaxValue) and Math.Pow (-1, Double.MinValue) should return 1 */
+                       result = POne.d;
+               } else if (x < -9007199254740991.0 && y < -9007199254740991.0) {
+                       /* Math.Pow (Double.MinValue, Double.MinValue) should return 0 */
+                       result = 0.0;
+               } else if (x < -9007199254740991.0 && y > 9007199254740991.0) {
+                       /* Math.Pow (Double.MinValue, Double.MaxValue) should return Double.PositiveInfinity */
+                       result = PInfinity.d;
+               }
+       }
+#endif
+
        return result == -0.0 ? 0 : result;
 }