@@ -101,7 +101,7 @@ template <size_t Bits> struct DyadicFloat {
101
101
return exponent + (Bits - 1 );
102
102
}
103
103
104
- template <typename T>
104
+ template <typename T, bool ShouldSignalExceptions >
105
105
LIBC_INLINE constexpr cpp::enable_if_t <
106
106
cpp::is_floating_point_v<T> && (FPBits<T>::FRACTION_LEN < Bits), T>
107
107
generic_as () const {
@@ -116,8 +116,10 @@ template <size_t Bits> struct DyadicFloat {
116
116
int unbiased_exp = get_unbiased_exponent ();
117
117
118
118
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
+ }
121
123
122
124
switch (quick_get_round ()) {
123
125
case FE_TONEAREST:
@@ -191,7 +193,7 @@ template <size_t Bits> struct DyadicFloat {
191
193
break ;
192
194
}
193
195
194
- if (round || sticky) {
196
+ if (ShouldSignalExceptions && ( round || sticky) ) {
195
197
int excepts = FE_INEXACT;
196
198
if (FPBits (result).is_inf ()) {
197
199
set_errno_if_required (ERANGE);
@@ -339,10 +341,8 @@ template <size_t Bits> struct DyadicFloat {
339
341
void >>
340
342
LIBC_INLINE constexpr T as () const {
341
343
#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>();
346
346
#endif
347
347
return fast_as<T, ShouldSignalExceptions>();
348
348
}
0 commit comments