Add a special case for floating-point pow() function: in case of ±0 the function should return 1.0

This commit is contained in:
Pavel Punegov
2020-07-09 14:10:10 +03:00
committed by Pavel Punegov
parent 8926992af1
commit d5a6c33b20
+8 -4
View File
@@ -156,8 +156,10 @@ KDouble Kotlin_math_abs(KDouble x) { return fabs(x); }
// extensions // extensions
KDouble Kotlin_math_Double_pow(KDouble thiz, KDouble x) { KDouble Kotlin_math_Double_pow(KDouble thiz, KDouble x) {
if (isinf(x) && (thiz == 1.0 || thiz == -1.0)) return NAN; // Kotlin corner case // Kotlin corner cases
return pow(thiz, x); if (x == 0.0 || x == -0.0) return 1.0;
if (isinf(x) && (thiz == 1.0 || thiz == -1.0)) return NAN;
return pow(thiz, x);
} }
KDouble Kotlin_math_Double_IEEErem(KDouble thiz, KDouble divisor) { return remainder(thiz, divisor); } KDouble Kotlin_math_Double_IEEErem(KDouble thiz, KDouble divisor) { return remainder(thiz, divisor); }
@@ -229,8 +231,10 @@ KFloat Kotlin_math_absf(KFloat x) { return fabsf(x); }
// extensions // extensions
KFloat Kotlin_math_Float_pow(KFloat thiz, KFloat x) { KFloat Kotlin_math_Float_pow(KFloat thiz, KFloat x) {
if (isinf(x) && (thiz == 1.0 || thiz == -1.0)) return NAN; // Kotlin corner case // Kotlin corner cases
return powf(thiz, x); if (x == 0.0 || x == -0.0) return 1.0;
if (isinf(x) && (thiz == 1.0 || thiz == -1.0)) return NAN;
return powf(thiz, x);
} }
KFloat Kotlin_math_Float_IEEErem(KFloat thiz, KFloat divisor) { return remainderf(thiz, divisor); } KFloat Kotlin_math_Float_IEEErem(KFloat thiz, KFloat divisor) { return remainderf(thiz, divisor); }