Multiplying sequences with floats
Christoph Zwerschke
cito at online.de
Sat Mar 25 05:56:16 EST 2006
Caleb Hattingh wrote:
> 4.0//2 doesn't return an integer, but the equality against an integer
> still holds. I agree that integer division should return an integer,
> because using the operator at all means you expect one.
There are actually two conflicting expectations here: You're right, the
semantics of a floor operation let you expect an int, but on the other
hand, the result type of all other binary operations is the common type
into which the operands are casted before the operation, and the result
type of math.floor() is always float, even for an int operand.
The thing that I thought is a bit awkward is that
a//b * some_list
will not work if a or b is a float, even if it represents an integer and
even though the result of a//b always represents an integer.
Now there are two ways to resolve this:
a) a//b always returns an int (or long)
b) n * some_list works if n is a float representing an integer
I was actually considering solution b), not a).
By the way, solution a) has another drawback: What would you return if
a=1e200 and b=1, or a=1 and b=1e-200? Of course, a floor division would
be pretty silly with such numbers, but returning a long number with 200
digits of which most are wrong anyway somehow does not look like the
right thing to do.
-- Christoph
More information about the Python-list
mailing list