[libc-commits] [libc] [libc][math] Fix signed zeros for powf when underflow happens. (PR #112601)

via libc-commits libc-commits at lists.llvm.org
Wed Oct 16 14:43:29 PDT 2024


================
@@ -855,9 +855,11 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
           : 0.0;
   exp2_hi_mid_dd.hi = exp2_hi_mid;
 
-  return static_cast<float>(
-             powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd)) +
-         0.0f;
+  double r_dd = powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd);
+  float r_f = static_cast<float>(r_dd);
+
+  // Only fix signed zeros for exact zeros results.
+  return r_dd != 0 ? r_f : r_f + 0.0f;
----------------
lntue wrote:

yes, for rounding modes other than FE_DOWNWARD

https://github.com/llvm/llvm-project/pull/112601


More information about the libc-commits mailing list