[libc-commits] [libc] [libc][NFC] Fix mixed up biased/unbiased exponent (PR #75037)

via libc-commits libc-commits at lists.llvm.org
Mon Dec 11 02:06:08 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

<details>
<summary>Changes</summary>

According to [wikipedia](https://en.wikipedia.org/wiki/Exponent_bias) the "biased exponent" is the encoded form that is always positive whereas the unbiased form is the actual "real" exponent that can be positive or negative.
`FPBits` seems to be using `unbiased_exponent` to describe the encoded form (unsigned). This patch simply use `biased` instead of `unbiased`.


---

Patch is 51.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75037.diff


29 Files Affected:

- (modified) libc/src/__support/FPUtil/FPBits.h (+10-10) 
- (modified) libc/src/__support/FPUtil/Hypot.h (+2-2) 
- (modified) libc/src/__support/FPUtil/NormalFloat.h (+10-10) 
- (modified) libc/src/__support/FPUtil/fpbits_str.h (+1-1) 
- (modified) libc/src/__support/FPUtil/generic/FMA.h (+7-7) 
- (modified) libc/src/__support/FPUtil/generic/FMod.h (+2-2) 
- (modified) libc/src/__support/FPUtil/generic/sqrt.h (+1-1) 
- (modified) libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h (+2-2) 
- (modified) libc/src/__support/FPUtil/x86_64/LongDoubleBits.h (+16-16) 
- (modified) libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h (+6-6) 
- (modified) libc/src/__support/str_to_float.h (+3-3) 
- (modified) libc/src/math/generic/expf.cpp (+1-1) 
- (modified) libc/src/math/generic/explogxf.h (+2-2) 
- (modified) libc/src/math/generic/hypotf.cpp (+2-2) 
- (modified) libc/src/math/generic/log10f.cpp (+1-1) 
- (modified) libc/src/math/generic/log1p.cpp (+2-2) 
- (modified) libc/src/math/generic/log1pf.cpp (+1-1) 
- (modified) libc/src/math/generic/log2f.cpp (+2-2) 
- (modified) libc/src/math/generic/logf.cpp (+2-2) 
- (modified) libc/src/math/generic/powf.cpp (+2-2) 
- (modified) libc/test/src/__support/FPUtil/fpbits_test.cpp (+30-30) 
- (modified) libc/test/src/math/LdExpTest.h (+1-1) 
- (modified) libc/test/src/math/NextAfterTest.h (+6-8) 
- (modified) libc/test/src/math/RoundToIntegerTest.h (+2-2) 
- (modified) libc/test/src/math/smoke/LdExpTest.h (+1-1) 
- (modified) libc/test/src/math/smoke/NextAfterTest.h (+6-8) 
- (modified) libc/test/src/math/smoke/NextTowardTest.h (+6-8) 
- (modified) libc/test/utils/FPUtil/x86_long_double_test.cpp (+5-5) 
- (modified) libc/utils/MPFRWrapper/MPFRUtils.cpp (+4-4) 


``````````diff
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index ca98aa7126249..bd075fe3d7287 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -59,13 +59,13 @@ template <typename T> struct FPBits {
     return bits & FloatProp::MANTISSA_MASK;
   }
 
-  LIBC_INLINE constexpr void set_unbiased_exponent(UIntType expVal) {
+  LIBC_INLINE constexpr void set_biased_exponent(UIntType expVal) {
     expVal = (expVal << (FloatProp::MANTISSA_WIDTH)) & FloatProp::EXPONENT_MASK;
     bits &= ~(FloatProp::EXPONENT_MASK);
     bits |= expVal;
   }
 
-  LIBC_INLINE constexpr uint16_t get_unbiased_exponent() const {
+  LIBC_INLINE constexpr uint16_t get_biased_exponent() const {
     return uint16_t((bits & FloatProp::EXPONENT_MASK) >>
                     (FloatProp::MANTISSA_WIDTH));
   }
@@ -73,7 +73,7 @@ template <typename T> struct FPBits {
   // The function return mantissa with the implicit bit set iff the current
   // value is a valid normal number.
   LIBC_INLINE constexpr UIntType get_explicit_mantissa() {
-    return ((get_unbiased_exponent() > 0 && !is_inf_or_nan())
+    return ((get_biased_exponent() > 0 && !is_inf_or_nan())
                 ? (FloatProp::MANTISSA_MASK + 1)
                 : 0) |
            (FloatProp::MANTISSA_MASK & bits);
@@ -126,7 +126,7 @@ template <typename T> struct FPBits {
   LIBC_INLINE constexpr UIntType uintval() const { return bits; }
 
   LIBC_INLINE constexpr int get_exponent() const {
-    return int(get_unbiased_exponent()) - EXPONENT_BIAS;
+    return int(get_biased_exponent()) - EXPONENT_BIAS;
   }
 
   // If the number is subnormal, the exponent is treated as if it were the
@@ -136,13 +136,13 @@ template <typename T> struct FPBits {
   // will give a slightly incorrect result. Additionally, zero has an exponent
   // of zero, and that should actually be treated as zero.
   LIBC_INLINE constexpr int get_explicit_exponent() const {
-    const int unbiased_exp = int(get_unbiased_exponent());
+    const int biased_exp = int(get_biased_exponent());
     if (is_zero()) {
       return 0;
-    } else if (unbiased_exp == 0) {
+    } else if (biased_exp == 0) {
       return 1 - EXPONENT_BIAS;
     } else {
-      return unbiased_exp - EXPONENT_BIAS;
+      return biased_exp - EXPONENT_BIAS;
     }
   }
 
@@ -228,7 +228,7 @@ template <typename T> struct FPBits {
     if (LIBC_LIKELY(ep >= 0)) {
       // Implicit number bit will be removed by mask
       result.set_mantissa(number);
-      result.set_unbiased_exponent(ep + 1);
+      result.set_biased_exponent(ep + 1);
     } else {
       result.set_mantissa(number >> -ep);
     }
@@ -236,10 +236,10 @@ template <typename T> struct FPBits {
   }
 
   LIBC_INLINE static constexpr FPBits<T>
-  create_value(bool sign, UIntType unbiased_exp, UIntType mantissa) {
+  create_value(bool sign, UIntType biased_exp, UIntType mantissa) {
     FPBits<T> result;
     result.set_sign(sign);
-    result.set_unbiased_exponent(unbiased_exp);
+    result.set_biased_exponent(biased_exp);
     result.set_mantissa(mantissa);
     return result;
   }
diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index fb04d8a7775df..42d9e1b3f8cec 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -120,8 +120,8 @@ LIBC_INLINE T hypot(T x, T y) {
     return y;
   }
 
-  uint16_t x_exp = x_bits.get_unbiased_exponent();
-  uint16_t y_exp = y_bits.get_unbiased_exponent();
+  uint16_t x_exp = x_bits.get_biased_exponent();
+  uint16_t y_exp = y_bits.get_biased_exponent();
   uint16_t exp_diff = (x_exp > y_exp) ? (x_exp - y_exp) : (y_exp - x_exp);
 
   if ((exp_diff >= MantissaWidth<T>::VALUE + 2) || (x == 0) || (y == 0)) {
diff --git a/libc/src/__support/FPUtil/NormalFloat.h b/libc/src/__support/FPUtil/NormalFloat.h
index d59de14fb695e..d3236316a8799 100644
--- a/libc/src/__support/FPUtil/NormalFloat.h
+++ b/libc/src/__support/FPUtil/NormalFloat.h
@@ -111,7 +111,7 @@ template <typename T> struct NormalFloat {
         const UIntType shift_out_mask = (UIntType(1) << shift) - 1;
         const UIntType shift_out_value = mantissa & shift_out_mask;
         const UIntType halfway_value = UIntType(1) << (shift - 1);
-        result.set_unbiased_exponent(0);
+        result.set_biased_exponent(0);
         result.set_mantissa(mantissa >> shift);
         UIntType new_mantissa = result.get_mantissa();
         if (shift_out_value > halfway_value) {
@@ -126,14 +126,14 @@ template <typename T> struct NormalFloat {
         // mantissa was all ones (0b111..11). For such a case, we will carry
         // the overflow into the exponent.
         if (new_mantissa == ONE)
-          result.set_unbiased_exponent(1);
+          result.set_biased_exponent(1);
         return T(result);
       } else {
         return T(result);
       }
     }
 
-    result.set_unbiased_exponent(exponent + FPBits<T>::EXPONENT_BIAS);
+    result.set_biased_exponent(exponent + FPBits<T>::EXPONENT_BIAS);
     result.set_mantissa(mantissa);
     return T(result);
   }
@@ -151,12 +151,12 @@ template <typename T> struct NormalFloat {
     }
 
     // Normalize subnormal numbers.
-    if (bits.get_unbiased_exponent() == 0) {
+    if (bits.get_biased_exponent() == 0) {
       unsigned shift = evaluate_normalization_shift(bits.get_mantissa());
       mantissa = UIntType(bits.get_mantissa()) << shift;
       exponent = 1 - FPBits<T>::EXPONENT_BIAS - shift;
     } else {
-      exponent = bits.get_unbiased_exponent() - FPBits<T>::EXPONENT_BIAS;
+      exponent = bits.get_biased_exponent() - FPBits<T>::EXPONENT_BIAS;
       mantissa = ONE | bits.get_mantissa();
     }
   }
@@ -184,7 +184,7 @@ NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
     return;
   }
 
-  if (bits.get_unbiased_exponent() == 0) {
+  if (bits.get_biased_exponent() == 0) {
     if (bits.get_implicit_bit() == 0) {
       // Since we ignore zero value, the mantissa in this case is non-zero.
       int normalization_shift =
@@ -201,7 +201,7 @@ NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
       exponent = 0;
       mantissa = 0;
     } else {
-      exponent = bits.get_unbiased_exponent() - 16383;
+      exponent = bits.get_biased_exponent() - 16383;
       mantissa = ONE | bits.get_mantissa();
     }
   }
@@ -228,7 +228,7 @@ template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
       const UIntType shift_out_mask = (UIntType(1) << shift) - 1;
       const UIntType shift_out_value = mantissa & shift_out_mask;
       const UIntType halfway_value = UIntType(1) << (shift - 1);
-      result.set_unbiased_exponent(0);
+      result.set_biased_exponent(0);
       result.set_mantissa(mantissa >> shift);
       UIntType new_mantissa = result.get_mantissa();
       if (shift_out_value > halfway_value) {
@@ -243,7 +243,7 @@ template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
       // mantissa was all ones (0b111..11). For such a case, we will carry
       // the overflow into the exponent and set the implicit bit to 1.
       if (new_mantissa == ONE) {
-        result.set_unbiased_exponent(1);
+        result.set_biased_exponent(1);
         result.set_implicit_bit(1);
       } else {
         result.set_implicit_bit(0);
@@ -254,7 +254,7 @@ template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
     }
   }
 
-  result.set_unbiased_exponent(biased_exponent);
+  result.set_biased_exponent(biased_exponent);
   result.set_mantissa(mantissa);
   result.set_implicit_bit(1);
   return static_cast<long double>(result);
diff --git a/libc/src/__support/FPUtil/fpbits_str.h b/libc/src/__support/FPUtil/fpbits_str.h
index 4dec85ac2cc86..5d0bb6cf1ac4d 100644
--- a/libc/src/__support/FPUtil/fpbits_str.h
+++ b/libc/src/__support/FPUtil/fpbits_str.h
@@ -53,7 +53,7 @@ template <typename T> LIBC_INLINE cpp::string str(fputil::FPBits<T> x) {
   s += sign_char(x.get_sign());
 
   s += ", E: ";
-  const details::ZeroPaddedHexFmt<uint16_t> exponent(x.get_unbiased_exponent());
+  const details::ZeroPaddedHexFmt<uint16_t> exponent(x.get_biased_exponent());
   s += exponent.view();
 
   if constexpr (cpp::is_same_v<T, long double> &&
diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index 4a825f2f4942c..61a1401c30e82 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -58,7 +58,7 @@ template <> LIBC_INLINE float fma<float>(float x, float y, float z) {
     // bit of sum, so that the sticky bits used when rounding sum to float are
     // correct (when it matters).
     fputil::FPBits<double> t(
-        (bit_prod.get_unbiased_exponent() >= bitz.get_unbiased_exponent())
+        (bit_prod.get_biased_exponent() >= bitz.get_biased_exponent())
             ? ((double(bit_sum) - double(bit_prod)) - double(bitz))
             : ((double(bit_sum) - double(bitz)) - double(bit_prod)));
 
@@ -106,15 +106,15 @@ template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
   int z_exp = 0;
 
   // Normalize denormal inputs.
-  if (LIBC_UNLIKELY(FPBits(x).get_unbiased_exponent() == 0)) {
+  if (LIBC_UNLIKELY(FPBits(x).get_biased_exponent() == 0)) {
     x_exp -= 52;
     x *= 0x1.0p+52;
   }
-  if (LIBC_UNLIKELY(FPBits(y).get_unbiased_exponent() == 0)) {
+  if (LIBC_UNLIKELY(FPBits(y).get_biased_exponent() == 0)) {
     y_exp -= 52;
     y *= 0x1.0p+52;
   }
-  if (LIBC_UNLIKELY(FPBits(z).get_unbiased_exponent() == 0)) {
+  if (LIBC_UNLIKELY(FPBits(z).get_biased_exponent() == 0)) {
     z_exp -= 52;
     z *= 0x1.0p+52;
   }
@@ -124,9 +124,9 @@ template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
   bool y_sign = y_bits.get_sign();
   bool z_sign = z_bits.get_sign();
   bool prod_sign = x_sign != y_sign;
-  x_exp += x_bits.get_unbiased_exponent();
-  y_exp += y_bits.get_unbiased_exponent();
-  z_exp += z_bits.get_unbiased_exponent();
+  x_exp += x_bits.get_biased_exponent();
+  y_exp += y_bits.get_biased_exponent();
+  z_exp += z_bits.get_biased_exponent();
 
   if (LIBC_UNLIKELY(x_exp == FPBits::MAX_EXPONENT ||
                     y_exp == FPBits::MAX_EXPONENT ||
diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h
index 0e71b039d5c06..7502660c88a13 100644
--- a/libc/src/__support/FPUtil/generic/FMod.h
+++ b/libc/src/__support/FPUtil/generic/FMod.h
@@ -233,8 +233,8 @@ class FMod {
       return FPB(FPB::zero()); // |x|=|y| return 0.0
     }
 
-    int e_x = sx.get_unbiased_exponent();
-    int e_y = sy.get_unbiased_exponent();
+    int e_x = sx.get_biased_exponent();
+    int e_y = sy.get_biased_exponent();
 
     // Most common case where |y| is "very normal" and |x/y| < 2^EXPONENT_WIDTH
     if (LIBC_LIKELY(e_y > int(FPB::FloatProp::MANTISSA_WIDTH) &&
diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h
index 6ae2171bacf7b..5bde9589fdc01 100644
--- a/libc/src/__support/FPUtil/generic/sqrt.h
+++ b/libc/src/__support/FPUtil/generic/sqrt.h
@@ -97,7 +97,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> sqrt(T x) {
       UIntType x_mant = bits.get_mantissa();
 
       // Step 1a: Normalize denormal input and append hidden bit to the mantissa
-      if (bits.get_unbiased_exponent() == 0) {
+      if (bits.get_biased_exponent() == 0) {
         ++x_exp; // let x_exp be the correct exponent of ONE bit.
         internal::normalize<T>(x_exp, x_mant);
       } else {
diff --git a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
index 0e7907e82943a..2f25be54e0bc3 100644
--- a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
+++ b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
@@ -65,7 +65,7 @@ LIBC_INLINE long double sqrt(long double x) {
     // Step 1a: Normalize denormal input
     if (bits.get_implicit_bit()) {
       x_mant |= ONE;
-    } else if (bits.get_unbiased_exponent() == 0) {
+    } else if (bits.get_biased_exponent() == 0) {
       normalize(x_exp, x_mant);
     }
 
@@ -128,7 +128,7 @@ LIBC_INLINE long double sqrt(long double x) {
 
     // Extract output
     FPBits<long double> out(0.0L);
-    out.set_unbiased_exponent(x_exp);
+    out.set_biased_exponent(x_exp);
     out.set_implicit_bit(1);
     out.set_mantissa((y & (ONE - 1)));
 
diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
index 2f07ff4a2c3e5..bbc30ff7a376d 100644
--- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
+++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
@@ -71,7 +71,7 @@ template <> struct FPBits<long double> {
     return bits & (FloatProp::MANTISSA_MASK | FloatProp::EXPLICIT_BIT_MASK);
   }
 
-  LIBC_INLINE constexpr void set_unbiased_exponent(UIntType expVal) {
+  LIBC_INLINE constexpr void set_biased_exponent(UIntType expVal) {
     expVal =
         (expVal << (FloatProp::BIT_WIDTH - 1 - FloatProp::EXPONENT_WIDTH)) &
         FloatProp::EXPONENT_MASK;
@@ -79,7 +79,7 @@ template <> struct FPBits<long double> {
     bits |= expVal;
   }
 
-  LIBC_INLINE constexpr uint16_t get_unbiased_exponent() const {
+  LIBC_INLINE constexpr uint16_t get_biased_exponent() const {
     return uint16_t((bits & FloatProp::EXPONENT_MASK) >>
                     (FloatProp::BIT_WIDTH - 1 - FloatProp::EXPONENT_WIDTH));
   }
@@ -137,7 +137,7 @@ template <> struct FPBits<long double> {
   }
 
   LIBC_INLINE constexpr int get_exponent() const {
-    return int(get_unbiased_exponent()) - EXPONENT_BIAS;
+    return int(get_biased_exponent()) - EXPONENT_BIAS;
   }
 
   // If the number is subnormal, the exponent is treated as if it were the
@@ -147,38 +147,38 @@ template <> struct FPBits<long double> {
   // will give a slightly incorrect result. Additionally, zero has an exponent
   // of zero, and that should actually be treated as zero.
   LIBC_INLINE constexpr int get_explicit_exponent() const {
-    const int unbiased_exp = int(get_unbiased_exponent());
+    const int biased_exp = int(get_biased_exponent());
     if (is_zero()) {
       return 0;
-    } else if (unbiased_exp == 0) {
+    } else if (biased_exp == 0) {
       return 1 - EXPONENT_BIAS;
     } else {
-      return unbiased_exp - EXPONENT_BIAS;
+      return biased_exp - EXPONENT_BIAS;
     }
   }
 
   LIBC_INLINE constexpr bool is_zero() const {
-    return get_unbiased_exponent() == 0 && get_mantissa() == 0 &&
+    return get_biased_exponent() == 0 && get_mantissa() == 0 &&
            get_implicit_bit() == 0;
   }
 
   LIBC_INLINE constexpr bool is_inf() const {
-    return get_unbiased_exponent() == MAX_EXPONENT && get_mantissa() == 0 &&
+    return get_biased_exponent() == MAX_EXPONENT && get_mantissa() == 0 &&
            get_implicit_bit() == 1;
   }
 
   LIBC_INLINE constexpr bool is_nan() const {
-    if (get_unbiased_exponent() == MAX_EXPONENT) {
+    if (get_biased_exponent() == MAX_EXPONENT) {
       return (get_implicit_bit() == 0) || get_mantissa() != 0;
-    } else if (get_unbiased_exponent() != 0) {
+    } else if (get_biased_exponent() != 0) {
       return get_implicit_bit() == 0;
     }
     return false;
   }
 
   LIBC_INLINE constexpr bool is_inf_or_nan() const {
-    return (get_unbiased_exponent() == MAX_EXPONENT) ||
-           (get_unbiased_exponent() != 0 && get_implicit_bit() == 0);
+    return (get_biased_exponent() == MAX_EXPONENT) ||
+           (get_biased_exponent() != 0 && get_implicit_bit() == 0);
   }
 
   // Methods below this are used by tests.
@@ -189,7 +189,7 @@ template <> struct FPBits<long double> {
 
   LIBC_INLINE static constexpr long double inf(bool sign = false) {
     FPBits<long double> bits(0.0l);
-    bits.set_unbiased_exponent(MAX_EXPONENT);
+    bits.set_biased_exponent(MAX_EXPONENT);
     bits.set_implicit_bit(1);
     if (sign) {
       bits.set_sign(true);
@@ -201,7 +201,7 @@ template <> struct FPBits<long double> {
 
   LIBC_INLINE static constexpr long double build_nan(UIntType v) {
     FPBits<long double> bits(0.0l);
-    bits.set_unbiased_exponent(MAX_EXPONENT);
+    bits.set_biased_exponent(MAX_EXPONENT);
     bits.set_implicit_bit(1);
     bits.set_mantissa(v);
     return bits;
@@ -228,10 +228,10 @@ template <> struct FPBits<long double> {
   }
 
   LIBC_INLINE static constexpr FPBits<long double>
-  create_value(bool sign, UIntType unbiased_exp, UIntType mantissa) {
+  create_value(bool sign, UIntType biased_exp, UIntType mantissa) {
     FPBits<long double> result;
     result.set_sign(sign);
-    result.set_unbiased_exponent(unbiased_exp);
+    result.set_biased_exponent(biased_exp);
     result.set_mantissa(mantissa);
     return result;
   }
diff --git a/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
index 4508671b47ee5..5e32f766ad586 100644
--- a/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
+++ b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
@@ -39,8 +39,8 @@ LIBC_INLINE long double nextafter(long double from, long double to) {
 
   // Convert pseudo subnormal number to normal number.
   if (from_bits.get_implicit_bit() == 1 &&
-      from_bits.get_unbiased_exponent() == 0) {
-    from_bits.set_unbiased_exponent(1);
+      from_bits.get_biased_exponent() == 0) {
+    from_bits.set_biased_exponent(1);
   }
 
   using UIntType = FPBits::UIntType;
@@ -59,7 +59,7 @@ LIBC_INLINE long double nextafter(long double from, long double to) {
         // Incrementing exponent might overflow the value to infinity,
         // which is what is expected. Since NaNs are handling separately,
         // it will never overflow "beyond" infinity.
-        from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() + 1);
+        from_bits.set_biased_exponent(from_bits.get_biased_exponent() + 1);
         if (from_bits.is_inf())
           raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
         return from_bits;
@@ -75,7 +75,7 @@ LIBC_INLINE long double nextafter(long double from, long double to) {
         from_bits.set_mantissa(MANTISSA_MASK);
         // from == 0 is handled separately so decrementing the exponent will not
         // lead to underflow.
-        from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() - 1);
+        from_bits.set_biased_exponent(from_bits.get_biased_exponent() - 1);
         return from_bits;
       } else {
         --int_val;
@@ -94,7 +94,7 @@ LIBC_INLINE long double nextafter(long double from, long double to) {
         from_bits.set_mantissa(MANTISSA_MASK);
         // from == 0 is handled separately so decrementing the exponent will not
         // lead to underflow.
-        from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() - 1);
+        from_bits.set_biased_exponent(from_bits.get_biased_exponent() - 1);
         return from_bits;
       } else {
         --int_val;
@@ -107,7 +107,7 @@ LIBC_INLINE long double nextafter(long double from, long double to) {
         // Incrementing exponent might overflow the value to infinity,
         // which is what is expected. Since NaNs are handling separately,
         // it will never overflow "beyond" infinity.
-        from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() + 1);
+        from_bits.set_biased_exponent(from_bits.get_biased_exponent() + 1);
         if (from_bits.is_inf())
           raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
         return from_bits;
diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index ad73e93f6faa8..d495c7a073cde 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -92,7 +92,7 @@ template <class T> LIBC_INLINE void set_implicit_bit(fputil::FPBits<T> &) {
 template <>
 LIBC_INLINE void
 set_implicit_bit<long double>(fputil::FPBits<long double> &result) {
-  result.set_implicit_bit(result.get_unbiased_exponent() != 0);
+  result.set_implicit_bit(result.get_biased_exponent() != 0);
 }
 #endif
 
@@ -643,7 +643,7 @@ clinger_fast_path(ExpandedFloat<T> init_num,
 
   ExpandedFloat<T> output;
   output.mantissa = result.get_mantissa();
-  output.exponent = result.get_unbiased_exponent();
+  output.exponent = result.get_biased_exponent();
   return output;
 }
 
@@ -1164,7 +1164,7 @@ LIBC_INLINE StrToNumResult<T> strtof...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list