On Jan 25, 2008 12:45 PM, Facundo Batista <facundobatista@gmail.com> wrote:
Mmm... no. int() is a builtin way to transform the builtin data type float into the builtin data type float [sic].
There's no "correct" way for a float to become an integer, but in the math module you have several ways to do it (floor, ceil, round, trunc, choose the one that you want, but you're "notified" <wink/2> that there're different ways to do it).
In keeping with this theme, why not define int() for floats (and other real types) as def __int__(n, method=math.trunc) or something similar, so that, by default, int() provides the same functionality as before (or whatever is decided to be preferred, I'm making no judgements on that end), but has a way --- by passing a different function --- of changing the way it rounds? The other (probably preferred) option, I suppose, would be to provide a few constants (float.FLOOR_METHOD et al.) instead of passing an arbitrary function (which, of course, makes me a bit uncomfortable). -- Cheers, Leif