Skip to content

Commit a83e0b1

Browse files
committed
Add explicit casts in Hypot
1 parent ec505e5 commit a83e0b1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

libc/src/__support/FPUtil/Hypot.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LIBC_INLINE T find_leading_one(T mant, int &shift_length) {
3030
if (mant > 0) {
3131
shift_length = (sizeof(mant) * 8) - 1 - cpp::countl_zero(mant);
3232
}
33-
return T(1) << shift_length;
33+
return (T)(T(1) << shift_length);
3434
}
3535

3636
} // namespace internal
@@ -207,8 +207,8 @@ LIBC_INLINE T hypot(T x, T y) {
207207

208208
for (StorageType current_bit = leading_one >> 1; current_bit;
209209
current_bit >>= 1) {
210-
r = (r << 1) + ((tail_bits & current_bit) ? 1 : 0);
211-
StorageType tmp = (y_new << 1) + current_bit; // 2*y_new(n - 1) + 2^(-n)
210+
r = (StorageType)(r << 1) + ((tail_bits & current_bit) ? 1 : 0);
211+
StorageType tmp = (StorageType)(y_new << 1) + current_bit; // 2*y_new(n - 1) + 2^(-n)
212212
if (r >= tmp) {
213213
r -= tmp;
214214
y_new += current_bit;

libc/test/src/math/exhaustive/hypotf16_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
3232
uint16_t ybits = xbits;
3333
do {
3434
float16 y = FPBits(ybits).get_val();
35-
bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y),
35+
bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot<float16>(x, y),
3636
LIBC_NAMESPACE::hypotf16(x, y));
3737
// Using MPFR will be much slower.
3838
// mpfr::BinaryInput<float16> input{x, y};

0 commit comments

Comments
 (0)