[Python-Dev] trunc()

Terry Reedy tjreedy at udel.edu
Mon Jan 28 00:37:19 CET 2008


"Michael Urman" <murman at gmail.com> wrote in message 
news:dcbbbb410801271039s4bf2b669ob919c53e43cb0cea at mail.gmail.com...

|  2) The semantics of int() are fuzzy; even non-numeric types
| (strings) are handled

One could just as well say that the semantics of float() are fuzzy since it 
also handles strings.

The actual claim seems to have been that the semantics of int(<float>) 
itself is fuzzy.  This in turn seems to be based one of two ideas (I am not 
sure which)
a. 'int' might either mean to some people 'some int associated with the 
float input' rather than the more precise 'the integer part of the float 
input', or
b. that some people might think the latter means the same as the former.

Possibility a is easy taken care of by documentation, especially when the 
behavior is what people expect.  Possibility b conflicts with what I 
believe to be both the plain English meaning of 'integer part' and what I 
believe Americans, at least, learn in elementary school.

Moreover, I challenge the notion that 'truncate' is unambiguous.  It simply 
means to cut off, without specifying how much.  '3.141' is pi truncated to 
3 decimal places.  Indeed, it would not be unreasonable to expect trunc() 
to have a second parameter specifying where to cut.

For one data point, I asked my bright 13-year-old for the 'integer part' of 
3.1, 3.9, -3.1, and -3.9 and got the expected 3,3,-3,-3 (as with int()). 
But asking 'truncate' the same numbers or even 'truncate toward zero' got a 
blank stare, which did not surprise me too much as it is not a common 
(American) English word.

tjr





More information about the Python-Dev mailing list