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.
This commit is contained in:
parent
a8a40ee575
commit
18b4e0e518
|
@ -49,11 +49,8 @@ ANSI C, POSIX.
|
||||||
double y;
|
double y;
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int c = __fpclassifyd(x);
|
if (__fpclassifyd(x) == FP_NAN) return(x);
|
||||||
if (c == FP_NAN) return(x);
|
|
||||||
if (__fpclassifyd(y) == FP_NAN) return(y);
|
if (__fpclassifyd(y) == FP_NAN) return(y);
|
||||||
if (c == FP_INFINITE)
|
|
||||||
return HUGE_VAL;
|
|
||||||
|
|
||||||
return x > y ? x - y : 0.0;
|
return x > y ? x - y : 0.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,8 @@
|
||||||
float y;
|
float y;
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int c = __fpclassifyf(x);
|
if (__fpclassifyf(x) == FP_NAN) return(x);
|
||||||
if (c == FP_NAN) return(x);
|
|
||||||
if (__fpclassifyf(y) == FP_NAN) return(y);
|
if (__fpclassifyf(y) == FP_NAN) return(y);
|
||||||
if (c == FP_INFINITE)
|
|
||||||
return HUGE_VALF;
|
|
||||||
|
|
||||||
return x > y ? x - y : 0.0;
|
return x > y ? x - y : 0.0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue