This is because in the code for rounding, an element's own round
method is tried before converting to a float.  The round function for
rationals rounds up if its exactly halfway:

    else:
        q, r = self.numerator().quo_rem(self.denominator())
        if r < self.denominator() / 2:
            return q
        else:
            return q+1

To get consistent results you could use round(N()) instead.  But
perhaps this should be considered a bug in the rational rounding.  I'm
not sure if there is a standard convention for that, its clearly a
borderline case.

-Marshall Hampton

On Nov 29, 9:47 am, michel paul <[email protected]> wrote:
> sage: round(4.5)
> 5.0
> sage: round(9/2)
> 4.0
>
> I noticed some strange behavior in a graph and tried to narrow down the
> issue.  This was it.
>
> --
> "Computer science is the new mathematics."
>
> -- Dr. Christos Papadimitriou

--

You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
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-edu?hl=en.


Reply via email to