Skip to content

Commit d58d2ee

Browse files
committed
chore: update and fix test
Signed-off-by: Krishna Pandey <[email protected]>
1 parent 270f0a1 commit d58d2ee

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

libc/src/math/generic/expbf16.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ LLVM_LIBC_FUNCTION(bfloat16, expbf16, (bfloat16 x)) {
104104
}
105105
}
106106

107-
// x <= -93
108-
if (x_u >= 0xc2baU) {
107+
// x <= -92.5
108+
if (x_u >= 0xc2b9U) {
109109
// exp(-inf) = +0
110110
if (x_bits.is_inf())
111111
return FPBits::zero().get_val();
@@ -115,7 +115,10 @@ LLVM_LIBC_FUNCTION(bfloat16, expbf16, (bfloat16 x)) {
115115

116116
switch (fputil::quick_get_round()) {
117117
case FE_UPWARD:
118-
return FPBits::min_subnormal().get_val();
118+
case FE_TONEAREST:
119+
if (LIBC_UNLIKELY(x_u == 0xc2b9U))
120+
return FPBits::min_subnormal().get_val();
121+
return FPBits::zero().get_val();
119122
default:
120123
return FPBits::zero().get_val();
121124
}
@@ -145,7 +148,7 @@ LLVM_LIBC_FUNCTION(bfloat16, expbf16, (bfloat16 x)) {
145148
// For -93 < x < 89, we do the following range reduction:
146149
// x = hi + mid + lo
147150
// where,
148-
// hi / 2^3 is an integer
151+
// hi is an integer
149152
// mid * 2^2 is an integer
150153
// -2^3 <= lo <= 2^3
151154
// also, hi + mid = round(4 * x) / x

libc/test/src/math/smoke/expbf16_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TEST_F(LlvmLibcExpf16Test, Underflow) {
5757

5858
EXPECT_FP_EQ_WITH_EXCEPTION(
5959
zero,
60-
LIBC_NAMESPACE::expbf16(LIBC_NAMESPACE::fputil::cast<bfloat16>(-92.5f)),
60+
LIBC_NAMESPACE::expbf16(LIBC_NAMESPACE::fputil::cast<bfloat16>(-93.0f)),
6161
FE_UNDERFLOW | FE_INEXACT);
6262
EXPECT_MATH_ERRNO(ERANGE);
6363
}

0 commit comments

Comments
 (0)