Skip to content

Commit 4758caf

Browse files
committed
Fix undefined behavior
1 parent ff3e115 commit 4758caf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libc/src/math/generic/tanhf16.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ LLVM_LIBC_FUNCTION(float16, tanhf16, (float16 x)) {
120120
float xf = x;
121121
float kf = fputil::nearest_integer(xf * (LOG2F_E * 2.0f * 0x1.0p+5f));
122122
int x_hi_mid = -static_cast<int>(kf);
123-
int x_hi = x_hi_mid >> 5;
124-
int x_mid = x_hi_mid & 0x1f;
123+
unsigned x_hi = static_cast<unsigned>(x_hi_mid) >> 5;
124+
unsigned x_mid = static_cast<unsigned>(x_hi_mid) & 0x1f;
125125
// lo = x - (hi + mid)
126126
// = round(x * log2(e) * 2 * 2^5) * log(2) * 0.5 * (-2^(-5)) + x
127127
float lo = fputil::multiply_add(kf, LOGF_2 * 0.5f * -0x1.0p-5f, xf);

0 commit comments

Comments
 (0)