-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Signed zero discrepancy vs. Python on float np.remainder #6317
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
Comments
Speaking of
Probably should return 0 with a warning, like |
Oh oops misread, you are talking about np.remainder |
fwiw that's a float nan interpreted as an integer (sorry for continuing off-topic..) >>> np.float64(np.nan).astype(int)
-9223372036854775808 |
Yes. Sorry for noise, please continue any side discussion at #6318. |
The problem with how the remainder is calculated also affects |
I'm not sure this is the same issue. Here the result's value is correct, just the sign is incorrect (note that 0.0 == -0.0). |
@pitrou - you may be right that the problems are separate. My link was triggered by the problem in |
I think the root of the problem is how the sign is calculated here:
From the most recent commit to that file it looks like the author's intention was to copy the behavior of the python function /* div is zero - get the same sign as the true quotient */
floordiv = copysign(0.0, vx / wx); /* zero w/ sign of vx/wx */ and double
copysign(double x, double y)
{
/* use atan2 to distinguish -0. from 0. */
if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) {
return fabs(x);
} else {
return -fabs(x);
}
} however the numpy implementation does not use the |
Closing as I think this has been fixed, on current master:
|
It seems Python is right here, since the result is supposed to be of the same sign as the dividend, e.g.:
And actually:
The text was updated successfully, but these errors were encountered: