Skip to content

Commit ac3f758

Browse files
committed
Add ShouldSignalExceptions support to generic_as()
1 parent f560144 commit ac3f758

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ template <size_t Bits> struct DyadicFloat {
101101
return exponent + (Bits - 1);
102102
}
103103

104-
template <typename T>
104+
template <typename T, bool ShouldSignalExceptions>
105105
LIBC_INLINE constexpr cpp::enable_if_t<
106106
cpp::is_floating_point_v<T> && (FPBits<T>::FRACTION_LEN < Bits), T>
107107
generic_as() const {
@@ -116,8 +116,10 @@ template <size_t Bits> struct DyadicFloat {
116116
int unbiased_exp = get_unbiased_exponent();
117117

118118
if (unbiased_exp + FPBits::EXP_BIAS >= FPBits::MAX_BIASED_EXPONENT) {
119-
set_errno_if_required(ERANGE);
120-
raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
119+
if constexpr (ShouldSignalExceptions) {
120+
set_errno_if_required(ERANGE);
121+
raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
122+
}
121123

122124
switch (quick_get_round()) {
123125
case FE_TONEAREST:
@@ -191,7 +193,7 @@ template <size_t Bits> struct DyadicFloat {
191193
break;
192194
}
193195

194-
if (round || sticky) {
196+
if (ShouldSignalExceptions && (round || sticky)) {
195197
int excepts = FE_INEXACT;
196198
if (FPBits(result).is_inf()) {
197199
set_errno_if_required(ERANGE);
@@ -339,10 +341,8 @@ template <size_t Bits> struct DyadicFloat {
339341
void>>
340342
LIBC_INLINE constexpr T as() const {
341343
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
342-
if constexpr (cpp::is_same_v<T, float16>) {
343-
static_assert(ShouldSignalExceptions);
344-
return generic_as<T>();
345-
}
344+
if constexpr (cpp::is_same_v<T, float16>)
345+
return generic_as<T, ShouldSignalExceptions>();
346346
#endif
347347
return fast_as<T, ShouldSignalExceptions>();
348348
}

0 commit comments

Comments
 (0)