First time here? Check out the FAQ!

Ask Your Question
0

Why .45 // .28 does not work?

asked 6 years ago

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'
Preview: (hide)

Comments

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

vdelecroix gravatar imagevdelecroix ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

Emmanuel Charpentier gravatar image

updated 6 years ago

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.

Preview: (hide)
link

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: 6 years ago

Seen: 313 times

Last updated: Aug 28 '18