[libc-commits] [libc] [libc][math] Update getpayload and fmul with NaN inputs. (PR #99812)
via libc-commits
libc-commits at lists.llvm.org
Sun Jul 21 11:18:10 PDT 2024
================
@@ -50,19 +50,19 @@ mul(InType x, InType y) {
raise_except_if_required(FE_INVALID);
if (x_bits.is_quiet_nan()) {
- InStorageType x_payload = static_cast<InStorageType>(getpayload(x));
- if ((x_payload & ~(OutFPBits::FRACTION_MASK >> 1)) == 0)
- return OutFPBits::quiet_nan(x_bits.sign(),
- static_cast<OutStorageType>(x_payload))
- .get_val();
+ InStorageType x_payload = x_bits.get_mantissa();
+ x_payload >>= (InFPBits::FRACTION_LEN - OutFPBits::FRACTION_LEN);
+ return OutFPBits::quiet_nan(x_bits.sign(),
+ static_cast<OutStorageType>(x_payload))
+ .get_val();
----------------
overmighty wrote:
IEEE Std 754-2019, section 6.2.3 "NaN propagation":
> An operation that propagates a NaN operand to its result and has a single NaN as an input should produce a
NaN with the payload of the input NaN if representable in the destination format.
>
> [...]
>
> Conversion of a quiet NaN to a floating-point format of the same or a different radix that does not allow
the payload to be preserved shall return a quiet NaN that should provide some language-defined diagnostic
information.
But I'm not sure if conversion covers rounding the result to a narrower type in this case, and if the second paragraph is complementary to the first one (an operation that propagates a NaN operand should return a quiet NaN with language-defined diagnostic information if the payload of the input NaN is not representable in the destination format) or if it's just a different case (an operation that propagates a NaN operand can return a NaN with whatever payload if the payload of the input NaN is not representable in the destination format).
Maybe conversion just means conversion operators/functions. glibc seems to just truncate the lower bits of the mantissa: https://godbolt.org/z/aP7Yhccje.
https://github.com/llvm/llvm-project/pull/99812
More information about the libc-commits
mailing list