Skip to content

Commit 0ccec54

Browse files
[libc] Fix compilation when long double is used as float128 (#97747)
Small patch that fixes the compilation when float128 is a long double, e.g., rv32. It fixes a static_cast, adds a missing %= operator and changes a cast to use get_val() in a test case instead
1 parent 8bb4294 commit 0ccec54

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

libc/src/__support/FPUtil/generic/FMod.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ template <typename T> struct FModDivisionInvMultHelper {
160160
template <typename T, typename U = typename FPBits<T>::StorageType,
161161
typename DivisionHelper = FModDivisionSimpleHelper<U>>
162162
class FMod {
163-
static_assert(cpp::is_floating_point_v<T> && cpp::is_unsigned_v<U> &&
163+
static_assert(cpp::is_floating_point_v<T> &&
164+
is_unsigned_integral_or_big_int_v<U> &&
164165
(sizeof(U) * CHAR_BIT > FPBits<T>::FRACTION_LEN),
165166
"FMod instantiated with invalid type.");
166167

libc/src/__support/big_int.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@ struct BigInt {
731731
return *result.div(other);
732732
}
733733

734+
LIBC_INLINE constexpr BigInt operator%=(const BigInt &other) {
735+
return *this->div(other);
736+
}
737+
734738
LIBC_INLINE constexpr BigInt &operator*=(const BigInt &other) {
735739
*this = *this * other;
736740
return *this;

libc/test/src/math/smoke/CopySignTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class CopySignTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
4242
StorageType v = 0;
4343
for (int i = 0; i <= COUNT; ++i, v += STEP) {
4444
FPBits x_bits = FPBits(v);
45-
T x = T(v);
4645
if (x_bits.is_nan() || x_bits.is_inf())
4746
continue;
47+
T x = x_bits.get_val();
4848

4949
T res1 = func(x, -x);
5050
ASSERT_FP_EQ(res1, -x);

0 commit comments

Comments
 (0)