[Python-Dev] Return type of round, floor, and ceil in 2.6

Guido van Rossum guido at python.org
Sat Jan 5 17:56:02 CET 2008


On Jan 5, 2008 12:56 AM, Jeffrey Yasskin <jyasskin at gmail.com> wrote:
>
> On Jan 4, 2008 8:50 AM, Guido van Rossum <guido at python.org> wrote:
> > On Jan 4, 2008 12:13 AM, Jeffrey Yasskin <jyasskin at gmail.com> wrote:
> > > On Jan 3, 2008 10:37 AM, Guido van Rossum <guido at python.org> wrote:
> > > > > Well, as issue 1689 states, the backporting was commited by Jeffrey on
> > > > > rev 5967 [2], so this is the time to understand if we want this or
> > > > > not.
> > > >
> > > > This is a problem. Right now, in the trunk, math.float(1) returns 1,
> > > > where it should return 1.0 for compatibility with 2.5. Jeffrey, can
> > > > you fix this and similar incompatibilities you introduced?
> > >
> > > Whoops! I've committed r59707 to fix math.{floor,ceil}. Let me know if
> > > you find any other problems. ... Hmm. I've also changed the behavior
> > > of round(2.5). I'll change that back tomorrow morning.
> >
> > Looks like in Python 2.6, round(0.5) right now returns 0.0, whereas in
> > 2.5, it returns 1.0.
> >
> > I think it should return 1.0, for best compatibility with Python 2.5.
> >
> > > I haven't seen any answers to the original question. It looks like
> > > Decimal is decided by 2.5 too: return a float from everything.
> >
> > Right.
> >
> > > Rational, being a completely new type, is up to you guys, but because
> > > new support for the conversion routines seems to be rare, it's
> > > probably best to have it return floats too.
> >
> > I think the pre-3.0 rule should be: round(), math.floor(), math.ceil()
> > *always* return a float.
>
> These rollbacks, and that of pow(-1,.5)==1j are submitted as r59731.
> Keep letting me know what else I broke.

I think the consensus is against round-to-even in 3.0 -- this requires
a PEP update as well as code changes. (Sorry for having caused so much
extra work, I should have flagged this earlier.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list