# Bug Report We are developing a software verification tool. While testing it on musl libc’s **math library**, we observed the following issues. | No. | Function | Rounding mode | Example input | Output | Version | Reference specification (excerpts from POSIX.1-2024) | |:---:|:-----------:|:---------------------:|:-----------------------:|:---------------------:|:-----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | 1 | atanh | Downward | ±1 | ±nan | 1.2.5/1.2.6 | If x is ±1, a pole error shall occur, and atanh(), atanhf(), and atanhl() shall return the value of the macro HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively, with the same sign as the correct value of the function. | | 2 | atanhf | Downward | ±1 | ±nan | 1.2.5/1.2.6 | If x is ±1, a pole error shall occur, and atanh(), atanhf(), and atanhl() shall return the value of the macro HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively, with the same sign as the correct value of the function. | | 3 | acosh | Downward | 1 | -0 | 1.2.5/1.2.6 | [If x is +1, +0 shall be returned.](https://pubs.opengroup.org/onlinepubs/9799919799/functions/acosh.html) | | 4 | acoshf | Downward | 1 | -0 | 1.2.5/1.2.6 | [If x is +1, +0 shall be returned.](https://pubs.opengroup.org/onlinepubs/9799919799/functions/acosh.html) | | 5 | acosh | Nearest, ties to even | -0x1.a10c9ddbabc22p+12 | -0x1.a1803c4eba963p+3 | 1.2.5/1.2.6 | We are unsure whether this behavior violates the standard: [For finite values of x < 1, a domain error shall occur, and [MX] [Option Start] either a NaN (if supported), or [Option End] an implementation-defined value shall be returned.](https://pubs.opengroup.org/onlinepubs/9799919799/functions/acosh.html). | | 6 | jn | All four modes | -3, +Inf | -0 | 1.2.5/1.2.6 | [If x is +Inf, +0 shall be returned.](https://pubs.opengroup.org/onlinepubs/9799919799/functions/jn.html) | | 7 | jnf | All four modes | -3, +Inf | -0 | 1.2.5/1.2.6 | By analogy with jn(); POSIX.1-2024 does not specifically define jnf. We are unsure whether this behavior violates the standard. | | 8 | lgamma | Downward | -1 | -Inf | 1.2.5/1.2.6 | [If x is a non-positive integer, a pole error shall occur ... shall return +HUGE_VAL, +HUGE_VALF, and +HUGE_VALL, respectively.](https://pubs.opengroup.org/onlinepubs/9799919799/functions/lgamma.html) | | 9 | __lgamma_r | Downward | -1, &sign | -Inf | 1.2.5/1.2.6 | See item 8. | | 10 | lgamma_r | Downward | -1, &sign | -Inf | 1.2.5/1.2.6 | See item 8. | | 11 | lgammaf | Downward | -1 | -Inf | 1.2.5/1.2.6 | See item 8. | | 12 | __lgammaf_r | Downward | -1, &sign | -Inf | 1.2.5/1.2.6 | See item 8. | | 13 | lgammaf_r | Downward | -1, &sign | -Inf | 1.2.5/1.2.6 | See item 8. | | 14 | fma | Downward | 0x1p-600, 0x1p-600, -0 | -0 | 1.2.5 | [rounded as one ternary operation ... round once to the result format](https://pubs.opengroup.org/onlinepubs/9799919799/functions/fma.html). | | 15 | fma | Nearest, ties to even | -0x1p-600, 0x1p-600, +0 | +0 | 1.2.5 | [rounded as one ternary operation ... round once to the result format](https://pubs.opengroup.org/onlinepubs/9799919799/functions/fma.html). | | 16 | sincosf | Upward | 0x1.2d97c8p+2 | sin=-1-2⁻²³ | 1.2.5/1.2.6 | POSIX.1-2024 does not define this interface. The GNU manual requires both outputs to satisfy: [are in the range of -1 to 1.](https://sourceware.org/glibc/manual/2.42/html_node/Trig-Functions.html) We are unsure whether this behavior violates the standard. | | 17 | sincosf | Upward | 0x1.f9cbe2p+8 | cos=-1-2⁻²³ | 1.2.5/1.2.6 | POSIX.1-2024 does not define this interface. The GNU manual requires both outputs to satisfy: [are in the range of -1 to 1.](https://sourceware.org/glibc/manual/2.42/html_node/Trig-Functions.html) We are unsure whether this behavior violates the standard. | ## Classification by Cause 1. **Propagation of negative zero (1–4, 8–13)**: For these inputs, subtraction under downward rounding produces `-0`. In `atanh/atanhf`, this makes `1-|x|` negative zero, so division produces `-Inf` and the subsequent call to `log1p` returns NaN. In `acosh/acoshf`, the negative zero from `x-1` propagates to the return value. The six entry points in the `lgamma` family return `-Inf` by evaluating `1/(x-x)` at negative integer poles. 2. **Sign bit ignored when selecting a branch (5)**: When extracting the exponent, `acosh` masks out the sign bit, causing negative inputs to enter a branch intended for positive arguments. Taking the reciprocal amplifies the cancellation error in `x+sqrt(x*x-1)`, making the argument passed to `log` positive and producing a finite return value. 3. **Zero sign changed when handling negative orders (6–7)**: For negative odd orders, `jn/jnf` set a flag indicating that the result must be negated. When the input is infinite, the computation first produces `+0`; applying the flag before returning changes it to `-0`. 4. **Adding zero after product underflow (14–15)**: When `z=0`, the software implementation of `fma` directly evaluates `x*y+z`. The product first underflows to zero. Adding a zero of the opposite sign then changes its sign, so the result differs from rounding the exact multiply-add once. Both cases were reproduced in the software implementation on x86-64; musl builds that use hardware FMA may bypass this branch. 5. **Negation after overshoot in the cosine kernel (16–17)**: When the reduced argument is close to zero, upward rounding causes `__cosdf` to return `1+2⁻²³`. Depending on the quadrant, `sincosf` then negates this value, producing a sine or cosine result of `-1-2⁻²³`, below `-1`.