Ask Your Question
0

Why .45 // .28 does not work?

asked 2018-08-28 11:03:40 +0100

Sébastien gravatar image

Taking modulo works with Python float and Sage float:

sage: .45r % .28r
0.16999999999999998
sage: .45 % .28
-0.110000000000000

The quotient works with Python float:

sage: .45r // .28r
1.0

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

Comments

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

vdelecroix gravatar imagevdelecroix ( 2018-08-30 14:00:41 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2018-08-28 14:37:14 +0100

Emmanuel Charpentier gravatar image

updated 2018-08-28 14:49:09 +0100

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

Stats

Asked: 2018-08-28 11:03:40 +0100

Seen: 278 times

Last updated: Aug 28 '18