A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-August/067867.html below:

[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers) [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)Greg Ewing greg.ewing at canterbury.ac.nz
Tue Aug 1 02:30:09 CEST 2006
Raymond Hettinger wrote:

> I think this would harm more than it would help.  It more confusing to 
> have several rounding-thingies to choose from than it is have an 
> explicit two-step.

But is it more confusing enough to be worth forcing
everyone to pay two function calls instead of one
in the most common case?

If I'm right that rounding-to-int is much more
commonly needed than rounding-to-float, the least
confusing thing would be for the builtin round()
to return an int, and have something somewhere
else, such as math.fround(), for round-to-float.

> BTW,  I thought the traditional idiom (for positive numbers) was:  
> int(x+.5)

It's the "for positive numbers" that's the problem
there. Most of my uses for round() involve graphics
coordinates, which I can't be sure won't be negative.
It's not immediately obvious what this will do with
negative numbers. It's not even immediately obvious
that it's doing round-to-nearest-integer unless
you're familiar with the idiom. A single well-named
function would be much more explicit.

--
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4