On Tue, Mar 5, 2019 at 7:53 PM Nils Bruin <nbr...@sfu.ca> wrote: > > On Tuesday, March 5, 2019 at 10:27:47 AM UTC-8, vdelecroix wrote: >> >> Just to give some elements of comparison. Following the specifications >> of the standard math library in C what MPFR [3] does is that >> >> - "floor", "ceil", "round", "trunc" are the standard rounding >> functions to some integer in their mathematical definition (ie >> independently of the rounding mode) >> > Yes, I think this is an important point. We should not deviate from that. > >> >> I am fine having extra argument to floor, ceil, round, trunc in >> sage to ask for bits after the decimal point. But I would keep >> carefully the above specifications. > > > I don't think we should have an extra argument. floor, ceil, round, and trunc > are maps from floats to integers. Rounding with extra digits after the > (decimal?) point would require a change in return type. Changing > representation length of a float is a different operation than converting it > to an integer.
I agree that it's a different operation, but the fact remains that the Python built-in round() (and by extension Sage's built-in round() which wraps the Python) performs both of these operations, dependent on whether or not the second argument is given as non-zero. There's also a difference between Python 2 and 3 in the return values of round(): When rounding a float to an int like `round(2.5)` there are two differences actually: Python 2: >>> round(2.5) 3.0 >>> type(round(2.5)) <type 'float'> Python 3: >>> round(2.5) 2 >>> type(round(2.5)) <class 'int'> So first of all, Python 3 returns an int, while Python 2 returns a float, and also Python 2 always rounds half-integers up, whereas Python 3 rounds even half-integers down and odd half-integers up. On Python 3, when giving a non-zero argument for the second argument--rounding to a decimal place--it always returns a float. Also on Python 3, an object a type that implements __round__ can return any type it wants for round(obj). -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.