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) *  |
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) *  |
Date: 2010-12-01 14:40 |
Did you look at the second footnote on that page? |
|
|
msg123340 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
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) *  |
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) *  |
Date: 2011-04-19 17:13 |
Uncle Timmy, was this the right thing to do? |
|
|
msg134122 - (view) |
Author: Tim Peters (tim.peters) *  |
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) *  |
Date: 2011-04-21 08:50 |
Raymond: just curious---why do you ask? Did this fix break something? |
|
|