Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msun: Fix incorrect results in hypotl near underflow #455

Closed
wants to merge 1 commit into from

Conversation

ararslan
Copy link

This patch is the work of @kargl, fixing a bug reported by @zimmermann6 in JuliaMath/openlibm#224. @kargl's authorship has been preserved in the commit.


In the edited code, t1 is intended to scale subnormal numbers, but t1=1 is needed instead of t1=0 when preparing the scaling.

With this test program, compiled with -fno-builtin:

#include <stdio.h>
#include <math.h>

int main() {
    long double x = 0x3.6526795f4176ep-16384l;
    long double y = 0x3.ffffffffffffep-16352l;
    long double z = hypotl(x, y);
    printf("z=%La\n", z);
    return 0;
}

msun generates z=0x0p+0, whereas GNU libc generates z=0xf.ffffffffffff8p-16354.

The result from msun is incorrect, as hypot(x, y) >= |y|, and thus cannot be zero for nonzero y.

This issue was reported by zimmermann6 on GitHub to openlibm, which repackages parts of msun. The test case is their work.

In the edited code, `t1` is intended to scale subnormal numbers, but
`t1=1` is needed instead of `t1=0` when preparing the scaling.

With this test program, compiled with `-fno-builtin`:
```c

int main() {
    long double x = 0x3.6526795f4176ep-16384l;
    long double y = 0x3.ffffffffffffep-16352l;
    long double z = hypotl(x, y);
    printf("z=%La\n", z);
    return 0;
}
```
msun generates `z=0x0p+0`, whereas GNU libc generates
`z=0xf.ffffffffffff8p-16354`.

The result from msun is incorrect, as `hypot(x, y) >= |y|`, and thus
cannot be zero for nonzero `y`.

This issue was reported by zimmermann6 on GitHub to openlibm, which
repackages parts of msun. The test case is their work.
@bsdimp
Copy link
Member

bsdimp commented Jun 3, 2021

d3338f3 by dim@ fixed this shortly after the pull request was opened and merged to openlibm...

@bsdimp bsdimp closed this Jun 3, 2021
@ararslan ararslan deleted the aa/hypotl branch June 3, 2021 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants