12 changes: 6 additions & 6 deletions libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libc/src/__support/str_to_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1164,7 +1164,7 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
}
seen_digit = parse_result.parsed_len != 0;
result.set_mantissa(parse_result.value.mantissa);
result.set_unbiased_exponent(parse_result.value.exponent);
result.set_biased_exponent(parse_result.value.exponent);
index += parse_result.parsed_len;
error = parse_result.error;
} else if (tolower(src[index]) == 'n') { // NaN
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/expf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LLVM_LIBC_FUNCTION(float, expf, (float x)) {
// When |x| >= 89, |x| < 2^-25, or x is nan
if (LIBC_UNLIKELY(x_abs >= 0x42b2'0000U || x_abs <= 0x3280'0000U)) {
// |x| < 2^-25
if (xbits.get_unbiased_exponent() <= 101) {
if (xbits.get_biased_exponent() <= 101) {
return 1.0f + x;
}

Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/explogxf.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ LIBC_INLINE static double log2_eval(double x) {
(LOG_P1_SIZE - 1);

bs.bits &= FPB::FloatProp::MANTISSA_MASK >> LOG_P1_BITS;
bs.set_unbiased_exponent(FPB::FloatProp::EXPONENT_BIAS);
bs.set_biased_exponent(FPB::FloatProp::EXPONENT_BIAS);
double dx = (bs.get_val() - 1.0) * LOG_P1_1_OVER[p1];

// Taylor series for log(2,1+x)
Expand Down Expand Up @@ -316,7 +316,7 @@ LIBC_INLINE static double log_eval(double x) {

// Set bs to (1 + (mx - p1*2^(-7))
bs.bits &= FPB::FloatProp::MANTISSA_MASK >> 7;
bs.set_unbiased_exponent(FPB::FloatProp::EXPONENT_BIAS);
bs.set_biased_exponent(FPB::FloatProp::EXPONENT_BIAS);
// dx = (mx - p1*2^(-7)) / (1 + p1*2^(-7)).
double dx = (bs.get_val() - 1.0) * ONE_OVER_F[p1];

Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/hypotf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ LLVM_LIBC_FUNCTION(float, hypotf, (float x, float y)) {

FPBits x_bits(x), y_bits(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 >= fputil::MantissaWidth<float>::VALUE + 2) {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/log10f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ LLVM_LIBC_FUNCTION(float, log10f, (float x)) {
// Extract 7 leading fractional bits of the mantissa
int index = (x_u >> 16) & 0x7F;
// Set bits to 1.m
xbits.set_unbiased_exponent(0x7F);
xbits.set_biased_exponent(0x7F);

float u = static_cast<float>(xbits);
double v;
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/log1p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ LLVM_LIBC_FUNCTION(double, log1p, (double x)) {

fputil::DoubleDouble x_dd{0.0, 0.0};

uint16_t x_exp = xbits.get_unbiased_exponent();
uint16_t x_exp = xbits.get_biased_exponent();

if (x_exp >= EXPONENT_BIAS) {
// |x| >= 1
Expand Down Expand Up @@ -909,7 +909,7 @@ LLVM_LIBC_FUNCTION(double, log1p, (double x)) {
}
} else {
// |x| < 1
if (LIBC_UNLIKELY(xbits.get_unbiased_exponent() <
if (LIBC_UNLIKELY(xbits.get_biased_exponent() <
EXPONENT_BIAS - MANTISSA_WIDTH - 1)) {
// Quick return when |x| < 2^-53.
// Since log(1 + x) = x - x^2/2 + x^3/3 - ...,
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/log1pf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ LIBC_INLINE float log(double x) {
xbits.get_mantissa() >> 45); // fputil::MantissaWidth<double>::VALUE - 7

// Set bits to 1.m
xbits.set_unbiased_exponent(0x3FF);
xbits.set_biased_exponent(0x3FF);
FPBits f = xbits;

// Clear the lowest 45 bits.
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/log2f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ LLVM_LIBC_FUNCTION(float, log2f, (float x)) {
m -= 23;
}

m += xbits.get_unbiased_exponent();
m += xbits.get_biased_exponent();
int index = xbits.get_mantissa() >> 16;
// Set bits to 1.m
xbits.set_unbiased_exponent(0x7F);
xbits.set_biased_exponent(0x7F);

float u = static_cast<float>(xbits);
double v;
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/logf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ LLVM_LIBC_FUNCTION(float, logf, (float x)) {
// rounding mode.
if (LIBC_UNLIKELY((x_u & 0x007f'ffffU) == 0))
return static_cast<float>(
static_cast<double>(m + xbits.get_unbiased_exponent()) * LOG_2);
static_cast<double>(m + xbits.get_biased_exponent()) * LOG_2);
#endif // LIBC_TARGET_CPU_HAS_FMA

uint32_t mant = xbits.get_mantissa();
Expand All @@ -146,7 +146,7 @@ LLVM_LIBC_FUNCTION(float, logf, (float x)) {
m += static_cast<int>((x_u + (1 << 16)) >> 23);

// Set bits to 1.m
xbits.set_unbiased_exponent(0x7F);
xbits.set_biased_exponent(0x7F);

float u = static_cast<float>(xbits);
double v;
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/powf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ LIBC_INLINE bool is_integer(float x) {

LIBC_INLINE bool larger_exponent(double a, double b) {
using DoubleBits = typename fputil::FPBits<double>;
return DoubleBits(a).get_unbiased_exponent() >=
DoubleBits(b).get_unbiased_exponent();
return DoubleBits(a).get_biased_exponent() >=
DoubleBits(b).get_biased_exponent();
}

// Calculate 2^(y * log2(x)) in double-double precision.
Expand Down
60 changes: 30 additions & 30 deletions libc/test/src/__support/FPUtil/fpbits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,47 @@ TEST(LlvmLibcFPBitsTest, FloatType) {

FloatBits zero(0.0f);
EXPECT_EQ(zero.get_sign(), false);
EXPECT_EQ(zero.get_unbiased_exponent(), static_cast<uint16_t>(0));
EXPECT_EQ(zero.get_biased_exponent(), static_cast<uint16_t>(0));
EXPECT_EQ(zero.get_mantissa(), static_cast<uint32_t>(0));
EXPECT_EQ(zero.uintval(), static_cast<uint32_t>(0x00000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(zero).c_str(),
"0x00000000 = (S: 0, E: 0x0000, M: 0x00000000)");

FloatBits negzero(-0.0f);
EXPECT_EQ(negzero.get_sign(), true);
EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast<uint16_t>(0));
EXPECT_EQ(negzero.get_biased_exponent(), static_cast<uint16_t>(0));
EXPECT_EQ(negzero.get_mantissa(), static_cast<uint32_t>(0));
EXPECT_EQ(negzero.uintval(), static_cast<uint32_t>(0x80000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(negzero).c_str(),
"0x80000000 = (S: 1, E: 0x0000, M: 0x00000000)");

FloatBits one(1.0f);
EXPECT_EQ(one.get_sign(), false);
EXPECT_EQ(one.get_unbiased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(one.get_biased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(one.get_mantissa(), static_cast<uint32_t>(0));
EXPECT_EQ(one.uintval(), static_cast<uint32_t>(0x3F800000));
EXPECT_STREQ(LIBC_NAMESPACE::str(one).c_str(),
"0x3F800000 = (S: 0, E: 0x007F, M: 0x00000000)");

FloatBits negone(-1.0f);
EXPECT_EQ(negone.get_sign(), true);
EXPECT_EQ(negone.get_unbiased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(negone.get_biased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(negone.get_mantissa(), static_cast<uint32_t>(0));
EXPECT_EQ(negone.uintval(), static_cast<uint32_t>(0xBF800000));
EXPECT_STREQ(LIBC_NAMESPACE::str(negone).c_str(),
"0xBF800000 = (S: 1, E: 0x007F, M: 0x00000000)");

FloatBits num(1.125f);
EXPECT_EQ(num.get_sign(), false);
EXPECT_EQ(num.get_unbiased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(num.get_biased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(num.get_mantissa(), static_cast<uint32_t>(0x00100000));
EXPECT_EQ(num.uintval(), static_cast<uint32_t>(0x3F900000));
EXPECT_STREQ(LIBC_NAMESPACE::str(num).c_str(),
"0x3F900000 = (S: 0, E: 0x007F, M: 0x00100000)");

FloatBits negnum(-1.125f);
EXPECT_EQ(negnum.get_sign(), true);
EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(negnum.get_biased_exponent(), static_cast<uint16_t>(0x7F));
EXPECT_EQ(negnum.get_mantissa(), static_cast<uint32_t>(0x00100000));
EXPECT_EQ(negnum.uintval(), static_cast<uint32_t>(0xBF900000));
EXPECT_STREQ(LIBC_NAMESPACE::str(negnum).c_str(),
Expand All @@ -84,47 +84,47 @@ TEST(LlvmLibcFPBitsTest, DoubleType) {

DoubleBits zero(0.0);
EXPECT_EQ(zero.get_sign(), false);
EXPECT_EQ(zero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_mantissa(), static_cast<uint64_t>(0x0000000000000000));
EXPECT_EQ(zero.uintval(), static_cast<uint64_t>(0x0000000000000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(zero).c_str(),
"0x0000000000000000 = (S: 0, E: 0x0000, M: 0x0000000000000000)");

DoubleBits negzero(-0.0);
EXPECT_EQ(negzero.get_sign(), true);
EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_mantissa(), static_cast<uint64_t>(0x0000000000000000));
EXPECT_EQ(negzero.uintval(), static_cast<uint64_t>(0x8000000000000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(negzero).c_str(),
"0x8000000000000000 = (S: 1, E: 0x0000, M: 0x0000000000000000)");

DoubleBits one(1.0);
EXPECT_EQ(one.get_sign(), false);
EXPECT_EQ(one.get_unbiased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(one.get_biased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(one.get_mantissa(), static_cast<uint64_t>(0x0000000000000000));
EXPECT_EQ(one.uintval(), static_cast<uint64_t>(0x3FF0000000000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(one).c_str(),
"0x3FF0000000000000 = (S: 0, E: 0x03FF, M: 0x0000000000000000)");

DoubleBits negone(-1.0);
EXPECT_EQ(negone.get_sign(), true);
EXPECT_EQ(negone.get_unbiased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(negone.get_biased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(negone.get_mantissa(), static_cast<uint64_t>(0x0000000000000000));
EXPECT_EQ(negone.uintval(), static_cast<uint64_t>(0xBFF0000000000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(negone).c_str(),
"0xBFF0000000000000 = (S: 1, E: 0x03FF, M: 0x0000000000000000)");

DoubleBits num(1.125);
EXPECT_EQ(num.get_sign(), false);
EXPECT_EQ(num.get_unbiased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(num.get_biased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(num.get_mantissa(), static_cast<uint64_t>(0x0002000000000000));
EXPECT_EQ(num.uintval(), static_cast<uint64_t>(0x3FF2000000000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(num).c_str(),
"0x3FF2000000000000 = (S: 0, E: 0x03FF, M: 0x0002000000000000)");

DoubleBits negnum(-1.125);
EXPECT_EQ(negnum.get_sign(), true);
EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(negnum.get_biased_exponent(), static_cast<uint16_t>(0x03FF));
EXPECT_EQ(negnum.get_mantissa(), static_cast<uint64_t>(0x0002000000000000));
EXPECT_EQ(negnum.uintval(), static_cast<uint64_t>(0xBFF2000000000000));
EXPECT_STREQ(LIBC_NAMESPACE::str(negnum).c_str(),
Expand All @@ -150,7 +150,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {

LongDoubleBits zero(0.0l);
EXPECT_EQ(zero.get_sign(), false);
EXPECT_EQ(zero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(zero.uintval(), static_cast<UInt128>(0x0000000000000000) << 64);
Expand All @@ -161,7 +161,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {

LongDoubleBits negzero(-0.0l);
EXPECT_EQ(negzero.get_sign(), true);
EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(negzero.uintval(), static_cast<UInt128>(0x1) << 79);
Expand All @@ -172,7 +172,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {

LongDoubleBits one(1.0l);
EXPECT_EQ(one.get_sign(), false);
EXPECT_EQ(one.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(one.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(one.get_mantissa(), static_cast<UInt128>(0x0000000000000000) << 64);
EXPECT_EQ(one.uintval(), static_cast<UInt128>(0x3FFF8) << 60);
EXPECT_STREQ(
Expand All @@ -182,7 +182,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {

LongDoubleBits negone(-1.0l);
EXPECT_EQ(negone.get_sign(), true);
EXPECT_EQ(negone.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negone.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negone.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(negone.uintval(), static_cast<UInt128>(0xBFFF8) << 60);
Expand All @@ -193,7 +193,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {

LongDoubleBits num(1.125l);
EXPECT_EQ(num.get_sign(), false);
EXPECT_EQ(num.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(num.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(num.get_mantissa(), static_cast<UInt128>(0x1) << 60);
EXPECT_EQ(num.uintval(), static_cast<UInt128>(0x3FFF9) << 60);
EXPECT_STREQ(
Expand All @@ -203,7 +203,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {

LongDoubleBits negnum(-1.125l);
EXPECT_EQ(negnum.get_sign(), true);
EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negnum.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negnum.get_mantissa(), static_cast<UInt128>(0x1) << 60);
EXPECT_EQ(negnum.uintval(), static_cast<UInt128>(0xBFFF9) << 60);
EXPECT_STREQ(
Expand All @@ -230,7 +230,7 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {

LongDoubleBits zero(0.0l);
EXPECT_EQ(zero.get_sign(), false);
EXPECT_EQ(zero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(zero.uintval(), static_cast<UInt128>(0x0000000000000000) << 64);
Expand All @@ -240,7 +240,7 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {

LongDoubleBits negzero(-0.0l);
EXPECT_EQ(negzero.get_sign(), true);
EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(negzero.uintval(), static_cast<UInt128>(0x1) << 127);
Expand All @@ -250,7 +250,7 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {

LongDoubleBits one(1.0l);
EXPECT_EQ(one.get_sign(), false);
EXPECT_EQ(one.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(one.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(one.get_mantissa(), static_cast<UInt128>(0x0000000000000000) << 64);
EXPECT_EQ(one.uintval(), static_cast<UInt128>(0x3FFF) << 112);
EXPECT_STREQ(LIBC_NAMESPACE::str(one).c_str(),
Expand All @@ -259,7 +259,7 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {

LongDoubleBits negone(-1.0l);
EXPECT_EQ(negone.get_sign(), true);
EXPECT_EQ(negone.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negone.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negone.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(negone.uintval(), static_cast<UInt128>(0xBFFF) << 112);
Expand All @@ -269,7 +269,7 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {

LongDoubleBits num(1.125l);
EXPECT_EQ(num.get_sign(), false);
EXPECT_EQ(num.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(num.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(num.get_mantissa(), static_cast<UInt128>(0x2) << 108);
EXPECT_EQ(num.uintval(), static_cast<UInt128>(0x3FFF2) << 108);
EXPECT_STREQ(LIBC_NAMESPACE::str(num).c_str(),
Expand All @@ -278,7 +278,7 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {

LongDoubleBits negnum(-1.125l);
EXPECT_EQ(negnum.get_sign(), true);
EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negnum.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negnum.get_mantissa(), static_cast<UInt128>(0x2) << 108);
EXPECT_EQ(negnum.uintval(), static_cast<UInt128>(0xBFFF2) << 108);
EXPECT_STREQ(LIBC_NAMESPACE::str(negnum).c_str(),
Expand All @@ -303,7 +303,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {

Float128Bits zero(Float128Bits::zero());
EXPECT_EQ(zero.get_sign(), false);
EXPECT_EQ(zero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(zero.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(zero.uintval(), static_cast<UInt128>(0x0000000000000000) << 64);
Expand All @@ -313,7 +313,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {

Float128Bits negzero(Float128Bits::neg_zero());
EXPECT_EQ(negzero.get_sign(), true);
EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_biased_exponent(), static_cast<uint16_t>(0x0000));
EXPECT_EQ(negzero.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(negzero.uintval(), static_cast<UInt128>(0x1) << 127);
Expand All @@ -323,7 +323,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {

Float128Bits one(float128(1.0));
EXPECT_EQ(one.get_sign(), false);
EXPECT_EQ(one.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(one.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(one.get_mantissa(), static_cast<UInt128>(0x0000000000000000) << 64);
EXPECT_EQ(one.uintval(), static_cast<UInt128>(0x3FFF) << 112);
EXPECT_STREQ(LIBC_NAMESPACE::str(one).c_str(),
Expand All @@ -332,7 +332,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {

Float128Bits negone(float128(-1.0));
EXPECT_EQ(negone.get_sign(), true);
EXPECT_EQ(negone.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negone.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negone.get_mantissa(), static_cast<UInt128>(0x0000000000000000)
<< 64);
EXPECT_EQ(negone.uintval(), static_cast<UInt128>(0xBFFF) << 112);
Expand All @@ -342,7 +342,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {

Float128Bits num(float128(1.125));
EXPECT_EQ(num.get_sign(), false);
EXPECT_EQ(num.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(num.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(num.get_mantissa(), static_cast<UInt128>(0x2) << 108);
EXPECT_EQ(num.uintval(), static_cast<UInt128>(0x3FFF2) << 108);
EXPECT_STREQ(LIBC_NAMESPACE::str(num).c_str(),
Expand All @@ -351,7 +351,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {

Float128Bits negnum(float128(-1.125));
EXPECT_EQ(negnum.get_sign(), true);
EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negnum.get_biased_exponent(), static_cast<uint16_t>(0x3FFF));
EXPECT_EQ(negnum.get_mantissa(), static_cast<UInt128>(0x2) << 108);
EXPECT_EQ(negnum.uintval(), static_cast<UInt128>(0xBFFF2) << 108);
EXPECT_STREQ(LIBC_NAMESPACE::str(negnum).c_str(),
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/LdExpTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class LdExpTestTemplate : public LIBC_NAMESPACE::testing::Test {
FPBits result_bits(result);
ASSERT_FALSE(result_bits.is_zero());
// Verify that the result is indeed subnormal.
ASSERT_EQ(result_bits.get_unbiased_exponent(), uint16_t(0));
ASSERT_EQ(result_bits.get_biased_exponent(), uint16_t(0));
// But if the exp is so less that normalization leads to zero, then
// the result should be zero.
result = func(x, -FPBits::MAX_EXPONENT - int(MANTISSA_WIDTH) - 5);
Expand Down
14 changes: 6 additions & 8 deletions libc/test/src/math/NextAfterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,30 +162,28 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::Test {
result = func(x, 0);
FPBits x_bits = FPBits(x);
FPBits result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_biased_exponent(),
uint16_t(x_bits.get_biased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);

result = func(x, T(33.0));
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_biased_exponent(), x_bits.get_biased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));

x = -x;

result = func(x, 0);
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_biased_exponent(),
uint16_t(x_bits.get_biased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);

result = func(x, T(-33.0));
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_biased_exponent(), x_bits.get_biased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));
}
};
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/RoundToIntegerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class RoundToIntegerTestTemplate : public LIBC_NAMESPACE::testing::Test {
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
bits.set_unbiased_exponent(EXPONENT_LIMIT + FPBits::EXPONENT_BIAS);
bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXPONENT_BIAS);
bits.set_sign(1);
bits.set_mantissa(0);

Expand Down Expand Up @@ -190,7 +190,7 @@ class RoundToIntegerTestTemplate : public LIBC_NAMESPACE::testing::Test {
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
bits.set_unbiased_exponent(EXPONENT_LIMIT + FPBits::EXPONENT_BIAS);
bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXPONENT_BIAS);
bits.set_sign(1);
bits.set_mantissa(UIntType(0x1)
<< (LIBC_NAMESPACE::fputil::MantissaWidth<F>::VALUE - 1));
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/LdExpTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class LdExpTestTemplate : public LIBC_NAMESPACE::testing::Test {
FPBits result_bits(result);
ASSERT_FALSE(result_bits.is_zero());
// Verify that the result is indeed subnormal.
ASSERT_EQ(result_bits.get_unbiased_exponent(), uint16_t(0));
ASSERT_EQ(result_bits.get_biased_exponent(), uint16_t(0));
// But if the exp is so less that normalization leads to zero, then
// the result should be zero.
result = func(x, -FPBits::MAX_EXPONENT - int(MANTISSA_WIDTH) - 5);
Expand Down
14 changes: 6 additions & 8 deletions libc/test/src/math/smoke/NextAfterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,28 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::Test {
result = func(x, 0);
FPBits x_bits = FPBits(x);
FPBits result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_biased_exponent(),
uint16_t(x_bits.get_biased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);

result = func(x, T(33.0));
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_biased_exponent(), x_bits.get_biased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));

x = -x;

result = func(x, 0);
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_biased_exponent(),
uint16_t(x_bits.get_biased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);

result = func(x, T(-33.0));
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_biased_exponent(), x_bits.get_biased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));
}
};
Expand Down
14 changes: 6 additions & 8 deletions libc/test/src/math/smoke/NextTowardTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,28 @@ class NextTowardTestTemplate : public LIBC_NAMESPACE::testing::Test {
result = func(x, 0);
FPBits x_bits = FPBits(x);
FPBits result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_biased_exponent(),
uint16_t(x_bits.get_biased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);

result = func(x, 33.0);
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_biased_exponent(), x_bits.get_biased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));

x = -x;

result = func(x, 0);
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_biased_exponent(),
uint16_t(x_bits.get_biased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);

result = func(x, -33.0);
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_biased_exponent(), x_bits.get_biased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));
}
};
Expand Down
10 changes: 5 additions & 5 deletions libc/test/utils/FPUtil/x86_long_double_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
constexpr uint32_t COUNT = 100'000;

FPBits bits(0.0l);
bits.set_unbiased_exponent(FPBits::MAX_EXPONENT);
bits.set_biased_exponent(FPBits::MAX_EXPONENT);
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent has the max value and the implicit bit is 0,
// then the number is a NaN for all values of mantissa.
Expand All @@ -43,7 +43,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
ASSERT_TRUE(bits.is_nan());
}

bits.set_unbiased_exponent(1);
bits.set_biased_exponent(1);
bits.set_implicit_bit(0);
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent is non-zero and also not max, and the implicit bit is 0,
Expand All @@ -54,7 +54,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
ASSERT_TRUE(bits.is_nan());
}

bits.set_unbiased_exponent(1);
bits.set_biased_exponent(1);
bits.set_implicit_bit(1);
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent is non-zero and also not max, and the implicit bit is 1,
Expand All @@ -65,7 +65,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
ASSERT_FALSE(bits.is_nan());
}

bits.set_unbiased_exponent(0);
bits.set_biased_exponent(0);
bits.set_implicit_bit(1);
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent is zero, then the number is a valid but denormal value.
Expand All @@ -75,7 +75,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
ASSERT_FALSE(bits.is_nan());
}

bits.set_unbiased_exponent(0);
bits.set_biased_exponent(0);
bits.set_implicit_bit(0);
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent is zero, then the number is a valid but denormal value.
Expand Down
8 changes: 4 additions & 4 deletions libc/utils/MPFRWrapper/MPFRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ class MPFRNumber {
int thisExponent = fputil::FPBits<T>(thisAsT).get_exponent();
int inputExponent = fputil::FPBits<T>(input).get_exponent();
// Adjust the exponents for denormal numbers.
if (fputil::FPBits<T>(thisAsT).get_unbiased_exponent() == 0)
if (fputil::FPBits<T>(thisAsT).get_biased_exponent() == 0)
++thisExponent;
if (fputil::FPBits<T>(input).get_unbiased_exponent() == 0)
if (fputil::FPBits<T>(input).get_biased_exponent() == 0)
++inputExponent;

if (thisAsT * input < 0 || thisExponent == inputExponent) {
Expand All @@ -483,9 +483,9 @@ class MPFRNumber {
int minExponent = fputil::FPBits<T>(min).get_exponent();
int maxExponent = fputil::FPBits<T>(max).get_exponent();
// Adjust the exponents for denormal numbers.
if (fputil::FPBits<T>(min).get_unbiased_exponent() == 0)
if (fputil::FPBits<T>(min).get_biased_exponent() == 0)
++minExponent;
if (fputil::FPBits<T>(max).get_unbiased_exponent() == 0)
if (fputil::FPBits<T>(max).get_biased_exponent() == 0)
++maxExponent;

MPFRNumber minMPFR(min);
Expand Down