From 5d0fbeb15a75f2ccb622ab4abda147fa2be44a3f Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Fri, 26 Jun 2020 18:18:59 +0300 Subject: [PATCH] Fix hypot corner cases: NaN and Inf function arguments. --- runtime/src/main/cpp/KotlinMath.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/cpp/KotlinMath.cpp b/runtime/src/main/cpp/KotlinMath.cpp index 6346445edc0..5879518ad60 100644 --- a/runtime/src/main/cpp/KotlinMath.cpp +++ b/runtime/src/main/cpp/KotlinMath.cpp @@ -132,7 +132,12 @@ KDouble Kotlin_math_acosh(KDouble x) { KDouble Kotlin_math_atanh(KDouble x) { return atanh(x); } -KDouble Kotlin_math_hypot(KDouble x, KDouble y) { return hypot(x, y); } +KDouble Kotlin_math_hypot(KDouble x, KDouble y) { + if (isinf(x) || isinf(y)) return INFINITY; + if (isnan(x) || isnan(y)) return NAN; + return hypot(x, y); +} + KDouble Kotlin_math_sqrt(KDouble x) { return sqrt(x); } KDouble Kotlin_math_exp(KDouble x) { return exp(x); } KDouble Kotlin_math_expm1(KDouble x) { return expm1(x); } @@ -200,7 +205,12 @@ KFloat Kotlin_math_acoshf(KFloat x) { KFloat Kotlin_math_atanhf(KFloat x) { return atanhf(x); } -KFloat Kotlin_math_hypotf(KFloat x, KFloat y) { return hypotf(x, y); } +KFloat Kotlin_math_hypotf(KFloat x, KFloat y) { + if (isinf(x) || isinf(y)) return INFINITY; + if (isnan(x) || isnan(y)) return NAN; + return hypotf(x, y); +} + KFloat Kotlin_math_sqrtf(KFloat x) { return sqrtf(x); } KFloat Kotlin_math_expf(KFloat x) { return expf(x); } KFloat Kotlin_math_expm1f(KFloat x) { return expm1f(x); }