ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Aug 2018 07:00:41 -0500Why .45 // .28 does not work?https://ask.sagemath.org/question/43498/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'
Tue, 28 Aug 2018 04:03:40 -0500https://ask.sagemath.org/question/43498/why-45-28-does-not-work/Comment by vdelecroix for <p>Taking modulo works with Python float and Sage float:</p>
<pre><code>sage: .45r % .28r
0.16999999999999998
sage: .45 % .28
-0.110000000000000
</code></pre>
<p>The quotient works with Python float:</p>
<pre><code>sage: .45r // .28r
1.0
</code></pre>
<p>But why should it not work with Sage float as well?</p>
<pre><code>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'
</code></pre>
https://ask.sagemath.org/question/43498/why-45-28-does-not-work/?comment=43531#post-id-43531You can have a look at my proposal concerning the operator % in [#21747](https://trac.sagemath.org/ticket/21747) and [#21745](https://trac.sagemath.org/ticket/21745)Thu, 30 Aug 2018 07:00:41 -0500https://ask.sagemath.org/question/43498/why-45-28-does-not-work/?comment=43531#post-id-43531Answer by Emmanuel Charpentier for <p>Taking modulo works with Python float and Sage float:</p>
<pre><code>sage: .45r % .28r
0.16999999999999998
sage: .45 % .28
-0.110000000000000
</code></pre>
<p>The quotient works with Python float:</p>
<pre><code>sage: .45r // .28r
1.0
</code></pre>
<p>But why should it not work with Sage float as well?</p>
<pre><code>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'
</code></pre>
https://ask.sagemath.org/question/43498/why-45-28-does-not-work/?answer=43502#post-id-43502At 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 `RealNumber`s (and, BTW, of `RealLiteral`s), ...
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 `mpfr`s 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](https://groups.google.com/forum/#!forum/sage-support) (or possibly [sage-devel](https://groups.google.com/forum/#!forum/sage-devel)) ? There might be subtleties I am not aware of.Tue, 28 Aug 2018 07:37:14 -0500https://ask.sagemath.org/question/43498/why-45-28-does-not-work/?answer=43502#post-id-43502