On Thu, Mar 6, 2008 at 5:48 PM, Nikos Apostolakis <[EMAIL PROTECTED]> wrote:
>
> "didier deshommes" <[EMAIL PROTECTED]> writes:
>
> > On Thu, Mar 6, 2008 at 4:22 PM, Nikos Apostolakis <[EMAIL PROTECTED]>
> wrote:
> >>
> >> Hello group,
> >>
> >> Is the following behavior a bug, or am I missing some fundamental
> >> understanding about how Integer works?
> >>
> >> ,----
> >> | sage: num = RealField(12).random_element(1,9.99)
> >> | sage: num
> >> | 3.18
> >> | sage: num*100
> >> | 318.
> >> | sage: Integer(_)
> >
> > I can confirm this. I think numbers are rounded up when they are
> > printed, which leads to confusion:
> > {{{
> > sage: num = RealField(12).random_element(1,9.99)*100
> > sage: num
> > 406.
> > }}}
> >
> > But num is actually ~405.725! :
> > {{{
> > sage: num -406
> > -0.375
> >
> > }}}
> >
> > And so ZZ(num) will fail, as it should, since num ~ 405.725.
> >
>
> Hm, I see! This behavior is very confusing. Wouldn't you say it *is*
> a bug?
I would say so. But I also remember Carl Witty and William putting a
lot of time into this. Any of you guys want to chime in?
>
> Anyway to get what I expected to get I can do something like
>
> sage: Integer(sage_eval(str(num))*100)
> 318
>
> but it seems like an ugly hack. Is there another way?
I would use the floor() function on this real number. It returns an Integer:
sage: q=num.floor()
sage: type(q)
<type 'sage.rings.integer.Integer'>
didier
>
>
>
> Thanks,
> Nikos
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---