[Python-checkins] CVS: python/dist/src/Objects floatobject.c,2.104,2.105
Tim Peters
tim_one@users.sourceforge.net
2001年11月01日 15:12:29 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv12223/python/Objects
Modified Files:
floatobject.c
Log Message:
SF bug #477221: abs and divmod act oddly with -0.0
Try to ensure that divmod(-0.0, 1.0) -> (-0.0, +0.0) across platforms.
It always did on Windows, and still does. It didn't on Linux. Alas,
there's no platform-independent way to write a test case for this.
Bugfix candidate.
Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.104
retrieving revision 2.105
diff -C2 -d -r2.104 -r2.105
*** floatobject.c 2001年11月01日 21:51:15 2.104
--- floatobject.c 2001年11月01日 23:12:27 2.105
***************
*** 465,479 ****
*/
div = (vx - mod) / wx;
! /* note: checking mod*wx < 0 is incorrect -- underflows to
! 0 if wx < sqrt(smallest nonzero double) */
! if (mod && ((wx < 0) != (mod < 0))) {
! mod += wx;
! div -= 1.0;
}
/* snap quotient to nearest integral value */
! floordiv = floor(div);
! if (div - floordiv > 0.5)
! floordiv += 1.0;
! PyFPE_END_PROTECT(div)
return Py_BuildValue("(dd)", floordiv, mod);
}
--- 465,496 ----
*/
div = (vx - mod) / wx;
! if (mod) {
! /* ensure the remainder has the same sign as the denominator */
! if ((wx < 0) != (mod < 0)) {
! mod += wx;
! div -= 1.0;
! }
}
+ else {
+ /* the remainder is zero, and in the presence of signed zeroes
+ fmod returns different results across platforms; ensure
+ it has the same sign as the denominator; we'd like to do
+ "mod = wx * 0.0", but that may get optimized away */
+ mod = 0.0;
+ if (wx < 0.0)
+ mod = -mod;
+ }
/* snap quotient to nearest integral value */
! if (div) {
! floordiv = floor(div);
! if (div - floordiv > 0.5)
! floordiv += 1.0;
! }
! else {
! /* div is zero - get the same sign as the true quotient */
! div *= div; /* hide "div = +0" from optimizers */
! floordiv = div * vx / wx; /* zero w/ sign of vx/wx */
! }
! PyFPE_END_PROTECT(floordiv)
return Py_BuildValue("(dd)", floordiv, mod);
}