This is how round(x) is in the C library:
(http://www.gnu.org/s/libc/manual/html_node/Rounding-Functions.html)
Function: double round (double x)
— Function: float roundf (float x)
— Function: long double roundl (long double x)
These functions are similar to rint, but they round
halfway cases away from zero instead of to the nearest even integer.
I think they just compute round(x) as floor(x+0.5)
Perhaps rounding for rational numbers can be changed to floor(x+1/2),
accordingly.
On Sun, Nov 29, 2009 at 11:33 AM, mhampton <[email protected]> wrote:
> 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.
>
>
>
--
"The main things which seem to me important on their own account, and
not merely as means to other things, are knowledge, art, instinctive
happiness, and relations of friendship or affection."
-Bertrand Russell
L. Felipe Martins
Department of Mathematics
Cleveland State University
[email protected]
--
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.