[Python-Dev] trunc() (original) (raw)

Jared Flatow jflatow at northwestern.edu
Fri Jan 25 20:47:19 CET 2008


On Jan 25, 2008, at 1:22 PM, Raymond Hettinger wrote:

I wouldn't fret about this too much. Intrepreting int(f) as meaning truncate has a long history in many programming languages. It is a specious argument int(f) is ambiguous. No one thinks it means ceil(f).

Not that I think my opinion will have any weight in this discussion,
but I'd agree that int has a long history not likely to be
misinterpreted when applied to real numbers.

Quoting from Graham, Knuth and Patashnik "Concrete Mathematics...2nd
edition" page 67:

"We start by covering the floor (greatest integer) and ceiling (least
integer) functions, which are defined for all real x...

...some pocket calculators have an INT function, defined as floor(x)
when x is positive and ceil(x) when x is negative. The designers of
these calculators probably wanted their INT function to satisfy the
identity INT(-X) = -INT(X). But we'll stick to our floor and ceiling
functions, because they have even nicer properties than this."

jared



More information about the Python-Dev mailing list