[libc][NFC] Make conversion from FPBits to the float point type explicit.
This will help us catch errors like the ones fixed by the commit
31ed45d9cfd5da2bf4f1d7ddba54122df6fc91fa
GitOrigin-RevId: fb706e086c70de9dd24852f1ef1d0f411bd501a1
diff --git a/test/src/math/FDimTest.h b/test/src/math/FDimTest.h
index d632b23..1a53440 100644
--- a/test/src/math/FDimTest.h
+++ b/test/src/math/FDimTest.h
@@ -57,7 +57,7 @@
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))
@@ -74,9 +74,9 @@
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());
+};
diff --git a/test/src/math/FmaTest.h b/test/src/math/FmaTest.h
index 9f90c86..eb31bf8 100644
--- a/test/src/math/FmaTest.h
+++ b/test/src/math/FmaTest.h
@@ -23,11 +23,11 @@
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};
@@ -50,16 +50,16 @@
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);
}
@@ -70,7 +70,8 @@
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);
@@ -83,7 +84,8 @@
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);
diff --git a/test/src/math/HypotTest.h b/test/src/math/HypotTest.h
index 34b1ff6..697d604 100644
--- a/test/src/math/HypotTest.h
+++ b/test/src/math/HypotTest.h
@@ -25,11 +25,11 @@
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) {
@@ -52,7 +52,7 @@
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);
@@ -65,7 +65,7 @@
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);
diff --git a/test/src/math/ILogbTest.h b/test/src/math/ILogbTest.h
index 724cc95..bf79960 100644
--- a/test/src/math/ILogbTest.h
+++ b/test/src/math/ILogbTest.h
@@ -22,13 +22,14 @@
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) {
@@ -78,7 +79,7 @@
(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;
@@ -94,7 +95,7 @@
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;
diff --git a/test/src/math/LdExpTest.h b/test/src/math/LdExpTest.h
index a2c1b54..046ec04 100644
--- a/test/src/math/LdExpTest.h
+++ b/test/src/math/LdExpTest.h
@@ -28,11 +28,11 @@
// 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);
diff --git a/test/src/math/NextAfterTest.h b/test/src/math/NextAfterTest.h
index 8ba3f30..9c53ab7 100644
--- a/test/src/math/NextAfterTest.h
+++ b/test/src/math/NextAfterTest.h
@@ -29,11 +29,11 @@
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;
diff --git a/test/src/math/RIntTest.h b/test/src/math/RIntTest.h
index 18331ec..edcc279 100644
--- a/test/src/math/RIntTest.h
+++ b/test/src/math/RIntTest.h
@@ -33,11 +33,11 @@
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) {
@@ -98,7 +98,7 @@
(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);
@@ -111,7 +111,7 @@
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)) {
diff --git a/test/src/math/RemQuoTest.h b/test/src/math/RemQuoTest.h
index f643079..7b442ff 100644
--- a/test/src/math/RemQuoTest.h
+++ b/test/src/math/RemQuoTest.h
@@ -23,11 +23,11 @@
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 *);
@@ -101,7 +101,7 @@
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);
@@ -115,7 +115,7 @@
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);
diff --git a/test/src/math/RoundToIntegerTest.h b/test/src/math/RoundToIntegerTest.h
index 0b83b9a..c3d0351 100644
--- a/test/src/math/RoundToIntegerTest.h
+++ b/test/src/math/RoundToIntegerTest.h
@@ -35,11 +35,11 @@
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);
@@ -139,7 +139,7 @@
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);
@@ -204,7 +204,7 @@
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);
@@ -228,7 +228,7 @@
(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.
@@ -270,7 +270,7 @@
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)) {
diff --git a/test/src/math/SqrtTest.h b/test/src/math/SqrtTest.h
index 56916a5..56a16bb 100644
--- a/test/src/math/SqrtTest.h
+++ b/test/src/math/SqrtTest.h
@@ -41,8 +41,8 @@
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;
diff --git a/test/src/math/frexp_test.cpp b/test/src/math/frexp_test.cpp
index d9fcae4..2d8ae1c 100644
--- a/test/src/math/frexp_test.cpp
+++ b/test/src/math/frexp_test.cpp
@@ -136,7 +136,7 @@
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;
diff --git a/test/src/math/frexpf_test.cpp b/test/src/math/frexpf_test.cpp
index 8d2fe30..a3a3da4 100644
--- a/test/src/math/frexpf_test.cpp
+++ b/test/src/math/frexpf_test.cpp
@@ -143,7 +143,7 @@
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;
diff --git a/test/src/math/frexpl_test.cpp b/test/src/math/frexpl_test.cpp
index ee18961..6036178 100644
--- a/test/src/math/frexpl_test.cpp
+++ b/test/src/math/frexpl_test.cpp
@@ -93,7 +93,7 @@
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;
diff --git a/utils/FPUtil/FPBits.h b/utils/FPUtil/FPBits.h
index b2c1e57..bc69829 100644
--- a/utils/FPUtil/FPBits.h
+++ b/utils/FPUtil/FPBits.h
@@ -102,7 +102,7 @@
FPBits() : integer(0) {}
- operator T() { return val; }
+ explicit operator T() { return val; }
UIntType uintval() const { return integer; }
@@ -143,7 +143,7 @@
static T buildNaN(UIntType v) {
FPBits<T> bits = inf();
bits.encoding.mantissa = v;
- return bits;
+ return T(bits);
}
};
diff --git a/utils/FPUtil/Hypot.h b/utils/FPUtil/Hypot.h
index 3585304..adbd9f5 100644
--- a/utils/FPUtil/Hypot.h
+++ b/utils/FPUtil/Hypot.h
@@ -125,7 +125,7 @@
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;
@@ -208,7 +208,7 @@
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
@@ -254,7 +254,7 @@
Y -= one >> 1;
++out_exp;
if (out_exp >= FPBits_t::maxExponent) {
- return FPBits_t::inf();
+ return T(FPBits_t::inf());
}
}
diff --git a/utils/FPUtil/ManipulationFunctions.h b/utils/FPUtil/ManipulationFunctions.h
index f0e5c8f..9bd54ec 100644
--- a/utils/FPUtil/ManipulationFunctions.h
+++ b/utils/FPUtil/ManipulationFunctions.h
@@ -47,13 +47,14 @@
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;
}
@@ -65,7 +66,7 @@
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,
@@ -104,12 +105,12 @@
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);
@@ -131,11 +132,11 @@
// 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);
diff --git a/utils/FPUtil/NearestIntegerOperations.h b/utils/FPUtil/NearestIntegerOperations.h
index 7bb79be..5ea4b41 100644
--- a/utils/FPUtil/NearestIntegerOperations.h
+++ b/utils/FPUtil/NearestIntegerOperations.h
@@ -51,7 +51,7 @@
int trimSize = MantissaWidth<T>::value - exponent;
bits.encoding.mantissa = (bits.encoding.mantissa >> trimSize) << trimSize;
- return bits;
+ return T(bits);
}
template <typename T,
diff --git a/utils/FPUtil/NormalFloat.h b/utils/FPUtil/NormalFloat.h
index 79e3d34..07bb91b 100644
--- a/utils/FPUtil/NormalFloat.h
+++ b/utils/FPUtil/NormalFloat.h
@@ -93,7 +93,7 @@
// 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));
@@ -126,15 +126,15 @@
// 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:
@@ -245,16 +245,16 @@
} 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
diff --git a/utils/FPUtil/TestHelpers.h b/utils/FPUtil/TestHelpers.h
index 6ad6d3f..263eace 100644
--- a/utils/FPUtil/TestHelpers.h
+++ b/utils/FPUtil/TestHelpers.h
@@ -68,11 +68,11 @@
#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( \