On Apr 5, 2010, at 9:44 PM, William Stein wrote:

On Mon, Apr 5, 2010 at 9:12 PM, Michael Welsh <[email protected]> wrote:

On 6/04/2010, at 3:56 PM, Eugene Goldberg wrote:

Hello!

Here is my pyhtons results:

python
Python 2.6.5 (r265:79063, Mar 23 2010, 04:49:54)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1+1
2
6e-6 % 10e-6
6.0000000000000002e-06


and here is sage:

./
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.. :(

Well, at least the two answers are equivalent mod 10e-6.

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.

This web page: http://pyref.infogami.com/operator-mod describes the Python semantics for Python's __mod__ on float's. They are different than MPFR's.

I would be in favor of following Python's conventions here--they at least seem more natural to me (after all, % is related to "floor division" not "round division." :)

- Robert


--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
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.

Reply via email to