[libc-commits] [libc] [libc][math][c23] Add f16fmaf C23 math function (PR #95483)
via libc-commits
libc-commits at lists.llvm.org
Fri Jun 14 07:53:48 PDT 2024
================
@@ -251,20 +275,21 @@ template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
----------------
overmighty wrote:
GitHub doesn't let me comment on the lines above because they're too far away from changes, but I think this is wrong:
```cpp
} else {
// Return +0.0 when there is exact cancellation, i.e., x*y == -z exactly.
prod_sign = Sign::POS;
}
```
To quote IEEE Std 754-2019 section "6.3 The sign bit":
> When the sum of two operands with opposite signs (or the difference of two operands with like signs) is
exactly zero, the sign of that sum (or difference) shall be +0 under all rounding-direction attributes except
roundTowardNegative; under that attribute, the sign of an exact zero sum (or difference) shall be −0.
However, under all rounding-direction attributes, when *x* is zero, *x*+*x* and *x*−(−*x*) have the sign of *x*.
>
> When (*a*×*b*)+*c* is exactly zero, the sign of **fusedMultiplyAdd**(*a*, *b*, *c*) shall be determined by the rules
above for a sum of operands. When the exact result of (*a*×*b*)+*c* is non-zero yet the result of
**fusedMultiplyAdd** is zero because of rounding, the zero result takes the sign of the exact result.
Also see https://godbolt.org/z/KsaKMYKao.
https://github.com/llvm/llvm-project/pull/95483
More information about the libc-commits
mailing list