Issue 10596: modulo operator bug (original) (raw)

Created on 2010-12-01 11:53 by Sergio.Ĥlutĉin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (10)
msg122991 - (view) Author: Сергей Хлутчин (Sergio.Ĥlutĉin) Date: 2010-12-01 11:53
Result of the modulo operator is wrong: >>> (-2.22044604925e-16)%4 4.0 >>> (-4.0)%4 -0.0
msg122992 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-12-01 12:24
What results were you expecting here? Both those results look fine to me (though it's arguable that the second should be +0.0 rather than -0.0).
msg122993 - (view) Author: Сергей Хлутчин (Sergio.Ĥlutĉin) Date: 2010-12-01 13:10
From the documetation: The modulo operator always yields a result with the same sign as its second operand (or zero); the absolute value of the result is strictly smaller than the absolute value of the second operand.
msg122995 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-12-01 14:40
Did you look at the second footnote on that page?
msg123340 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-12-04 12:27
Fixed the sign of the zero (in py3k) in r87032. I'll backport to 2.7 and 3.1, then close this. Sergio, is that acceptable? You still haven't said what results you were expecting for these operations.
msg123344 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-12-04 13:06
Backported to 3.1 (after one botched backport attempt) and 2.7 in r87037 and r87033.
msg123438 - (view) Author: Сергей Хлутчин (Sergio.Ĥlutĉin) Date: 2010-12-05 20:32
Yes i agree, the first example is the result of rounding error, as well as here: >>> 4.0-2.22044604925e-16==4.0 True
msg134081 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-04-19 17:13
Uncle Timmy, was this the right thing to do?
msg134122 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2011-04-20 04:14
Raymond, Mark pointed to the footnote explaining the first result. As to the second, Kahan tried his best, but I'm afraid nobody can make me care about the sign bit on a zero ;-) Whatever Mark thought best is fine by me.
msg134199 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-04-21 08:50
Raymond: just curious---why do you ask? Did this fix break something?
History
Date User Action Args
2022-04-11 14:57:09 admin set github: 54805
2011-04-21 08:50:06 mark.dickinson set messages: +
2011-04-20 04:14:55 tim.peters set messages: +
2011-04-19 17:13:36 rhettinger set assignee: mark.dickinson -> tim.petersmessages: + nosy: + rhettinger, tim.peters
2010-12-05 20:32:58 Sergio.Ĥlutĉin set messages: +
2010-12-04 13:06:28 mark.dickinson set status: open -> closedmessages: +
2010-12-04 12:27:42 mark.dickinson set resolution: fixedstage: resolvedmessages: + versions: + Python 3.1, Python 2.7, - Python 2.6
2010-12-01 14:40:07 mark.dickinson set messages: +
2010-12-01 13:10:03 Sergio.Ĥlutĉin set messages: +
2010-12-01 12:24:27 mark.dickinson set assignee: mark.dickinsonmessages: +
2010-12-01 12:06:57 pitrou set nosy: + mark.dickinson
2010-12-01 11:53:17 Sergio.Ĥlutĉin create