bug? from __future__ import division

8 views
Skip to first unread message

Mats

unread,
Jun 15, 2008, 9:45:22 AM6/15/08
to sage-devel
Hello,

I've done Integer=int, but however it seems that after I do "from
__future__ import division", I still get 2/3=1. This does not occur in
the python interpreter; I get .666666... as I should.

Sincerely,
Mats

Nick Alexander

unread,
Jun 15, 2008, 1:12:56 PM6/15/08
to sage-...@googlegroups.com

On 15-Jun-08, at 6:45 AM, Mats wrote:
>
> Hello,
>
> I've done Integer=int, but however it seems that after I do "from
> __future__ import division", I still get 2/3=1.

Can you give an example?

> This does not occur in
> the python interpreter; I get .666666... as I should.

If you mean that you find

sage: 2/3
.66666

then something is very strange. By default, the sage interpreter
preparses '2/3' to 'Integer(2)/Integer(3)' which evaluates to a
Rational, namely 2/3. So you should get

sage: 2/3
2/3

You can turn off the preparser -- preparse? might give you useful
information and examples.

Examples of what you want to do would be useful.
Nick

William Stein

unread,
Jun 15, 2008, 1:36:37 PM6/15/08
to sage-...@googlegroups.com
On Sun, Jun 15, 2008 at 10:12 AM, Nick Alexander <ncale...@gmail.com> wrote:
>
>
> On 15-Jun-08, at 6:45 AM, Mats wrote:
>>
>> Hello,
>>
>> I've done Integer=int, but however it seems that after I do "from
>> __future__ import division", I still get 2/3=1.
>
> Can you give an example?

The original poster is claiming that the following doesn't work:

D-69-91-137-77:~ was$ sage
----------------------------------------------------------------------
| SAGE Version 3.0.2, Release Date: 2008-05-24 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: from __future__ import division
sage: 2/3
2/3
sage: Integer = int
sage: 2/3
0.66666666666666663

Actually it does, so .... ?

>
>> This does not occur in
>> the python interpreter; I get .666666... as I should.
>
> If you mean that you find
>
> sage: 2/3
> .66666
>
> then something is very strange. By default, the sage interpreter
> preparses '2/3' to 'Integer(2)/Integer(3)' which evaluates to a
> Rational, namely 2/3. So you should get
>
> sage: 2/3
> 2/3
>
> You can turn off the preparser -- preparse? might give you useful
> information and examples.
>
> Examples of what you want to do would be useful.
> Nick
>
> >
>

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Mats

unread,
Jun 17, 2008, 12:59:28 PM6/17/08
to sage-devel
It seems that "from __future__ import division" works in console mode,
but does not work in notebook mode.
Running the commands quoted below will yield the expected results in
the console mode (.6666...), but 2/3 will equal 0 in notebook mode.

Sincerely,
Mats

On Jun 15, 1:36 pm, "William Stein" <wst...@gmail.com> wrote:

Mats

unread,
Jul 6, 2008, 2:31:50 PM7/6/08
to sage-devel
Excuse me please, but is there any sort of workaround yet to this? It
is preventing me from running python code that expects 2/3=0.6666...
in notebook mode...

Thank you,
Mats
Reply all
Reply to author
Forward
0 new messages