Ask Your Question

Why .45 // .28 does not work?

asked 2018-08-28 04:03:40 -0500

Sébastien gravatar image

Taking modulo works with Python float and Sage float:

sage: .45r % .28r
sage: .45 % .28

The quotient works with Python float:

sage: .45r // .28r

But why should it not work with Sage float as well?

sage: .45 // .28
Traceback (most recent call last):
TypeError: unsupported operand parent(s) for //: 'Real Field with 53 bits of precision' and 'Real Field with 53 bits of precision'
edit retag flag offensive close merge delete


You can have a look at my proposal concerning the operator % in #21747 and #21745

vdelecroix gravatar imagevdelecroix ( 2018-08-30 07:00:41 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2018-08-28 07:37:14 -0500

Emmanuel Charpentier gravatar image

updated 2018-08-28 07:49:09 -0500

At first sight, this seems indeed inconsistent, but I've learned to be wary of "obvious" answers when it comes to Sage's arithmetic.

The type of the objects may be a hint :

sage: type(.45)
<type 'sage.rings.real_mpfr.RealLiteral'>
sage: type(.45/.28)
<type 'sage.rings.real_mpfr.RealNumber'>

So mpfr defines some operator called / (possibly division) of RealNumbers (and, BTW, of RealLiterals), ...

sage: type(.45%.28)
<type 'sage.rings.real_mpfr.RealNumber'>

... as well as something called % (which indeed looks like modulo.

The question is now why mpfrs authors did not define anything called //. And why Sage's developers didn't extend mpfr to define //...

May I suggest to ask this interesting question on sage-support (or possibly sage-devel) ? There might be subtleties I am not aware of.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-08-28 04:03:40 -0500

Seen: 47 times

Last updated: Aug 28