diff options
author | Fabian Schriever <fabian.schriever@gtd-gmbh.de> | 2020-03-10 11:24:12 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2020-03-10 15:11:23 +0100 |
commit | 18b4e0e5187f7e2076661e53747977f21dabedff (patch) | |
tree | b05a7b2cdfc7452c05692cc8b1b12268e9c1a277 /newlib/libm/common/sf_fdim.c | |
parent | a8a40ee5750cb8a4280379a38c1ed490262481c4 (diff) | |
download | newlib-18b4e0e5187f7e2076661e53747977f21dabedff.zip newlib-18b4e0e5187f7e2076661e53747977f21dabedff.tar.gz newlib-18b4e0e5187f7e2076661e53747977f21dabedff.tar.bz2 |
Fix error in fdim/f for infinities
The comparison c == FP_INFINITE causes the function to return +inf as it
expects x = +inf to always be larger than y. This shortcut causes
several issues as it also returns +inf for the following cases:
- fdim(+inf, +inf), expected (as per C99): +0.0
- fdim(-inf, any non NaN), expected: +0.0
I don't see a reason to keep the comparison as all the infinity cases
return the correct result using just the ternary operation.
Diffstat (limited to 'newlib/libm/common/sf_fdim.c')
-rw-r--r-- | newlib/libm/common/sf_fdim.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/newlib/libm/common/sf_fdim.c b/newlib/libm/common/sf_fdim.c index fe34909..8fee570 100644 --- a/newlib/libm/common/sf_fdim.c +++ b/newlib/libm/common/sf_fdim.c @@ -14,11 +14,8 @@ float y; #endif { - int c = __fpclassifyf(x); - if (c == FP_NAN) return(x); + if (__fpclassifyf(x) == FP_NAN) return(x); if (__fpclassifyf(y) == FP_NAN) return(y); - if (c == FP_INFINITE) - return HUGE_VALF; return x > y ? x - y : 0.0; } |