No subject
Tue Oct 14 00:29:20 CEST 2008
walk up the 'Number type tower', at least as far as function arguments
are involved (operators are a different mess). The number tower is:
int -> long -> float -> complex
So, putting ints where floats are expected is always ok. This is part of
what I think is 'intended design'. The reverse not true, though. Most
python stuff don't react well to putting floats where ints are expected.
I think it's also ok to accept a longint where ints are expected if you
can convert it without loss. That's what sequence indexing (in Python
2.1) and range() do.
Speaking of which, I think range() is an explicit exception because of
it's semantics. It tries to convert all numbers it gets to int.
I mentioned operators being a different mess mostly because of the
division operator, but this is changing in the direction of always
allowing you to go up the number tower.
So, to sumarize:
* you can go up the number tower.
* longs can be used where ints are expected if int(yourlong) doesn't raise an
exception
* you can break the above rules if it makes sense and you really want
to :-)
Cheers, Leo
--
Ideas don't stay in some minds very long because they don't like
solitary confinement.
More information about the Cplusplus-sig
mailing list