(08-26-2019, 01:49 PM)dexter1 Wrote: I can attest the sign being negative when executing the binary with either -lm or -lmx library
This violates C standard because the sign of the first operand should be preserved. But on the other hand, positive zero compares with negative zero.
You could wrap fmod into an other function and copy the sign from the x operand like
Code:
double fmodwrapper(double x, double y)
{
double r = fmod(x,y);
return abs(r)*sgn(x); /* not sure if C has a sign function like sgn, but it can be macro'd */
}
Hi dexter. First off, thanks for your help. It's alaways a pleasure to see you around.
This fmod bug is something to note for other projects. Surprisingly, the manpage states the correct behaviour for this function.
Thanks for the proposed workaround. Since there are only two cases when the sign is wrong, I've come up with my own inline sign correcting solution:
f = x >= 0.0L ? 1.0L : -1.0L;
if (((f == 1.0L) && (mod <= -0.0L)) || ((f == -1.0L) && (mod >= 0.0L)))
mod = -1.0L * mod;
Greets