[Numpy-discussion] ceil returns real ?

Pauli Virtanen pav@iki...
Wed Jul 28 08:39:38 CDT 2010

Wed, 28 Jul 2010 14:26:36 +0200, Mark Bakker wrote:
> I don't understand why ceil and floor return real values, while the doc
> string says:
> The ceil of the scalar `x` is the smallest integer `i`
> Wouldn't an integer make more sense?

Which integer? Only arbitrary-size integers (Python longs) are able to 
span the whole floating-point range, but we don't necessarily want


to start returning object arrays, because of efficiency reasons. 
Returning machine integers, on the other hand, can result to overflow.
There, one should (i) raise exceptions on overflow, or, (ii) return bogus 
results for overflowed values.

Numpy is here following the C tradition in defining the ceil and floor 
functions as float -> float. This leaves overflow handling on casting to 
the user.

Python can redefine its floor and ceil since arbitrary-size integers are 
first-class citizens in the Python world.  This sits less well with 
Numpy: (i) Numpy tries to sit close to the hardware, and (ii) strictly 
speaking, arbitrary-size integers cannot be a Numpy scalar type since 
they by definition are not fixed-size in memory.

Pauli Virtanen

More information about the NumPy-Discussion mailing list