Skip to content

Commit 8492b25

Browse files
committed
[libc][math][c23] Fix RoundToIntegerTest.h
1 parent 8c29f63 commit 8492b25

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

libc/test/src/math/RoundToIntegerTest.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ class RoundToIntegerTestTemplate
137137
return;
138138

139139
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
140+
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
141+
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
142+
return;
140143
// We start with 1.0 so that the implicit bit for x86 long doubles
141144
// is set.
142145
FPBits bits(F(1.0));
143-
bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
146+
bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
144147
bits.set_sign(Sign::NEG);
145148
bits.set_mantissa(0);
146149

@@ -201,10 +204,13 @@ class RoundToIntegerTestTemplate
201204
return;
202205

203206
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
207+
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
208+
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
209+
return;
204210
// We start with 1.0 so that the implicit bit for x86 long doubles
205211
// is set.
206212
FPBits bits(F(1.0));
207-
bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
213+
bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
208214
bits.set_sign(Sign::NEG);
209215
bits.set_mantissa(FPBits::FRACTION_MASK);
210216

libc/utils/MPFRWrapper/MPFRUtils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ template <typename T> bool round_to_long(T x, long &result) {
10911091
template bool round_to_long<float>(float, long &);
10921092
template bool round_to_long<double>(double, long &);
10931093
template bool round_to_long<long double>(long double, long &);
1094+
#ifdef LIBC_TYPES_HAS_FLOAT16
1095+
template bool round_to_long<float16>(float16, long &);
1096+
#endif
10941097

10951098
template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
10961099
MPFRNumber mpfr(x);
@@ -1100,6 +1103,9 @@ template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
11001103
template bool round_to_long<float>(float, RoundingMode, long &);
11011104
template bool round_to_long<double>(double, RoundingMode, long &);
11021105
template bool round_to_long<long double>(long double, RoundingMode, long &);
1106+
#ifdef LIBC_TYPES_HAS_FLOAT16
1107+
template bool round_to_long<float16>(float16, RoundingMode, long &);
1108+
#endif
11031109

11041110
template <typename T> T round(T x, RoundingMode mode) {
11051111
MPFRNumber mpfr(x);
@@ -1110,6 +1116,9 @@ template <typename T> T round(T x, RoundingMode mode) {
11101116
template float round<float>(float, RoundingMode);
11111117
template double round<double>(double, RoundingMode);
11121118
template long double round<long double>(long double, RoundingMode);
1119+
#ifdef LIBC_TYPES_HAS_FLOAT16
1120+
template float16 round<float16>(float16, RoundingMode);
1121+
#endif
11131122

11141123
} // namespace mpfr
11151124
} // namespace testing

0 commit comments

Comments
 (0)