Skip to content

Commit 2c314bc

Browse files
committed
[libc][math][c23] Fix RoundToIntegerTest.h
1 parent daaf55b commit 2c314bc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,9 @@ template <typename T> bool round_to_long(T x, long &result) {
10851085
template bool round_to_long<float>(float, long &);
10861086
template bool round_to_long<double>(double, long &);
10871087
template bool round_to_long<long double>(long double, long &);
1088+
#ifdef LIBC_TYPES_HAS_FLOAT16
1089+
template bool round_to_long<float16>(float16, long &);
1090+
#endif
10881091

10891092
template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
10901093
MPFRNumber mpfr(x);
@@ -1094,6 +1097,9 @@ template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
10941097
template bool round_to_long<float>(float, RoundingMode, long &);
10951098
template bool round_to_long<double>(double, RoundingMode, long &);
10961099
template bool round_to_long<long double>(long double, RoundingMode, long &);
1100+
#ifdef LIBC_TYPES_HAS_FLOAT16
1101+
template bool round_to_long<float16>(float16, RoundingMode, long &);
1102+
#endif
10971103

10981104
template <typename T> T round(T x, RoundingMode mode) {
10991105
MPFRNumber mpfr(x);
@@ -1104,7 +1110,9 @@ template <typename T> T round(T x, RoundingMode mode) {
11041110
template float round<float>(float, RoundingMode);
11051111
template double round<double>(double, RoundingMode);
11061112
template long double round<long double>(long double, RoundingMode);
1113+
#ifdef LIBC_TYPES_HAS_FLOAT16
11071114
template float16 round<float16>(float16, RoundingMode);
1115+
#endif
11081116

11091117
} // namespace mpfr
11101118
} // namespace testing

0 commit comments

Comments
 (0)