[Python-Dev] Rounding float to int directly ...

Nick Maclaren nmm1 at cus.cam.ac.uk
Thu Aug 3 21:43:07 CEST 2006


Ka-Ping Yee <python-dev at zesty.ca> wrote:
>
> That's my experience as well.  In my opinion, the purpose of round()
> is most commonly described as "to make an integer".  So it should
> yield an integer.

Grrk.  No, that logic is flawed.

There are algorithms where the operation of rounding (or truncation)
is needed, but where the value may be larger than can be held in an
integer, and that is not an error.  If the only rounding or truncation
primitive converts to an integer, those algorithms are unimplementable.
You need at least one primitive that converts a float to an integer,
held as a float.

Which is independent of whether THIS particular facility should yield
an integer or float!


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679


More information about the Python-Dev mailing list