Ask Your Question

# Why .45 // .28 does not work?

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 close merge delete

## Comments

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

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

## 1 Answer

Sort by » oldest newest most voted

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.

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 255 times

Last updated: Aug 28 '18