fabs(-0.0) returns -0.0
Khilan Gudka
Khilan.Gudka at cl.cam.ac.uk
Mon Nov 13 22:52:34 UTC 2017
Hi,
The implementation of fabs(3) for MIPS (at least) appears to not be giving
the right answer for when -0 is passed, as it returns -0 instead of +0. The
implementation of fabs is:
double fabs(double x) {
if (x < 0)
return -x;
return x;
}
The if-test fails for -0 and thus it is returned. Is this a known issue? A
simple fix would be to return x+0.0 instead of just x.
The implication of this is that other functions which rely on fabs, such as
hypot, also return -0. For example, hypot(-0.0, 0.0) returns -0 instead of
+0.
Thanks,
Khilan
More information about the freebsd-mips
mailing list