From: Peter Steinfeld Date: Thu, 7 Jul 2022 17:42:47 +0000 (-0700) Subject: [flang] SET_EXPONENT(-0.0) should return -0.0 X-Git-Tag: upstream/15.0.7~2389 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f9e9d9cfc2e2f929c17de4a1065c0eb68e479c0;p=platform%2Fupstream%2Fllvm.git [flang] SET_EXPONENT(-0.0) should return -0.0 Section 16.9.171 says: If X has the value zero, the result has the same value as X So if X is -0.0, SET_EXPONENT should return -0.0. Differential Revision: https://reviews.llvm.org/D129309 --- diff --git a/flang/runtime/numeric.cpp b/flang/runtime/numeric.cpp index 8d02973..a989d3a 100644 --- a/flang/runtime/numeric.cpp +++ b/flang/runtime/numeric.cpp @@ -122,7 +122,7 @@ template inline T SetExponent(T x, std::int64_t p) { } else if (std::isinf(x)) { return std::numeric_limits::quiet_NaN(); // +/-Inf -> NaN } else if (x == 0) { - return 0; // 0 -> 0 + return x; // return negative zero if x is negative zero } else { int expo{std::ilogb(x) + 1}; auto ip{static_cast(p - expo)};