> >> sage > >> Sage Version 4.3.5, Release Date: > >> 2010-03-28 > >> sage: 1+1 > >> 2 > >> sage: 6e-6 % 10e-6 > >> -4.00000000000000e-6 > >> > >> I'm sure sage is wrong.. :( > > > > They're both the same... > > No they aren't. > > If you type > > sage: s = 6e-6 > sage: s.__mod__?? > > then you can read the documentation for Sage's % on real numbers. > Definitely the result > > sage: 6e-6 - 10e-6 > -4.00000000000000e-6 > > matches what is claimed in the docstring. The actual function calls the > MPFR function "mpfr_remainder", which is documented here: > > http://www.mpfr.org/algorithms.pdf > > See Section 3.8.
exactly, MPFR follows the ISO C99 remainder function (see "man remainder"): the quotient is rounded to the nearest integer, with ties to even, for example sage: 5. % 10. 5.00000000000000 sage: 15. % 10. -5.00000000000000 However maybe Sage could use the "mpfr_fmod" function instead, which rounds its quotient towards zero. This would match the Python function for positive quotient, but not for negative quotient, since the Python function seems to round the quotient towards -infinity: >>> (-6e-6) % 10e-6 4.0000000000000007e-06 >>> (6e-6) % (-10e-6) -4.0000000000000007e-06 In C99 (and in MPFR) there is no mod/remainder function that rounds towards -infinity. Paul Zimmermann -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org To unsubscribe, reply using "remove me" as the subject.