From d5a6c33b2084d70a423ec03b9a48b718c59f00b5 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Thu, 9 Jul 2020 14:10:10 +0300 Subject: [PATCH] =?UTF-8?q?Add=20a=20special=20case=20for=20floating-point?= =?UTF-8?q?=20pow()=20function:=20in=20case=20of=20=C2=B10=20the=20functio?= =?UTF-8?q?n=20should=20return=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/src/main/cpp/KotlinMath.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/runtime/src/main/cpp/KotlinMath.cpp b/runtime/src/main/cpp/KotlinMath.cpp index 5879518ad60..17e19c8e123 100644 --- a/runtime/src/main/cpp/KotlinMath.cpp +++ b/runtime/src/main/cpp/KotlinMath.cpp @@ -156,8 +156,10 @@ KDouble Kotlin_math_abs(KDouble x) { return fabs(x); } // extensions KDouble Kotlin_math_Double_pow(KDouble thiz, KDouble x) { - if (isinf(x) && (thiz == 1.0 || thiz == -1.0)) return NAN; // Kotlin corner case - return pow(thiz, x); + // Kotlin corner cases + 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); } @@ -229,8 +231,10 @@ KFloat Kotlin_math_absf(KFloat x) { return fabsf(x); } // extensions KFloat Kotlin_math_Float_pow(KFloat thiz, KFloat x) { - if (isinf(x) && (thiz == 1.0 || thiz == -1.0)) return NAN; // Kotlin corner case - return powf(thiz, x); + // Kotlin corner cases + 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); }