[libc][NFC] Remove FPBits cast operator (#79142)

The semantics for casting can range from "bitcast" (same representation)
to "different representation", to "type promotion". Here we remove the
cast operator and force usage of `get_val` as the only function to get
the floating point value, making the intent clearer and more consistent.
This commit is contained in:
Guillaume Chatelet 2024-01-23 17:30:19 +01:00 committed by GitHub
parent e1aa5b1fd1
commit 2856db0d3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
102 changed files with 365 additions and 368 deletions

View File

@ -21,7 +21,7 @@ template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE T abs(T x) {
FPBits<T> bits(x);
bits.set_sign(Sign::POS);
return T(bits);
return bits.get_val();
}
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>

View File

@ -86,7 +86,7 @@ LIBC_INLINE T remquo(T x, T y, int &q) {
// then the conversion to native remainder value should be updated
// appropriately and some directed tests added.
T native_remainder(remainder);
T absy = T(ybits);
T absy = ybits.get_val();
int cmp = remainder.mul2(1).cmp(normaly);
if (cmp > 0) {
q = q + 1;

View File

@ -727,8 +727,6 @@ struct FPBits final : public internal::FPRep<get_fp_type<T>(), FPBits<T>> {
// Floating-point conversions.
LIBC_INLINE constexpr T get_val() const { return cpp::bit_cast<T>(bits); }
LIBC_INLINE constexpr explicit operator T() const { return get_val(); }
// TODO: Use an uint32_t for 'biased_exp'.
LIBC_INLINE static constexpr FPBits<T>
create_value(Sign sign, StorageType biased_exp, StorageType mantissa) {

View File

@ -111,7 +111,7 @@ LIBC_INLINE T hypot(T x, T y) {
FPBits_t x_bits(x), y_bits(y);
if (x_bits.is_inf() || y_bits.is_inf()) {
return T(FPBits_t::inf());
return FPBits_t::inf().get_val();
}
if (x_bits.is_nan()) {
return x;
@ -196,8 +196,8 @@ LIBC_INLINE T hypot(T x, T y) {
if (out_exp >= FPBits_t::MAX_BIASED_EXPONENT) {
if (int round_mode = quick_get_round();
round_mode == FE_TONEAREST || round_mode == FE_UPWARD)
return T(FPBits_t::inf());
return T(FPBits_t::max_normal());
return FPBits_t::inf().get_val();
return FPBits_t::max_normal().get_val();
}
} else {
// For denormal result, we simply move the leading bit of the result to
@ -253,8 +253,8 @@ LIBC_INLINE T hypot(T x, T y) {
++out_exp;
if (out_exp >= FPBits_t::MAX_BIASED_EXPONENT) {
if (round_mode == FE_TONEAREST || round_mode == FE_UPWARD)
return T(FPBits_t::inf());
return T(FPBits_t::max_normal());
return FPBits_t::inf().get_val();
return FPBits_t::max_normal().get_val();
}
}

View File

@ -49,13 +49,13 @@ LIBC_INLINE T modf(T x, T &iptr) {
return x;
} else if (bits.is_inf()) {
iptr = x;
return T(FPBits<T>::zero(bits.sign()));
return FPBits<T>::zero(bits.sign()).get_val();
} else {
iptr = trunc(x);
if (x == iptr) {
// If x is already an integer value, then return zero with the right
// sign.
return T(FPBits<T>::zero(bits.sign()));
return FPBits<T>::zero(bits.sign()).get_val();
} else {
return x - iptr;
}
@ -66,7 +66,7 @@ template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE T copysign(T x, T y) {
FPBits<T> xbits(x);
xbits.set_sign(FPBits<T>(y).sign());
return T(xbits);
return xbits.get_val();
}
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
@ -103,12 +103,12 @@ LIBC_INLINE T logb(T x) {
if (bits.is_zero()) {
// TODO(Floating point exception): Raise div-by-zero exception.
// TODO(errno): POSIX requires setting errno to ERANGE.
return T(FPBits<T>::inf(Sign::NEG));
return FPBits<T>::inf(Sign::NEG).get_val();
} else if (bits.is_nan()) {
return x;
} else if (bits.is_inf()) {
// Return positive infinity.
return T(FPBits<T>::inf());
return FPBits<T>::inf().get_val();
}
NormalFloat<T> normal(bits);
@ -131,11 +131,11 @@ LIBC_INLINE T ldexp(T x, int exp) {
// calculating the limit.
int exp_limit = FPBits<T>::MAX_BIASED_EXPONENT + FPBits<T>::FRACTION_LEN + 1;
if (exp > exp_limit)
return T(FPBits<T>::inf(bits.sign()));
return FPBits<T>::inf(bits.sign()).get_val();
// Similarly on the negative side we return zero early if |exp| is too small.
if (exp < -exp_limit)
return T(FPBits<T>::zero(bits.sign()));
return FPBits<T>::zero(bits.sign()).get_val();
// For all other values, NormalFloat to T conversion handles it the right way.
NormalFloat<T> normal(bits);

View File

@ -41,11 +41,11 @@ LIBC_INLINE T trunc(T x) {
// If the exponent is such that abs(x) is less than 1, then return 0.
if (exponent <= -1)
return T(FPBits<T>::zero(bits.sign()));
return FPBits<T>::zero(bits.sign()).get_val();
int trim_size = FPBits<T>::FRACTION_LEN - exponent;
bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size);
return T(bits);
return bits.get_val();
}
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
@ -73,7 +73,7 @@ LIBC_INLINE T ceil(T x) {
uint32_t trim_size = FPBits<T>::FRACTION_LEN - exponent;
bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size);
T trunc_value = T(bits);
T trunc_value = bits.get_val();
// If x is already an integer, return it.
if (trunc_value == x)
@ -114,19 +114,19 @@ LIBC_INLINE T round(T x) {
if (exponent == -1) {
// Absolute value of x is greater than equal to 0.5 but less than 1.
return T(FPBits<T>::one(bits.sign()));
return FPBits<T>::one(bits.sign()).get_val();
}
if (exponent <= -2) {
// Absolute value of x is less than 0.5.
return T(FPBits<T>::zero(bits.sign()));
return FPBits<T>::zero(bits.sign()).get_val();
}
uint32_t trim_size = FPBits<T>::FRACTION_LEN - exponent;
bool half_bit_set =
bool(bits.get_mantissa() & (StorageType(1) << (trim_size - 1)));
bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size);
T trunc_value = T(bits);
T trunc_value = bits.get_val();
// If x is already an integer, return it.
if (trunc_value == x)
@ -180,7 +180,7 @@ LIBC_INLINE T round_using_current_rounding_mode(T x) {
uint32_t trim_size = FPBits<T>::FRACTION_LEN - exponent;
FPBits<T> new_bits = bits;
new_bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size);
T trunc_value = T(new_bits);
T trunc_value = new_bits.get_val();
// If x is already an integer, return it.
if (trunc_value == x)

View File

@ -96,7 +96,7 @@ template <typename T> struct NormalFloat {
// Max exponent is of the form 0xFF...E. That is why -2 and not -1.
constexpr int MAX_EXPONENT_VALUE = (1 << FPBits<T>::EXP_LEN) - 2;
if (biased_exponent > MAX_EXPONENT_VALUE) {
return T(FPBits<T>::inf(sign));
return FPBits<T>::inf(sign).get_val();
}
FPBits<T> result(T(0.0));
@ -129,15 +129,15 @@ template <typename T> struct NormalFloat {
// the overflow into the exponent.
if (new_mantissa == ONE)
result.set_biased_exponent(1);
return T(result);
return result.get_val();
} else {
return T(result);
return result.get_val();
}
}
result.set_biased_exponent(exponent + FPBits<T>::EXP_BIAS);
result.set_mantissa(mantissa);
return T(result);
return result.get_val();
}
private:
@ -250,16 +250,16 @@ template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
} else {
result.set_implicit_bit(0);
}
return static_cast<long double>(result);
return result.get_val();
} else {
return static_cast<long double>(result);
return result.get_val();
}
}
result.set_biased_exponent(biased_exponent);
result.set_mantissa(mantissa);
result.set_implicit_bit(1);
return static_cast<long double>(result);
return result.get_val();
}
#endif // LIBC_LONG_DOUBLE_IS_X86_FLOAT80

View File

@ -58,8 +58,8 @@ template <> LIBC_INLINE float fma<float>(float x, float y, float z) {
// correct (when it matters).
fputil::FPBits<double> t(
(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)));
? ((bit_sum.get_val() - bit_prod.get_val()) - bitz.get_val())
: ((bit_sum.get_val() - bitz.get_val()) - bit_prod.get_val()));
// Update sticky bits if t != 0.0 and the least (52 - 23 - 1 = 28) bits are
// zero.
@ -72,7 +72,7 @@ template <> LIBC_INLINE float fma<float>(float x, float y, float z) {
}
}
return static_cast<float>(static_cast<double>(bit_sum));
return static_cast<float>(bit_sum.get_val());
}
namespace internal {
@ -257,7 +257,7 @@ template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
(round_mode == FE_DOWNWARD && prod_sign.is_pos())) {
return FPBits::max_normal(prod_sign).get_val();
}
return static_cast<double>(FPBits::inf(prod_sign));
return FPBits::inf(prod_sign).get_val();
}
// Remove hidden bit and append the exponent field and sign bit.

View File

@ -568,11 +568,11 @@ clinger_fast_path(ExpandedFloat<T> init_num,
ClingerConsts<T>::POWERS_OF_TEN_ARRAY[exp10]);
// If the results are equal, then we don't need to use the rounding mode.
if (T(result) != -T(negative_result)) {
if (result.get_val() != -negative_result.get_val()) {
FPBits lower_result;
FPBits higher_result;
if (T(result) < -T(negative_result)) {
if (result.get_val() < -negative_result.get_val()) {
lower_result = result;
higher_result = negative_result;
} else {
@ -1194,7 +1194,7 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
// special 80 bit long doubles. Otherwise it should be inlined out.
set_implicit_bit<T>(result);
return {T(result), index, error};
return {result.get_val(), index, error};
}
template <class T> LIBC_INLINE StrToNumResult<T> strtonan(const char *arg) {
@ -1216,7 +1216,7 @@ template <class T> LIBC_INLINE StrToNumResult<T> strtonan(const char *arg) {
}
result = FPBits::build_quiet_nan(fputil::Sign::POS, nan_mantissa);
return {T(result), 0, error};
return {result.get_val(), 0, error};
}
} // namespace internal

View File

@ -222,7 +222,7 @@ double set_exceptional(double x) {
fputil::raise_except_if_required(FE_OVERFLOW);
}
// x is +inf or nan
return x + static_cast<double>(FPBits::inf());
return x + FPBits::inf().get_val();
}
} // namespace

View File

@ -268,7 +268,7 @@ double set_exceptional(double x) {
fputil::raise_except_if_required(FE_OVERFLOW);
}
// x is +inf or nan
return x + static_cast<double>(FPBits::inf());
return x + FPBits::inf().get_val();
}
} // namespace

View File

@ -243,7 +243,7 @@ double set_exceptional(double x) {
fputil::raise_except_if_required(FE_OVERFLOW);
}
// x is +inf or nan
return x + static_cast<double>(FPBits::inf());
return x + FPBits::inf().get_val();
}
} // namespace

View File

@ -67,7 +67,7 @@ LLVM_LIBC_FUNCTION(float, expf, (float x)) {
fputil::raise_except_if_required(FE_OVERFLOW);
}
// x is +inf or nan
return x + static_cast<float>(FPBits::inf());
return x + FPBits::inf().get_val();
}
}
// For -104 < x < 89, to compute exp(x), we perform the following range

View File

@ -46,7 +46,7 @@ LLVM_LIBC_FUNCTION(float, hypotf, (float x, float y)) {
if (!DoubleBits(sum_sq).is_inf_or_nan()) {
// Correct rounding.
double r_sq = static_cast<double>(result) * static_cast<double>(result);
double r_sq = result.get_val() * result.get_val();
double diff = sum_sq - r_sq;
constexpr uint64_t mask = 0x0000'0000'3FFF'FFFFULL;
uint64_t lrs = result.uintval() & mask;
@ -60,14 +60,14 @@ LLVM_LIBC_FUNCTION(float, hypotf, (float x, float y)) {
FPBits bits_x(x), bits_y(y);
if (bits_x.is_inf_or_nan() || bits_y.is_inf_or_nan()) {
if (bits_x.is_inf() || bits_y.is_inf())
return static_cast<float>(FPBits::inf());
return FPBits::inf().get_val();
if (bits_x.is_nan())
return x;
return y;
}
}
return static_cast<float>(static_cast<double>(result));
return static_cast<float>(result.get_val());
}
} // namespace LIBC_NAMESPACE

View File

@ -191,7 +191,7 @@ LLVM_LIBC_FUNCTION(float, log10f, (float x)) {
// Set bits to 1.m
xbits.set_biased_exponent(0x7F);
float u = static_cast<float>(xbits);
float u = xbits.get_val();
double v;
#ifdef LIBC_TARGET_CPU_HAS_FMA
v = static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.

View File

@ -66,7 +66,7 @@ LIBC_INLINE float log(double x) {
// Clear the lowest 45 bits.
f.bits &= ~0x0000'1FFF'FFFF'FFFFULL;
double d = static_cast<double>(xbits) - static_cast<double>(f);
double d = xbits.get_val() - f.get_val();
d *= ONE_OVER_F[f_index];
double extra_factor = fputil::multiply_add(m, LOG_2, LOG_F[f_index]);
@ -106,7 +106,7 @@ LLVM_LIBC_FUNCTION(float, log1pf, (float x)) {
case 0xbf800000U: // x = -1.0
fputil::set_errno_if_required(ERANGE);
fputil::raise_except_if_required(FE_DIVBYZERO);
return static_cast<float>(fputil::FPBits<float>::inf(fputil::Sign::NEG));
return FPBits::inf(fputil::Sign::NEG).get_val();
#ifndef LIBC_TARGET_CPU_HAS_FMA
case 0x4cc1c80bU: // x = 0x1.839016p+26f
return fputil::round_result_slightly_down(0x1.26fc04p+4f);

View File

@ -94,7 +94,7 @@ LLVM_LIBC_FUNCTION(float, log2f, (float x)) {
// Set bits to 1.m
xbits.set_biased_exponent(0x7F);
float u = static_cast<float>(xbits);
float u = xbits.get_val();
double v;
#ifdef LIBC_TARGET_CPU_HAS_FMA
v = static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.

View File

@ -85,7 +85,7 @@ LLVM_LIBC_FUNCTION(float, logf, (float x)) {
// Return -inf and raise FE_DIVBYZERO
fputil::set_errno_if_required(ERANGE);
fputil::raise_except_if_required(FE_DIVBYZERO);
return static_cast<float>(FPBits::inf(fputil::Sign::NEG));
return FPBits::inf(Sign::NEG).get_val();
}
// Normalize denormal inputs.
xbits = FPBits(xbits.get_val() * 0x1.0p23f);
@ -149,7 +149,7 @@ LLVM_LIBC_FUNCTION(float, logf, (float x)) {
// Set bits to 1.m
xbits.set_biased_exponent(0x7F);
float u = static_cast<float>(xbits);
float u = xbits.get_val();
double v;
#ifdef LIBC_TARGET_CPU_HAS_FMA
v = static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.

View File

@ -52,7 +52,7 @@ LIBC_INLINE int64_t large_range_reduction(double x, int x_exp, double &y) {
// least 2^6.
fputil::FPBits<double> prod_hi(x * THIRTYTWO_OVER_PI[0]);
prod_hi.bits &= (x_exp < 55) ? (~0xfffULL) : (~0ULL); // |x| < 2^55
double k_hi = fputil::nearest_integer(static_cast<double>(prod_hi));
double k_hi = fputil::nearest_integer(prod_hi.get_val());
double truncated_prod = fputil::fma(x, THIRTYTWO_OVER_PI[0], -k_hi);
double prod_lo = fputil::fma(x, THIRTYTWO_OVER_PI[1], truncated_prod);
double k_lo = fputil::nearest_integer(prod_lo);
@ -71,7 +71,7 @@ LIBC_INLINE int64_t large_range_reduction(double x, int x_exp, double &y) {
// least 64.
fputil::FPBits<double> prod_hi(x * THIRTYTWO_OVER_PI[1]);
prod_hi.bits &= (x_exp < 110) ? (~0xfffULL) : (~0ULL); // |x| < 2^110
double k_hi = fputil::nearest_integer(static_cast<double>(prod_hi));
double k_hi = fputil::nearest_integer(prod_hi.get_val());
double truncated_prod = fputil::fma(x, THIRTYTWO_OVER_PI[1], -k_hi);
double prod_lo = fputil::fma(x, THIRTYTWO_OVER_PI[2], truncated_prod);
double k_lo = fputil::nearest_integer(prod_lo);

View File

@ -498,7 +498,7 @@ LIBC_INLINE int convert_float_decimal_typed(Writer *writer,
PaddingWriter padding_writer(to_conv, sign_char);
FloatWriter float_writer(writer, has_decimal_point, padding_writer);
FloatToString<T> float_converter(static_cast<T>(float_bits));
FloatToString<T> float_converter(float_bits.get_val());
const size_t positive_blocks = float_converter.get_positive_blocks();
@ -608,7 +608,7 @@ LIBC_INLINE int convert_float_dec_exp_typed(Writer *writer,
PaddingWriter padding_writer(to_conv, sign_char);
FloatWriter float_writer(writer, has_decimal_point, padding_writer);
FloatToString<T> float_converter(static_cast<T>(float_bits));
FloatToString<T> float_converter(float_bits.get_val());
size_t digits_written = 0;
int final_exponent = 0;
@ -767,7 +767,7 @@ LIBC_INLINE int convert_float_dec_auto_typed(Writer *writer,
// it has style E, so here we calculate the precision we'll use in that case.
const unsigned int exp_precision = init_precision - 1;
FloatToString<T> float_converter(static_cast<T>(float_bits));
FloatToString<T> float_converter(float_bits.get_val());
// Here we would subtract 1 to account for the fact that block 0 counts as a
// positive block, but the loop below accounts for this by starting with

View File

@ -66,16 +66,16 @@ template <typename T> struct FPTest : public Test {
using Sign = LIBC_NAMESPACE::fputil::Sign;
static constexpr StorageType STORAGE_MAX =
LIBC_NAMESPACE::cpp::numeric_limits<StorageType>::max();
static constexpr T zero = T(FPBits::zero(Sign::POS));
static constexpr T neg_zero = T(FPBits::zero(Sign::NEG));
static constexpr T aNaN = T(FPBits::build_quiet_nan());
static constexpr T sNaN = T(FPBits::build_nan(Sign::POS, 1));
static constexpr T inf = T(FPBits::inf(Sign::POS));
static constexpr T neg_inf = T(FPBits::inf(Sign::NEG));
static constexpr T min_normal = T(FPBits::min_normal());
static constexpr T max_normal = T(FPBits::max_normal());
static constexpr T min_denormal = T(FPBits::min_subnormal());
static constexpr T max_denormal = T(FPBits::max_subnormal());
static constexpr T zero = FPBits::zero(Sign::POS).get_val();
static constexpr T neg_zero = FPBits::zero(Sign::NEG).get_val();
static constexpr T aNaN = FPBits::build_quiet_nan().get_val();
static constexpr T sNaN = FPBits::build_nan(Sign::POS, 1).get_val();
static constexpr T inf = FPBits::inf(Sign::POS).get_val();
static constexpr T neg_inf = FPBits::inf(Sign::NEG).get_val();
static constexpr T min_normal = FPBits::min_normal().get_val();
static constexpr T max_normal = FPBits::max_normal().get_val();
static constexpr T min_denormal = FPBits::min_subnormal().get_val();
static constexpr T max_denormal = FPBits::max_subnormal().get_val();
static constexpr int N_ROUNDING_MODES = 4;
static constexpr fputil::testing::RoundingMode ROUNDING_MODES[4] = {
@ -95,16 +95,16 @@ template <typename T> struct FPTest : public Test {
using Sign = LIBC_NAMESPACE::fputil::Sign; \
static constexpr StorageType STORAGE_MAX = \
LIBC_NAMESPACE::cpp::numeric_limits<StorageType>::max(); \
const T zero = T(FPBits::zero(Sign::POS)); \
const T neg_zero = T(FPBits::zero(Sign::NEG)); \
const T aNaN = T(FPBits::build_quiet_nan()); \
const T sNaN = T(FPBits::build_nan(Sign::POS, 1)); \
const T inf = T(FPBits::inf(Sign::POS)); \
const T neg_inf = T(FPBits::inf(Sign::NEG)); \
const T min_normal = T(FPBits::min_normal()); \
const T max_normal = T(FPBits::max_normal()); \
const T min_denormal = T(FPBits::min_subnormal()); \
const T max_denormal = T(FPBits::max_subnormal());
const T zero = FPBits::zero(Sign::POS).get_val(); \
const T neg_zero = FPBits::zero(Sign::NEG).get_val(); \
const T aNaN = FPBits::build_quiet_nan().get_val(); \
const T sNaN = FPBits::build_nan(Sign::POS, 1).get_val(); \
const T inf = FPBits::inf(Sign::POS).get_val(); \
const T neg_inf = FPBits::inf(Sign::NEG).get_val(); \
const T min_normal = FPBits::min_normal().get_val(); \
const T max_normal = FPBits::max_normal().get_val(); \
const T min_denormal = FPBits::min_subnormal().get_val(); \
const T max_denormal = FPBits::max_subnormal().get_val();
#define EXPECT_FP_EQ(expected, actual) \
EXPECT_THAT(actual, LIBC_NAMESPACE::testing::getMatcher< \

View File

@ -67,7 +67,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;

View File

@ -37,7 +37,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;

View File

@ -35,7 +35,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, func(x), 0.0);

View File

@ -20,11 +20,11 @@ public:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
void test_na_n_arg(FuncPtr func) {
EXPECT_FP_EQ(nan, func(nan, inf));
@ -66,7 +66,7 @@ public:
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))

View File

@ -59,7 +59,7 @@ public:
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))

View File

@ -59,7 +59,7 @@ public:
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))

View File

@ -67,7 +67,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;

View File

@ -25,14 +25,14 @@ private:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T min_subnormal = T(FPBits::min_subnormal(Sign::POS));
const T min_normal = T(FPBits::min_normal(Sign::POS));
const T max_normal = T(FPBits::max_normal(Sign::POS));
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T min_subnormal = FPBits::min_subnormal(Sign::POS).get_val();
const T min_normal = FPBits::min_normal(Sign::POS).get_val();
const T max_normal = FPBits::max_normal(Sign::POS).get_val();
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
static constexpr StorageType MAX_NORMAL = FPBits::max_normal().uintval();
static constexpr StorageType MIN_NORMAL = FPBits::min_normal().uintval();
@ -63,9 +63,9 @@ public:
// Test underflow rounding up.
EXPECT_FP_EQ(func(T(0.5), min_subnormal, min_subnormal),
T(FPBits(StorageType(2))));
FPBits(StorageType(2)).get_val());
// Test underflow rounding down.
T v = T(FPBits(MIN_NORMAL + StorageType(1)));
T v = FPBits(MIN_NORMAL + StorageType(1)).get_val();
EXPECT_FP_EQ(func(T(1) / T(MIN_NORMAL << 1), v, min_normal), v);
// Test overflow.
T z = max_normal;
@ -80,8 +80,8 @@ public:
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
T x = T(FPBits(get_random_bit_pattern())), y = T(FPBits(v)),
z = T(FPBits(w));
T x = FPBits(get_random_bit_pattern()).get_val(), y = FPBits(v).get_val(),
z = FPBits(w).get_val();
mpfr::TernaryInput<T> input{x, y, z};
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Fma, input, func(x, y, z),
0.5);
@ -93,8 +93,8 @@ public:
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
for (StorageType v = MIN_NORMAL, w = MAX_NORMAL;
v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w)),
z = T(FPBits(get_random_bit_pattern()));
T x = FPBits(v).get_val(), y = FPBits(w).get_val(),
z = FPBits(get_random_bit_pattern()).get_val();
mpfr::TernaryInput<T> input{x, y, z};
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Fma, input, func(x, y, z),
0.5);

View File

@ -96,7 +96,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = static_cast<T>(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0l)
continue;

View File

@ -25,15 +25,15 @@ private:
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
using Sign = LIBC_NAMESPACE::fputil::Sign;
using StorageType = typename FPBits::StorageType;
const T nan = T(FPBits::build_quiet_nan());
const T inf = T(FPBits::inf());
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero());
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T max_normal = T(FPBits::max_normal());
const T min_normal = T(FPBits::min_normal());
const T max_subnormal = T(FPBits::max_subnormal());
const T min_subnormal = T(FPBits::min_subnormal());
const T nan = FPBits::build_quiet_nan().get_val();
const T inf = FPBits::inf().get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero().get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T max_normal = FPBits::max_normal().get_val();
const T min_normal = FPBits::min_normal().get_val();
const T max_subnormal = FPBits::max_subnormal().get_val();
const T min_subnormal = FPBits::min_subnormal().get_val();
static constexpr StorageType MAX_NORMAL = FPBits::max_normal().uintval();
static constexpr StorageType MIN_NORMAL = FPBits::min_normal().uintval();
@ -74,7 +74,7 @@ public:
for (int signs = 0; signs < 4; ++signs) {
for (StorageType v = MIN_SUBNORMAL, w = max_value;
v <= max_value && w >= MIN_SUBNORMAL; v += step, w -= step) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (signs % 2 == 1) {
x = -x;
}
@ -96,7 +96,7 @@ public:
for (int signs = 0; signs < 4; ++signs) {
for (StorageType v = MIN_NORMAL, w = MAX_NORMAL;
v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (signs % 2 == 1) {
x = -x;
}

View File

@ -26,11 +26,11 @@ public:
void test_special_numbers(typename ILogbFunc<T>::Func func) {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
using Sign = LIBC_NAMESPACE::fputil::Sign;
EXPECT_EQ(FP_ILOGB0, func(T(FPBits::zero(Sign::POS))));
EXPECT_EQ(FP_ILOGB0, func(T(FPBits::zero(Sign::NEG))));
EXPECT_EQ(FP_ILOGBNAN, func(T(FPBits::build_quiet_nan())));
EXPECT_EQ(INT_MAX, func(T(FPBits::inf(Sign::POS))));
EXPECT_EQ(INT_MAX, func(T(FPBits::inf(Sign::NEG))));
EXPECT_EQ(FP_ILOGB0, func(FPBits::zero(Sign::POS).get_val()));
EXPECT_EQ(FP_ILOGB0, func(FPBits::zero(Sign::NEG).get_val()));
EXPECT_EQ(FP_ILOGBNAN, func(FPBits::build_quiet_nan().get_val()));
EXPECT_EQ(INT_MAX, func(FPBits::inf(Sign::POS).get_val()));
EXPECT_EQ(INT_MAX, func(FPBits::inf(Sign::NEG).get_val()));
}
template <typename T>
@ -81,7 +81,7 @@ public:
constexpr StorageType COUNT = 10'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType v = MIN_SUBNORMAL; v <= MAX_SUBNORMAL; v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0)
continue;
@ -100,7 +100,7 @@ public:
constexpr StorageType COUNT = 10'001;
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
for (StorageType v = MIN_NORMAL; v <= MAX_NORMAL; v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0)
continue;

View File

@ -25,11 +25,11 @@ class LdExpTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
// A normalized mantissa to be used with tests.
static constexpr StorageType MANTISSA = NormalFloat::ONE + 0x1234;

View File

@ -75,7 +75,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = static_cast<T>(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0l)
continue;

View File

@ -87,7 +87,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == T(0.0))
continue;

View File

@ -23,11 +23,11 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
const StorageType min_subnormal = FPBits::min_subnormal().uintval();
const StorageType max_subnormal = FPBits::max_subnormal().uintval();

View File

@ -34,11 +34,11 @@ private:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
static constexpr StorageType MIN_SUBNORMAL =
FPBits::min_subnormal().uintval();
@ -104,7 +104,7 @@ public:
constexpr StorageType COUNT = 100'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
T x = T(FPBits(i));
T x = FPBits(i).get_val();
for (int mode : ROUNDING_MODES) {
LIBC_NAMESPACE::fputil::set_round(mode);
mpfr::RoundingMode mpfr_mode = to_mpfr_rounding_mode(mode);
@ -117,7 +117,7 @@ public:
constexpr StorageType COUNT = 100'001;
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
T x = T(FPBits(i));
T x = FPBits(i).get_val();
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
if (isnan(x)) {

View File

@ -24,11 +24,11 @@ class RemQuoTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
static constexpr StorageType MIN_SUBNORMAL =
FPBits::min_subnormal().uintval();
@ -107,7 +107,7 @@ public:
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
mpfr::BinaryOutput<T> result;
mpfr::BinaryInput<T> input{x, y};
result.f = func(x, y, &result.i);
@ -120,7 +120,7 @@ public:
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
for (StorageType v = MIN_NORMAL, w = MAX_NORMAL;
v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
mpfr::BinaryOutput<T> result;
mpfr::BinaryInput<T> input{x, y};
result.f = func(x, y, &result.i);

View File

@ -67,7 +67,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;

View File

@ -33,11 +33,11 @@ private:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const F zero = F(FPBits::zero());
const F neg_zero = F(FPBits::zero(Sign::NEG));
const F inf = F(FPBits::inf());
const F neg_inf = F(FPBits::inf(Sign::NEG));
const F nan = F(FPBits::build_quiet_nan());
const F zero = FPBits::zero().get_val();
const F neg_zero = FPBits::zero(Sign::NEG).get_val();
const F inf = FPBits::inf().get_val();
const F neg_inf = FPBits::inf(Sign::NEG).get_val();
const F nan = FPBits::build_quiet_nan().get_val();
static constexpr StorageType MAX_NORMAL = FPBits::max_normal().uintval();
static constexpr StorageType MIN_NORMAL = FPBits::min_normal().uintval();
@ -139,7 +139,7 @@ public:
bits.set_sign(Sign::NEG);
bits.set_mantissa(0);
F x = F(bits);
F x = bits.get_val();
long mpfr_result;
bool erangeflag = mpfr::round_to_long(x, mpfr_result);
ASSERT_FALSE(erangeflag);
@ -203,7 +203,7 @@ public:
bits.set_sign(Sign::NEG);
bits.set_mantissa(FPBits::FRACTION_MASK);
F x = F(bits);
F x = bits.get_val();
if (TestModes) {
for (int m : ROUNDING_MODES) {
LIBC_NAMESPACE::fputil::set_round(m);
@ -225,7 +225,7 @@ public:
constexpr StorageType COUNT = 1'000'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = F(FPBits(i));
F x = FPBits(i).get_val();
if (x == F(0.0))
continue;
// All subnormal numbers should round to zero.
@ -267,7 +267,7 @@ public:
constexpr StorageType COUNT = 1'000'001;
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
F x = F(FPBits(i));
F x = FPBits(i).get_val();
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
if (isnan(x)) {

View File

@ -41,7 +41,7 @@ public:
for (StorageType mant = 1; mant < HIDDEN_BIT; mant <<= 1) {
FPBits denormal(T(0.0));
denormal.set_mantissa(mant);
T x = T(denormal);
T x = denormal.get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x, func(x), 0.5);
}

View File

@ -67,7 +67,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;

View File

@ -47,7 +47,7 @@ TEST_F(LlvmLibcAcosfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
@ -74,7 +74,7 @@ TEST_F(LlvmLibcAcosfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
LIBC_NAMESPACE::acosf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, -x,

View File

@ -44,7 +44,7 @@ TEST_F(LlvmLibcAcoshfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
@ -70,7 +70,7 @@ TEST_F(LlvmLibcAcoshfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
LIBC_NAMESPACE::acoshf(x), 0.5);
}

View File

@ -45,7 +45,7 @@ TEST_F(LlvmLibcAsinfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
@ -70,7 +70,7 @@ TEST_F(LlvmLibcAsinfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
LIBC_NAMESPACE::asinf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, -x,

View File

@ -44,7 +44,7 @@ TEST_F(LlvmLibcAsinhfTest, InFloatRange) {
constexpr uint32_t COUNT = 1'001;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
@ -71,7 +71,7 @@ TEST_F(LlvmLibcAsinhfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
LIBC_NAMESPACE::asinhf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, -x,

View File

@ -43,7 +43,7 @@ TEST_F(LlvmLibcAtanfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
const uint32_t STEP = FPBits(inf).uintval() / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
LIBC_NAMESPACE::atanf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, -x,
@ -56,7 +56,7 @@ TEST_F(LlvmLibcAtanfTest, SpecialValues) {
uint32_t val_arr[] = {0x3d8d6b23U, 0x3feefcfbU, 0xbd8d6b23U,
0xbfeefcfbU, 0x7F800000U, 0xFF800000U};
for (uint32_t v : val_arr) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
LIBC_NAMESPACE::atanf(x), 0.5);
}

View File

@ -88,7 +88,7 @@ TEST_F(LlvmLibcAtanhfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
const uint32_t STEP = FPBits(1.0f).uintval() / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
ASSERT_MPFR_MATCH(mpfr::Operation::Atanh, x, LIBC_NAMESPACE::atanhf(x),
0.5);
ASSERT_MPFR_MATCH(mpfr::Operation::Atanh, -x, LIBC_NAMESPACE::atanhf(-x),
@ -98,12 +98,12 @@ TEST_F(LlvmLibcAtanhfTest, InFloatRange) {
// For small values, atanh(x) is x.
TEST_F(LlvmLibcAtanhfTest, SmallValues) {
float x = float(FPBits(uint32_t(0x17800000)));
float x = FPBits(uint32_t(0x17800000)).get_val();
float result = LIBC_NAMESPACE::atanhf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Atanh, x, result, 0.5);
EXPECT_FP_EQ(x, result);
x = float(FPBits(uint32_t(0x00400000)));
x = FPBits(uint32_t(0x00400000)).get_val();
result = LIBC_NAMESPACE::atanhf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Atanh, x, result, 0.5);
EXPECT_FP_EQ(x, result);

View File

@ -22,7 +22,7 @@ TEST_F(LlvmLibcCosTest, Range) {
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
double x = double(FPBits(v));
double x = FPBits(v).get_val();
// TODO: Expand the range of testing after range reduction is implemented.
if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
continue;

View File

@ -46,7 +46,7 @@ TEST_F(LlvmLibcCosfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x,
@ -102,7 +102,7 @@ TEST_F(LlvmLibcCosfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x,
LIBC_NAMESPACE::cosf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, -x,
@ -114,7 +114,7 @@ TEST_F(LlvmLibcCosfTest, SpecificBitPatterns) {
// returns values furthest beyond its nominal upper bound of pi/4.
TEST_F(LlvmLibcCosfTest, SDCOMP_26094) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, LIBC_NAMESPACE::cosf(x), 0.5);
}
}

View File

@ -44,15 +44,15 @@ TEST_F(LlvmLibcCoshfTest, SpecialNumbers) {
TEST_F(LlvmLibcCoshfTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::coshf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::coshf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::coshf(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::coshf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::coshf(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::coshf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}
@ -60,7 +60,7 @@ TEST_F(LlvmLibcCoshfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Cosh, x, LIBC_NAMESPACE::coshf(x), 0.5);
@ -68,12 +68,12 @@ TEST_F(LlvmLibcCoshfTest, InFloatRange) {
}
TEST_F(LlvmLibcCoshfTest, SmallValues) {
float x = float(FPBits(0x17800000U));
float x = FPBits(0x17800000U).get_val();
float result = LIBC_NAMESPACE::coshf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Cosh, x, result, 0.5);
EXPECT_FP_EQ(1.0f, result);
x = float(FPBits(0x0040000U));
x = FPBits(0x0040000U).get_val();
result = LIBC_NAMESPACE::coshf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Cosh, x, result, 0.5);
EXPECT_FP_EQ(1.0f, result);

View File

@ -36,7 +36,7 @@ TEST_F(LlvmLibcErffTest, TrickyInputs) {
0x4004'1e6aU, // |x| = 0x1.083cd4p+1f
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Erf, x,
LIBC_NAMESPACE::erff(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Erf, -x,

View File

@ -55,7 +55,7 @@ struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
uint64_t failed = 0;
do {
FPBits xbits(bits);
FloatType x = FloatType(xbits);
FloatType x = xbits.get_val();
bool correct =
TEST_MPFR_MATCH_ROUNDING_SILENTLY(Op, x, FUNC(x), 0.5, rounding);
failed += (!correct);
@ -127,9 +127,8 @@ struct LlvmLibcExhaustiveMathTest
msg << "Test failed for " << std::dec << failed_in_range
<< " inputs in range: " << range_begin << " to " << range_end
<< " [0x" << std::hex << range_begin << ", 0x" << range_end
<< "), [" << std::hexfloat
<< static_cast<FloatType>(FPBits(range_begin)) << ", "
<< static_cast<FloatType>(FPBits(range_end)) << ")\n";
<< "), [" << std::hexfloat << FPBits(range_begin).get_val()
<< ", " << FPBits(range_end).get_val() << ")\n";
std::cerr << msg.str() << std::flush;
failed.fetch_add(failed_in_range);

View File

@ -31,10 +31,10 @@ struct HypotfChecker : public virtual LIBC_NAMESPACE::testing::Test {
uint32_t xbits = start;
uint64_t failed = 0;
do {
float x = float(FPBits(xbits));
float x = FPBits(xbits).get_val();
uint32_t ybits = Y_START;
do {
float y = float(FPBits(ybits));
float y = FPBits(ybits).get_val();
bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y),
LIBC_NAMESPACE::hypotf(x, y));
// Using MPFR will be much slower.

View File

@ -26,7 +26,7 @@ struct SincosfChecker : public virtual LIBC_NAMESPACE::testing::Test {
uint64_t failed = 0;
do {
FPBits xbits(bits);
FloatType x = FloatType(xbits);
FloatType x = xbits.get_val();
FloatType sinx, cosx;
LIBC_NAMESPACE::sincosf(x, &sinx, &cosx);

View File

@ -79,7 +79,7 @@ TEST_F(LlvmLibcExp10Test, TrickyInputs) {
0x4037000000000000, // x = 23
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
LIBC_NAMESPACE::exp10(x), 0.5);
}

View File

@ -42,30 +42,31 @@ TEST_F(LlvmLibcExp10fTest, SpecialNumbers) {
TEST_F(LlvmLibcExp10fTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp10f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp10f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp10f(float(FPBits(0x43000000U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp10f(FPBits(0x43000000U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp10f(float(FPBits(0x43000001U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp10f(FPBits(0x43000001U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}
TEST_F(LlvmLibcExp10fTest, Underflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
0.0f, LIBC_NAMESPACE::exp10f(float(FPBits(0xff7fffffU))), FE_UNDERFLOW);
0.0f, LIBC_NAMESPACE::exp10f(FPBits(0xff7fffffU).get_val()),
FE_UNDERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
float x = float(FPBits(0xc2cffff8U));
float x = FPBits(0xc2cffff8U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
LIBC_NAMESPACE::exp10f(x), 0.5);
EXPECT_MATH_ERRNO(ERANGE);
x = float(FPBits(0xc2d00008U));
x = FPBits(0xc2d00008U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
LIBC_NAMESPACE::exp10f(x), 0.5);
EXPECT_MATH_ERRNO(ERANGE);
@ -97,7 +98,7 @@ TEST_F(LlvmLibcExp10fTest, TrickyInputs) {
};
for (int i = 0; i < N; ++i) {
libc_errno = 0;
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
LIBC_NAMESPACE::exp10f(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, -x,
@ -109,7 +110,7 @@ TEST_F(LlvmLibcExp10fTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
libc_errno = 0;

View File

@ -54,7 +54,7 @@ TEST_F(LlvmLibcExp2Test, TrickyInputs) {
0xbc971547652b82fe, // x=-0x1.71547652b82fep-54
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
LIBC_NAMESPACE::exp2(x), 0.5);
}

View File

@ -43,15 +43,15 @@ TEST_F(LlvmLibcExp2fTest, SpecialNumbers) {
TEST_F(LlvmLibcExp2fTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp2f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp2f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp2f(float(FPBits(0x43000000U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp2f(FPBits(0x43000000U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp2f(float(FPBits(0x43000001U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp2f(FPBits(0x43000001U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}
@ -73,7 +73,7 @@ TEST_F(LlvmLibcExp2fTest, TrickyInputs) {
};
for (int i = 0; i < N; ++i) {
libc_errno = 0;
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
LIBC_NAMESPACE::exp2f(x), 0.5);
EXPECT_MATH_ERRNO(0);
@ -83,20 +83,20 @@ TEST_F(LlvmLibcExp2fTest, TrickyInputs) {
TEST_F(LlvmLibcExp2fTest, Underflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
0.0f, LIBC_NAMESPACE::exp2f(float(FPBits(0xff7fffffU))), FE_UNDERFLOW);
0.0f, LIBC_NAMESPACE::exp2f(FPBits(0xff7fffffU).get_val()), FE_UNDERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
float x = float(FPBits(0xc3158000U));
float x = FPBits(0xc3158000U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
LIBC_NAMESPACE::exp2f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xc3160000U));
x = FPBits(0xc3160000U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
LIBC_NAMESPACE::exp2f(x), 0.5);
EXPECT_MATH_ERRNO(ERANGE);
x = float(FPBits(0xc3165432U));
x = FPBits(0xc3165432U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
LIBC_NAMESPACE::exp2f(x), 0.5);
EXPECT_MATH_ERRNO(ERANGE);
@ -106,7 +106,7 @@ TEST_F(LlvmLibcExp2fTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
libc_errno = 0;

View File

@ -52,7 +52,7 @@ TEST_F(LlvmLibcExpTest, TrickyInputs) {
0xc0867a172ceb0990, // x=-0x1.67a172ceb099p+9
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::exp(x), 0.5);
}

View File

@ -42,30 +42,30 @@ TEST_F(LlvmLibcExpfTest, SpecialNumbers) {
TEST_F(LlvmLibcExpfTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expf(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expf(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}
TEST_F(LlvmLibcExpfTest, Underflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
0.0f, LIBC_NAMESPACE::expf(float(FPBits(0xff7fffffU))), FE_UNDERFLOW);
0.0f, LIBC_NAMESPACE::expf(FPBits(0xff7fffffU).get_val()), FE_UNDERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
float x = float(FPBits(0xc2cffff8U));
float x = FPBits(0xc2cffff8U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(ERANGE);
x = float(FPBits(0xc2d00008U));
x = FPBits(0xc2d00008U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(ERANGE);
@ -77,27 +77,27 @@ TEST_F(LlvmLibcExpfTest, Borderline) {
float x;
libc_errno = 0;
x = float(FPBits(0x42affff8U));
x = FPBits(0x42affff8U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0x42b00008U));
x = FPBits(0x42b00008U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xc2affff8U));
x = FPBits(0xc2affff8U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xc2b00008U));
x = FPBits(0xc2b00008U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xc236bd8cU));
x = FPBits(0xc236bd8cU).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
LIBC_NAMESPACE::expf(x), 0.5);
EXPECT_MATH_ERRNO(0);
@ -107,7 +107,7 @@ TEST_F(LlvmLibcExpfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
libc_errno = 0;

View File

@ -48,7 +48,7 @@ TEST_F(LlvmLibcExpm1Test, TrickyInputs) {
0xc042b708872320dd, // x=-0x1.2b708872320ddp+5
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1(x), 0.5);
}

View File

@ -42,26 +42,26 @@ TEST_F(LlvmLibcExpm1fTest, SpecialNumbers) {
TEST_F(LlvmLibcExpm1fTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expm1f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expm1f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expm1f(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expm1f(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expm1f(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expm1f(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}
TEST_F(LlvmLibcExpm1fTest, Underflow) {
libc_errno = 0;
EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::expm1f(float(FPBits(0xff7fffffU))));
EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::expm1f(FPBits(0xff7fffffU).get_val()));
float x = float(FPBits(0xc2cffff8U));
float x = FPBits(0xc2cffff8U).get_val();
EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::expm1f(x));
x = float(FPBits(0xc2d00008U));
x = FPBits(0xc2d00008U).get_val();
EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::expm1f(x));
}
@ -71,42 +71,42 @@ TEST_F(LlvmLibcExpm1fTest, Borderline) {
float x;
libc_errno = 0;
x = float(FPBits(0x42affff8U));
x = FPBits(0x42affff8U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0x42b00008U));
x = FPBits(0x42b00008U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xc2affff8U));
x = FPBits(0xc2affff8U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xc2b00008U));
x = FPBits(0xc2b00008U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0x3dc252ddU));
x = FPBits(0x3dc252ddU).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0x3e35bec5U));
x = FPBits(0x3e35bec5U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0x942ed494U));
x = FPBits(0x942ed494U).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
x = float(FPBits(0xbdc1c6cbU));
x = FPBits(0xbdc1c6cbU).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
LIBC_NAMESPACE::expm1f(x), 0.5);
EXPECT_MATH_ERRNO(0);
@ -116,7 +116,7 @@ TEST_F(LlvmLibcExpm1fTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
libc_errno = 0;

View File

@ -66,7 +66,7 @@ TEST_F(LlvmLibcLog10Test, TrickyInputs) {
0x30160580e7268a99, 0x5ca04103b7eaa345, 0x19ad77dc4a40093f,
0x0000449fb5c8a96e};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x,
LIBC_NAMESPACE::log10(x), 0.5);
}

View File

@ -59,7 +59,7 @@ TEST_F(LlvmLibcLog10fTest, TrickyInputs) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x,
LIBC_NAMESPACE::log10f(x), 0.5);
}
@ -69,7 +69,7 @@ TEST_F(LlvmLibcLog10fTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x,
LIBC_NAMESPACE::log10f(x), 0.5);
}

View File

@ -67,7 +67,7 @@ TEST_F(LlvmLibcLog1pTest, TrickyInputs) {
0x5671e2f1628093e4, 0x73dac56e2bf1a951, 0x8001bc6879ea14c5,
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x,
LIBC_NAMESPACE::log1p(x), 0.5);
}

View File

@ -63,7 +63,7 @@ TEST_F(LlvmLibcLog1pfTest, TrickyInputs) {
0xbf800000U, /*-1.0f*/
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x,
LIBC_NAMESPACE::log1pf(x), 0.5);
}
@ -73,7 +73,7 @@ TEST_F(LlvmLibcLog1pfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
libc_errno = 0;

View File

@ -64,7 +64,7 @@ TEST_F(LlvmLibcLog2Test, TrickyInputs) {
0x3fefbfdaa448ed98,
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,
LIBC_NAMESPACE::log2(x), 0.5);
}

View File

@ -39,7 +39,7 @@ TEST_F(LlvmLibcLog2fTest, TrickyInputs) {
0x3f80079bU, 0x3f81d0b5U, 0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,
LIBC_NAMESPACE::log2f(x), 0.5);
}
@ -49,7 +49,7 @@ TEST_F(LlvmLibcLog2fTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
libc_errno = 0;

View File

@ -63,7 +63,7 @@ TEST_F(LlvmLibcLogTest, TrickyInputs) {
0x3fefbfdaa448ed98,
};
for (int i = 0; i < N; ++i) {
double x = double(FPBits(INPUTS[i]));
double x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,
LIBC_NAMESPACE::log(x), 0.5);
}

View File

@ -71,7 +71,7 @@ TEST_F(LlvmLibcLogfTest, TrickyInputs) {
0x7a17f30aU, /*0x1.2fe614p+117f*/
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,
LIBC_NAMESPACE::logf(x), 0.5);
}
@ -81,7 +81,7 @@ TEST_F(LlvmLibcLogfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,

View File

@ -23,7 +23,7 @@ TEST_F(LlvmLibcSinTest, Range) {
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
double x = double(FPBits(v));
double x = FPBits(v).get_val();
// TODO: Expand the range of testing after range reduction is implemented.
if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
continue;

View File

@ -100,7 +100,7 @@ TEST_F(LlvmLibcSinCosfTest, InFloatRange) {
constexpr uint32_t COUNT = 1'001;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits((v)));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
@ -159,7 +159,7 @@ TEST_F(LlvmLibcSinCosfTest, SpecialValues) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_SINCOS_MATCH_ALL_ROUNDING(x);
EXPECT_SINCOS_MATCH_ALL_ROUNDING(-x);
}
@ -169,7 +169,7 @@ TEST_F(LlvmLibcSinCosfTest, SpecialValues) {
// returns values furthest beyond its nominal upper bound of pi/4.
TEST_F(LlvmLibcSinCosfTest, SDCOMP_26094) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits((v)));
float x = FPBits(v).get_val();
EXPECT_SINCOS_MATCH_ALL_ROUNDING(x);
EXPECT_SINCOS_MATCH_ALL_ROUNDING(-x);
}

View File

@ -47,7 +47,7 @@ TEST_F(LlvmLibcSinfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
@ -97,7 +97,7 @@ TEST_F(LlvmLibcSinfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
LIBC_NAMESPACE::sinf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, -x,
@ -107,11 +107,11 @@ TEST_F(LlvmLibcSinfTest, SpecificBitPatterns) {
// For small values, sin(x) is x.
TEST_F(LlvmLibcSinfTest, SmallValues) {
float x = float(FPBits(0x1780'0000U));
float x = FPBits(0x1780'0000U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
LIBC_NAMESPACE::sinf(x), 0.5);
x = float(FPBits(0x0040'0000U));
x = FPBits(0x0040'0000U).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
LIBC_NAMESPACE::sinf(x), 0.5);
}
@ -120,7 +120,7 @@ TEST_F(LlvmLibcSinfTest, SmallValues) {
// returns values furthest beyond its nominal upper bound of pi/4.
TEST_F(LlvmLibcSinfTest, SDCOMP_26094) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits((v)));
float x = FPBits((v)).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
LIBC_NAMESPACE::sinf(x), 0.5);
}

View File

@ -45,7 +45,7 @@ TEST_F(LlvmLibcSinhfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Sinh, x, LIBC_NAMESPACE::sinhf(x), 0.5);
@ -54,12 +54,12 @@ TEST_F(LlvmLibcSinhfTest, InFloatRange) {
// For small values, sinh(x) is x.
TEST_F(LlvmLibcSinhfTest, SmallValues) {
float x = float(FPBits(uint32_t(0x17800000)));
float x = FPBits(uint32_t(0x17800000)).get_val();
float result = LIBC_NAMESPACE::sinhf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Sinh, x, result, 0.5);
EXPECT_FP_EQ(x, result);
x = float(FPBits(uint32_t(0x00400000)));
x = FPBits(uint32_t(0x00400000)).get_val();
result = LIBC_NAMESPACE::sinhf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Sinh, x, result, 0.5);
EXPECT_FP_EQ(x, result);
@ -68,24 +68,24 @@ TEST_F(LlvmLibcSinhfTest, SmallValues) {
TEST_F(LlvmLibcSinhfTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::sinhf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::sinhf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::sinhf(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::sinhf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::sinhf(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::sinhf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}
TEST_F(LlvmLibcSinhfTest, ExceptionalValues) {
float x = float(FPBits(uint32_t(0x3a12'85ffU)));
float x = FPBits(uint32_t(0x3a12'85ffU)).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x,
LIBC_NAMESPACE::sinhf(x), 0.5);
x = -float(FPBits(uint32_t(0x3a12'85ffU)));
x = -FPBits(uint32_t(0x3a12'85ffU)).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x,
LIBC_NAMESPACE::sinhf(x), 0.5);
}

View File

@ -20,11 +20,11 @@ public:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
void test_na_n_arg(FuncPtr func) {
EXPECT_FP_EQ(nan, func(nan, inf));
@ -66,7 +66,7 @@ public:
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))

View File

@ -56,7 +56,7 @@ public:
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))

View File

@ -56,7 +56,7 @@ public:
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))

View File

@ -21,11 +21,11 @@ private:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
public:
void test_special_numbers(Func func) {
@ -39,16 +39,16 @@ public:
EXPECT_FP_EQ(func(inf, neg_inf, nan), nan);
// Test underflow rounding up.
EXPECT_FP_EQ(
func(T(0.5), T(FPBits::min_subnormal()), T(FPBits::min_subnormal())),
T(FPBits(StorageType(2))));
EXPECT_FP_EQ(func(T(0.5), FPBits::min_subnormal().get_val(),
FPBits::min_subnormal().get_val()),
FPBits(StorageType(2)).get_val());
// Test underflow rounding down.
StorageType MIN_NORMAL = FPBits::min_normal().uintval();
T v = T(FPBits(MIN_NORMAL + StorageType(1)));
EXPECT_FP_EQ(func(T(1) / T(MIN_NORMAL << 1), v, T(FPBits::min_normal())),
v);
T v = FPBits(MIN_NORMAL + StorageType(1)).get_val();
EXPECT_FP_EQ(
func(T(1) / T(MIN_NORMAL << 1), v, FPBits::min_normal().get_val()), v);
// Test overflow.
T z = T(FPBits::max_normal());
T z = FPBits::max_normal().get_val();
EXPECT_FP_EQ(func(T(1.75), z, -z), T(0.75) * z);
// Exact cancellation.
EXPECT_FP_EQ(func(T(3.0), T(5.0), -T(15.0)), T(0.0));

View File

@ -22,16 +22,16 @@ private:
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T nan = T(FPBits::build_quiet_nan());
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = FPBits::build_quiet_nan().get_val();
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T max_normal = T(FPBits::max_normal());
const T min_normal = T(FPBits::min_normal());
const T max_subnormal = T(FPBits::max_subnormal());
const T min_subnormal = T(FPBits::min_subnormal());
const T max_normal = FPBits::max_normal().get_val();
const T min_normal = FPBits::min_normal().get_val();
const T max_subnormal = FPBits::max_subnormal().get_val();
const T min_subnormal = FPBits::min_subnormal().get_val();
public:
void test_special_numbers(Func func) {

View File

@ -26,11 +26,11 @@ public:
void test_special_numbers(typename ILogbFunc<T>::Func func) {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
using Sign = LIBC_NAMESPACE::fputil::Sign;
EXPECT_EQ(FP_ILOGB0, func(T(FPBits::zero(Sign::POS))));
EXPECT_EQ(FP_ILOGB0, func(T(FPBits::zero(Sign::NEG))));
EXPECT_EQ(FP_ILOGBNAN, func(T(FPBits::build_quiet_nan())));
EXPECT_EQ(INT_MAX, func(T(FPBits::inf(Sign::POS))));
EXPECT_EQ(INT_MAX, func(T(FPBits::inf(Sign::NEG))));
EXPECT_EQ(FP_ILOGB0, func(FPBits::zero(Sign::POS).get_val()));
EXPECT_EQ(FP_ILOGB0, func(FPBits::zero(Sign::NEG).get_val()));
EXPECT_EQ(FP_ILOGBNAN, func(FPBits::build_quiet_nan().get_val()));
EXPECT_EQ(INT_MAX, func(FPBits::inf(Sign::POS).get_val()));
EXPECT_EQ(INT_MAX, func(FPBits::inf(Sign::NEG).get_val()));
}
template <typename T>
@ -81,7 +81,7 @@ public:
constexpr StorageType COUNT = 10'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType v = MIN_SUBNORMAL; v <= MAX_SUBNORMAL; v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0)
continue;
@ -100,7 +100,7 @@ public:
constexpr StorageType COUNT = 10'001;
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
for (StorageType v = MIN_NORMAL; v <= MAX_NORMAL; v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0)
continue;

View File

@ -25,11 +25,11 @@ class LdExpTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
// A normalized mantissa to be used with tests.
static constexpr StorageType MANTISSA = NormalFloat::ONE + 0x1234;

View File

@ -72,7 +72,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = static_cast<T>(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == 0.0l)
continue;

View File

@ -84,7 +84,7 @@ public:
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
T x = FPBits(v).get_val();
if (isnan(x) || isinf(x) || x == T(0.0))
continue;

View File

@ -34,11 +34,11 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
static constexpr StorageType min_subnormal =
FPBits::min_subnormal().uintval();

View File

@ -36,11 +36,11 @@ class NextTowardTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
const long double to_zero = ToFPBits::zero().get_val();
const long double to_neg_zero = ToFPBits::zero(Sign::NEG).get_val();

View File

@ -31,11 +31,11 @@ private:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
public:
void testSpecialNumbers(RIntFunc func) {

View File

@ -21,11 +21,11 @@ class RemQuoTestTemplate : public LIBC_NAMESPACE::testing::Test {
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const T inf = T(FPBits::inf(Sign::POS));
const T neg_inf = T(FPBits::inf(Sign::NEG));
const T zero = T(FPBits::zero(Sign::POS));
const T neg_zero = T(FPBits::zero(Sign::NEG));
const T nan = T(FPBits::build_quiet_nan());
const T inf = FPBits::inf(Sign::POS).get_val();
const T neg_inf = FPBits::inf(Sign::NEG).get_val();
const T zero = FPBits::zero(Sign::POS).get_val();
const T neg_zero = FPBits::zero(Sign::NEG).get_val();
const T nan = FPBits::build_quiet_nan().get_val();
public:
typedef T (*RemQuoFunc)(T, T, int *);

View File

@ -30,11 +30,11 @@ private:
using StorageType = typename FPBits::StorageType;
using Sign = LIBC_NAMESPACE::fputil::Sign;
const F zero = F(FPBits::zero(Sign::POS));
const F neg_zero = F(FPBits::zero(Sign::NEG));
const F inf = F(FPBits::inf(Sign::POS));
const F neg_inf = F(FPBits::inf(Sign::NEG));
const F nan = F(FPBits::build_quiet_nan());
const F zero = FPBits::zero(Sign::POS).get_val();
const F neg_zero = FPBits::zero(Sign::NEG).get_val();
const F inf = FPBits::inf(Sign::POS).get_val();
const F neg_inf = FPBits::inf(Sign::NEG).get_val();
const F nan = FPBits::build_quiet_nan().get_val();
static constexpr StorageType MAX_SUBNORMAL =
FPBits::max_subnormal().uintval();
@ -119,7 +119,7 @@ public:
constexpr StorageType COUNT = 1'000'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = F(FPBits(i));
F x = FPBits(i).get_val();
if (x == F(0.0))
continue;
// All subnormal numbers should round to zero.

View File

@ -41,14 +41,14 @@ TEST_F(LlvmLibcCoshfTest, SpecialNumbers) {
TEST_F(LlvmLibcCoshfTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::coshf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::coshf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::coshf(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::coshf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::coshf(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::coshf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}

View File

@ -43,14 +43,14 @@ TEST_F(LlvmLibcExp10fTest, SpecialNumbers) {
TEST_F(LlvmLibcExp10fTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp10f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp10f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp10f(float(FPBits(0x43000000U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp10f(FPBits(0x43000000U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp10f(float(FPBits(0x43000001U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp10f(FPBits(0x43000001U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}

View File

@ -45,14 +45,14 @@ TEST_F(LlvmLibcExp2fTest, SpecialNumbers) {
TEST_F(LlvmLibcExp2fTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp2f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp2f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp2f(float(FPBits(0x43000000U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp2f(FPBits(0x43000000U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::exp2f(float(FPBits(0x43000001U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::exp2f(FPBits(0x43000001U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}

View File

@ -39,14 +39,14 @@ TEST_F(LlvmLibcExpfTest, SpecialNumbers) {
TEST_F(LlvmLibcExpfTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expf(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expf(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}

View File

@ -39,14 +39,14 @@ TEST_F(LlvmLibcExpm1fTest, SpecialNumbers) {
TEST_F(LlvmLibcExpm1fTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expm1f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expm1f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expm1f(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expm1f(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::expm1f(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::expm1f(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}

View File

@ -40,11 +40,11 @@ TEST_F(LlvmLibcSinhfTest, SpecialNumbers) {
// For small values, sinh(x) is x.
TEST_F(LlvmLibcSinhfTest, SmallValues) {
float x = float(FPBits(uint32_t(0x17800000)));
float x = FPBits(uint32_t(0x17800000)).get_val();
float result = LIBC_NAMESPACE::sinhf(x);
EXPECT_FP_EQ(x, result);
x = float(FPBits(uint32_t(0x00400000)));
x = FPBits(uint32_t(0x00400000)).get_val();
result = LIBC_NAMESPACE::sinhf(x);
EXPECT_FP_EQ(x, result);
}
@ -52,14 +52,14 @@ TEST_F(LlvmLibcSinhfTest, SmallValues) {
TEST_F(LlvmLibcSinhfTest, Overflow) {
libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::sinhf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::sinhf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::sinhf(float(FPBits(0x42cffff8U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::sinhf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
EXPECT_FP_EQ_WITH_EXCEPTION(
inf, LIBC_NAMESPACE::sinhf(float(FPBits(0x42d00008U))), FE_OVERFLOW);
inf, LIBC_NAMESPACE::sinhf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
EXPECT_MATH_ERRNO(ERANGE);
}

View File

@ -22,7 +22,7 @@ TEST_F(LlvmLibcTanTest, Range) {
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
double x = double(FPBits(v));
double x = FPBits(v).get_val();
// TODO: Expand the range of testing after range reduction is implemented.
if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
continue;

View File

@ -47,7 +47,7 @@ TEST_F(LlvmLibcTanfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, x,
@ -115,7 +115,7 @@ TEST_F(LlvmLibcTanfTest, SpecificBitPatterns) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, x,
LIBC_NAMESPACE::tanf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, -x,
@ -127,7 +127,7 @@ TEST_F(LlvmLibcTanfTest, SpecificBitPatterns) {
// returns values furthest beyond its nominal upper bound of pi/4.
TEST_F(LlvmLibcTanfTest, SDCOMP_26094) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
ASSERT_MPFR_MATCH(mpfr::Operation::Tan, x, LIBC_NAMESPACE::tanf(x), 0.5);
}
}

View File

@ -44,7 +44,7 @@ TEST_F(LlvmLibcTanhfTest, InFloatRange) {
constexpr uint32_t COUNT = 100'001;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
float x = FPBits(v).get_val();
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanh, x,
@ -62,7 +62,7 @@ TEST_F(LlvmLibcTanhfTest, ExceptionalValues) {
};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanh, x,
LIBC_NAMESPACE::tanhf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanh, -x,

View File

@ -26,7 +26,7 @@ TEST(LlvmLibcAToFTest, SimpleTest) {
libc_errno = 0;
EXPECT_THAT(LIBC_NAMESPACE::atof("123"),
Succeeds<double>(static_cast<double>(expected_fp)));
Succeeds<double>(expected_fp.get_val()));
}
TEST(LlvmLibcAToFTest, FailedParsingTest) {

View File

@ -50,10 +50,9 @@ public:
libc_errno = 0;
double result = LIBC_NAMESPACE::strtod(inputString, &str_end);
if (expectedErrno == 0)
EXPECT_THAT(result, Succeeds<double>(static_cast<double>(expected_fp)));
EXPECT_THAT(result, Succeeds<double>(expected_fp.get_val()));
else
EXPECT_THAT(result, Fails<double>(expectedErrno,
static_cast<double>(expected_fp)));
EXPECT_THAT(result, Fails<double>(expectedErrno, expected_fp.get_val()));
EXPECT_EQ(str_end - inputString, expectedStrLen);
}
};

Some files were not shown because too many files have changed in this diff Show More