Possible Duplicate:
Why do Python's math.ceil() and math.floor() operations return floats instead of integers?
From the Python documentation of math.ceil…
math.ceil(x)
Return the ceiling of x as a float, the smallest integer value greater than or equal to x.
Why did they consider float to be better? After all, the ceil of a number is by definition an integer and operations requiring real numbers can easily convert from int to float, but not necessarily the other way around, like in the case of [0] * ceil(x).
There are floating point numbers that do not fit into an integer, so the function would fail if it returned an integer. Returning the same type as the parameter ensures the result will fit.
Edit: Even though Python can represent very large integers, this wasn’t always the case. I don’t know when long integers were introduced, but until version 2.4 they didn’t intermix with regular integers very well. I assume that
math.ceilwas around before long integers were introduced, but I don’t have enough Python history to know for sure.The conversion from floating point to integer can also hold some surprises. By keeping the
ceilfunction separate from theintconversion it’s easy to see which part is the source of the surprise.