constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count;
++i, v += step, w -= step) {
- T x = FPBits(v), y = FPBits(w);
+ T x = T(FPBits(v)), y = T(FPBits(w));
if (isnan(x) || isinf(x))
continue;
if (isnan(y) || isinf(y))
private:
// constexpr does not work on FPBits yet, so we cannot have these constants as
// static.
- const T nan = __llvm_libc::fputil::FPBits<T>::buildNaN(1);
- const T inf = __llvm_libc::fputil::FPBits<T>::inf();
- const T negInf = __llvm_libc::fputil::FPBits<T>::negInf();
- const T zero = __llvm_libc::fputil::FPBits<T>::zero();
- const T negZero = __llvm_libc::fputil::FPBits<T>::negZero();
-};
\ No newline at end of file
+ const T nan = T(__llvm_libc::fputil::FPBits<T>::buildNaN(1));
+ const T inf = T(__llvm_libc::fputil::FPBits<T>::inf());
+ const T negInf = T(__llvm_libc::fputil::FPBits<T>::negInf());
+ const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
+ const T negZero = T(__llvm_libc::fputil::FPBits<T>::negZero());
+};
using Func = T (*)(T, T, T);
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
- const T nan = __llvm_libc::fputil::FPBits<T>::buildNaN(1);
- const T inf = __llvm_libc::fputil::FPBits<T>::inf();
- const T negInf = __llvm_libc::fputil::FPBits<T>::negInf();
- const T zero = __llvm_libc::fputil::FPBits<T>::zero();
- const T negZero = __llvm_libc::fputil::FPBits<T>::negZero();
+ const T nan = T(__llvm_libc::fputil::FPBits<T>::buildNaN(1));
+ const T inf = T(__llvm_libc::fputil::FPBits<T>::inf());
+ const T negInf = T(__llvm_libc::fputil::FPBits<T>::negInf());
+ const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
+ const T negZero = T(__llvm_libc::fputil::FPBits<T>::negZero());
UIntType getRandomBitPattern() {
UIntType bits{0};
EXPECT_FP_EQ(func(inf, negInf, nan), nan);
// Test underflow rounding up.
- EXPECT_FP_EQ(func(T(0.5), FPBits(FPBits::minSubnormal),
- FPBits(FPBits::minSubnormal)),
- FPBits(UIntType(2)));
+ EXPECT_FP_EQ(func(T(0.5), T(FPBits(FPBits::minSubnormal)),
+ T(FPBits(FPBits::minSubnormal))),
+ T(FPBits(UIntType(2))));
// Test underflow rounding down.
- FPBits v(FPBits::minNormal + UIntType(1));
+ T v = T(FPBits(FPBits::minNormal + UIntType(1)));
EXPECT_FP_EQ(
- func(T(1) / T(FPBits::minNormal << 1), v, FPBits(FPBits::minNormal)),
+ func(T(1) / T(FPBits::minNormal << 1), v, T(FPBits(FPBits::minNormal))),
v);
// Test overflow.
- FPBits z(FPBits::maxNormal);
+ T z = T(FPBits(FPBits::maxNormal));
EXPECT_FP_EQ(func(T(1.75), z, -z), T(0.75) * z);
}
for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal;
v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal;
v += step, w -= step) {
- T x = FPBits(getRandomBitPattern()), y = FPBits(v), z = FPBits(w);
+ T x = T(FPBits(getRandomBitPattern())), y = T(FPBits(v)),
+ z = T(FPBits(w));
T result = func(x, y, z);
mpfr::TernaryInput<T> input{x, y, z};
ASSERT_MPFR_MATCH(mpfr::Operation::Fma, input, result, 0.5);
for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal;
v <= FPBits::maxNormal && w >= FPBits::minNormal;
v += step, w -= step) {
- T x = FPBits(v), y = FPBits(w), z = FPBits(getRandomBitPattern());
+ T x = T(FPBits(v)), y = T(FPBits(w)),
+ z = T(FPBits(getRandomBitPattern()));
T result = func(x, y, z);
mpfr::TernaryInput<T> input{x, y, z};
ASSERT_MPFR_MATCH(mpfr::Operation::Fma, input, result, 0.5);
using Func = T (*)(T, T);
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
- const T nan = __llvm_libc::fputil::FPBits<T>::buildNaN(1);
- const T inf = __llvm_libc::fputil::FPBits<T>::inf();
- const T negInf = __llvm_libc::fputil::FPBits<T>::negInf();
- const T zero = __llvm_libc::fputil::FPBits<T>::zero();
- const T negZero = __llvm_libc::fputil::FPBits<T>::negZero();
+ const T nan = T(__llvm_libc::fputil::FPBits<T>::buildNaN(1));
+ const T inf = T(__llvm_libc::fputil::FPBits<T>::inf());
+ const T negInf = T(__llvm_libc::fputil::FPBits<T>::negInf());
+ const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
+ const T negZero = T(__llvm_libc::fputil::FPBits<T>::negZero());
public:
void testSpecialNumbers(Func func) {
for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal;
v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal;
v += step, w -= step) {
- T x = FPBits(v), y = FPBits(w);
+ T x = T(FPBits(v)), y = T(FPBits(w));
T result = func(x, y);
mpfr::BinaryInput<T> input{x, y};
ASSERT_MPFR_MATCH(mpfr::Operation::Hypot, input, result, 0.5);
for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal;
v <= FPBits::maxNormal && w >= FPBits::minNormal;
v += step, w -= step) {
- T x = FPBits(v), y = FPBits(w);
+ T x = T(FPBits(v)), y = T(FPBits(w));
T result = func(x, y);
mpfr::BinaryInput<T> input{x, y};
ASSERT_MPFR_MATCH(mpfr::Operation::Hypot, input, result, 0.5);
template <typename T>
void testSpecialNumbers(typename ILogbFunc<T>::Func func) {
- EXPECT_EQ(FP_ILOGB0, func(__llvm_libc::fputil::FPBits<T>::zero()));
- EXPECT_EQ(FP_ILOGB0, func(__llvm_libc::fputil::FPBits<T>::negZero()));
+ EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits<T>::zero())));
+ EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits<T>::negZero())));
- EXPECT_EQ(FP_ILOGBNAN, func(__llvm_libc::fputil::FPBits<T>::buildNaN(1)));
+ EXPECT_EQ(FP_ILOGBNAN,
+ func(T(__llvm_libc::fputil::FPBits<T>::buildNaN(1))));
- EXPECT_EQ(INT_MAX, func(__llvm_libc::fputil::FPBits<T>::inf()));
- EXPECT_EQ(INT_MAX, func(__llvm_libc::fputil::FPBits<T>::negInf()));
+ EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits<T>::inf())));
+ EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits<T>::negInf())));
}
template <typename T> void testPowersOfTwo(typename ILogbFunc<T>::Func func) {
(FPBits::maxSubnormal - FPBits::minSubnormal) / count;
for (UIntType v = FPBits::minSubnormal; v <= FPBits::maxSubnormal;
v += step) {
- T x = FPBits(v);
+ T x = T(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0)
continue;
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count;
for (UIntType v = FPBits::minNormal; v <= FPBits::maxNormal; v += step) {
- T x = FPBits(v);
+ T x = T(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0)
continue;
// A normalized mantissa to be used with tests.
static constexpr UIntType mantissa = NormalFloat::one + 0x1234;
- const T zero = __llvm_libc::fputil::FPBits<T>::zero();
- const T negZero = __llvm_libc::fputil::FPBits<T>::negZero();
- const T inf = __llvm_libc::fputil::FPBits<T>::inf();
- const T negInf = __llvm_libc::fputil::FPBits<T>::negInf();
- const T nan = __llvm_libc::fputil::FPBits<T>::buildNaN(1);
+ const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
+ const T negZero = T(__llvm_libc::fputil::FPBits<T>::negZero());
+ const T inf = T(__llvm_libc::fputil::FPBits<T>::inf());
+ const T negInf = T(__llvm_libc::fputil::FPBits<T>::negInf());
+ const T nan = T(__llvm_libc::fputil::FPBits<T>::buildNaN(1));
public:
typedef T (*LdExpFunc)(T, int);
static constexpr int bitWidthOfType = sizeof(T) * 8;
#endif
- const T zero = FPBits::zero();
- const T negZero = FPBits::negZero();
- const T inf = FPBits::inf();
- const T negInf = FPBits::negInf();
- const T nan = FPBits::buildNaN(1);
+ const T zero = T(FPBits::zero());
+ const T negZero = T(FPBits::negZero());
+ const T inf = T(FPBits::inf());
+ const T negInf = T(FPBits::negInf());
+ const T nan = T(FPBits::buildNaN(1));
const UIntType minSubnormal = FPBits::minSubnormal;
const UIntType maxSubnormal = FPBits::maxSubnormal;
const UIntType minNormal = FPBits::minNormal;
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
- const T zero = FPBits::zero();
- const T negZero = FPBits::negZero();
- const T inf = FPBits::inf();
- const T negInf = FPBits::negInf();
- const T nan = FPBits::buildNaN(1);
+ const T zero = T(FPBits::zero());
+ const T negZero = T(FPBits::negZero());
+ const T inf = T(FPBits::inf());
+ const T negInf = T(FPBits::negInf());
+ const T nan = T(FPBits::buildNaN(1));
static inline mpfr::RoundingMode toMPFRRoundingMode(int mode) {
switch (mode) {
(FPBits::maxSubnormal - FPBits::minSubnormal) / count;
for (UIntType i = FPBits::minSubnormal; i <= FPBits::maxSubnormal;
i += step) {
- T x = FPBits(i);
+ T x = T(FPBits(i));
for (int mode : roundingModes) {
__llvm_libc::fputil::setRound(mode);
mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode);
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count;
for (UIntType i = FPBits::minNormal; i <= FPBits::maxNormal; i += step) {
- T x = FPBits(i);
+ T x = T(FPBits(i));
// 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)) {
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
- const T zero = __llvm_libc::fputil::FPBits<T>::zero();
- const T negZero = __llvm_libc::fputil::FPBits<T>::negZero();
- const T inf = __llvm_libc::fputil::FPBits<T>::inf();
- const T negInf = __llvm_libc::fputil::FPBits<T>::negInf();
- const T nan = __llvm_libc::fputil::FPBits<T>::buildNaN(1);
+ const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
+ const T negZero = T(__llvm_libc::fputil::FPBits<T>::negZero());
+ const T inf = T(__llvm_libc::fputil::FPBits<T>::inf());
+ const T negInf = T(__llvm_libc::fputil::FPBits<T>::negInf());
+ const T nan = T(__llvm_libc::fputil::FPBits<T>::buildNaN(1));
public:
typedef T (*RemQuoFunc)(T, T, int *);
for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal;
v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal;
v += step, w -= step) {
- T x = FPBits(v), y = FPBits(w);
+ T x = T(FPBits(v)), y = T(FPBits(w));
mpfr::BinaryOutput<T> result;
mpfr::BinaryInput<T> input{x, y};
result.f = func(x, y, &result.i);
for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal;
v <= FPBits::maxNormal && w >= FPBits::minNormal;
v += step, w -= step) {
- T x = FPBits(v), y = FPBits(w);
+ T x = T(FPBits(v)), y = T(FPBits(w));
mpfr::BinaryOutput<T> result;
mpfr::BinaryInput<T> input{x, y};
result.f = func(x, y, &result.i);
using FPBits = __llvm_libc::fputil::FPBits<F>;
using UIntType = typename FPBits::UIntType;
- const F zero = __llvm_libc::fputil::FPBits<F>::zero();
- const F negZero = __llvm_libc::fputil::FPBits<F>::negZero();
- const F inf = __llvm_libc::fputil::FPBits<F>::inf();
- const F negInf = __llvm_libc::fputil::FPBits<F>::negInf();
- const F nan = __llvm_libc::fputil::FPBits<F>::buildNaN(1);
+ const F zero = F(__llvm_libc::fputil::FPBits<F>::zero());
+ const F negZero = F(__llvm_libc::fputil::FPBits<F>::negZero());
+ const F inf = F(__llvm_libc::fputil::FPBits<F>::inf());
+ const F negInf = F(__llvm_libc::fputil::FPBits<F>::negInf());
+ const F nan = F(__llvm_libc::fputil::FPBits<F>::buildNaN(1));
static constexpr I IntegerMin = I(1) << (sizeof(I) * 8 - 1);
static constexpr I IntegerMax = -(IntegerMin + 1);
bits.encoding.sign = 1;
bits.encoding.mantissa = 0;
- F x = bits;
+ F x = F(bits);
long mpfrResult;
bool erangeflag = mpfr::RoundToLong(x, mpfrResult);
ASSERT_FALSE(erangeflag);
bits.encoding.mantissa =
UIntType(0x1) << (__llvm_libc::fputil::MantissaWidth<F>::value - 1);
- F x = bits;
+ F x = F(bits);
if (TestModes) {
for (int m : roundingModes) {
__llvm_libc::fputil::setRound(m);
(FPBits::maxSubnormal - FPBits::minSubnormal) / count;
for (UIntType i = FPBits::minSubnormal; i <= FPBits::maxSubnormal;
i += step) {
- F x = FPBits(i);
+ F x = F(FPBits(i));
if (x == F(0.0))
continue;
// All subnormal numbers should round to zero.
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count;
for (UIntType i = FPBits::minNormal; i <= FPBits::maxNormal; i += step) {
- F x = FPBits(i);
+ F x = F(FPBits(i));
// 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)) {
FPBits denormal(T(0.0));
denormal.encoding.mantissa = mant;
- ASSERT_MPFR_MATCH(mpfr::Operation::Sqrt, T(denormal),
- func(denormal), T(0.5));
+ ASSERT_MPFR_MATCH(mpfr::Operation::Sqrt, T(denormal), func(T(denormal)),
+ T(0.5));
}
constexpr UIntType count = 1'000'001;
constexpr UIntType count = 1000001;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- double x = FPBits(v);
+ double x = double(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0)
continue;
constexpr UIntType count = 1000001;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- float x = FPBits(v);
+ float x = float(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0)
continue;
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- long double x = FPBits(v);
+ long double x = static_cast<long double>(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0l)
continue;
FPBits() : integer(0) {}
- operator T() { return val; }
+ explicit operator T() { return val; }
UIntType uintval() const { return integer; }
static T buildNaN(UIntType v) {
FPBits<T> bits = inf();
bits.encoding.mantissa = v;
- return bits;
+ return T(bits);
}
};
FPBits_t x_bits(x), y_bits(y);
if (x_bits.isInf() || y_bits.isInf()) {
- return FPBits_t::inf();
+ return T(FPBits_t::inf());
}
if (x_bits.isNaN()) {
return x;
sum >>= 2;
++out_exp;
if (out_exp >= FPBits_t::maxExponent) {
- return FPBits_t::inf();
+ return T(FPBits_t::inf());
}
} else {
// For denormal result, we simply move the leading bit of the result to
Y -= one >> 1;
++out_exp;
if (out_exp >= FPBits_t::maxExponent) {
- return FPBits_t::inf();
+ return T(FPBits_t::inf());
}
}
return x;
} else if (bits.isInf()) {
iptr = x;
- return bits.encoding.sign ? FPBits<T>::negZero() : FPBits<T>::zero();
+ return bits.encoding.sign ? T(FPBits<T>::negZero()) : T(FPBits<T>::zero());
} else {
iptr = trunc(x);
if (x == iptr) {
// If x is already an integer value, then return zero with the right
// sign.
- return bits.encoding.sign ? FPBits<T>::negZero() : FPBits<T>::zero();
+ return bits.encoding.sign ? T(FPBits<T>::negZero())
+ : T(FPBits<T>::zero());
} else {
return x - iptr;
}
static inline T copysign(T x, T y) {
FPBits<T> xbits(x);
xbits.encoding.sign = FPBits<T>(y).encoding.sign;
- return xbits;
+ return T(xbits);
}
template <typename T,
if (bits.isZero()) {
// TODO(Floating point exception): Raise div-by-zero exception.
// TODO(errno): POSIX requires setting errno to ERANGE.
- return FPBits<T>::negInf();
+ return T(FPBits<T>::negInf());
} else if (bits.isNaN()) {
return x;
} else if (bits.isInf()) {
// Return positive infinity.
- return FPBits<T>::inf();
+ return T(FPBits<T>::inf());
}
NormalFloat<T> normal(bits);
// calculating the limit.
int expLimit = FPBits<T>::maxExponent + MantissaWidth<T>::value + 1;
if (exp > expLimit)
- return bits.encoding.sign ? FPBits<T>::negInf() : FPBits<T>::inf();
+ return bits.encoding.sign ? T(FPBits<T>::negInf()) : T(FPBits<T>::inf());
// Similarly on the negative side we return zero early if |exp| is too small.
if (exp < -expLimit)
- return bits.encoding.sign ? FPBits<T>::negZero() : FPBits<T>::zero();
+ return bits.encoding.sign ? T(FPBits<T>::negZero()) : T(FPBits<T>::zero());
// For all other values, NormalFloat to T conversion handles it the right way.
NormalFloat<T> normal(bits);
int trimSize = MantissaWidth<T>::value - exponent;
bits.encoding.mantissa = (bits.encoding.mantissa >> trimSize) << trimSize;
- return bits;
+ return T(bits);
}
template <typename T,
// Max exponent is of the form 0xFF...E. That is why -2 and not -1.
constexpr int maxExponentValue = (1 << ExponentWidth<T>::value) - 2;
if (biasedExponent > maxExponentValue) {
- return sign ? FPBits<T>::negInf() : FPBits<T>::inf();
+ return sign ? T(FPBits<T>::negInf()) : T(FPBits<T>::inf());
}
FPBits<T> result(T(0.0));
// the overflow into the exponent.
if (newMantissa == one)
result.encoding.exponent = 1;
- return result;
+ return T(result);
} else {
- return result;
+ return T(result);
}
}
result.encoding.exponent = exponent + FPBits<T>::exponentBias;
result.encoding.mantissa = mantissa;
- return result;
+ return T(result);
}
private:
} else {
result.encoding.implicitBit = 0;
}
- return result;
+ return static_cast<long double>(result);
} else {
- return result;
+ return static_cast<long double>(result);
}
}
result.encoding.exponent = biasedExponent;
result.encoding.mantissa = mantissa;
result.encoding.implicitBit = 1;
- return result;
+ return static_cast<long double>(result);
}
#endif
#define DECLARE_SPECIAL_CONSTANTS(T) \
using FPBits = __llvm_libc::fputil::FPBits<T>; \
using UIntType = typename FPBits::UIntType; \
- const T zero = FPBits::zero(); \
- const T negZero = FPBits::negZero(); \
- const T aNaN = FPBits::buildNaN(1); \
- const T inf = FPBits::inf(); \
- const T negInf = FPBits::negInf();
+ const T zero = T(FPBits::zero()); \
+ const T negZero = T(FPBits::negZero()); \
+ const T aNaN = T(FPBits::buildNaN(1)); \
+ const T inf = T(FPBits::inf()); \
+ const T negInf = T(FPBits::negInf());
#define EXPECT_FP_EQ(expected, actual) \
EXPECT_THAT( \