[Numpy-discussion] Re: Why floor and ceil change the type of the array?

Robert Kern robert.kern at gmail.com
Wed Feb 22 23:06:14 EST 2006

Sasha wrote:
> On 2/23/06, Robert Kern <robert.kern at gmail.com> wrote:

>>AFAICT, the story goes like this: sin() has two implementations, one for
>>single-precision floats and one for doubles. The ufunc machinery sees the int16
>>and picks single-precision as the smallest type of the two that can fit an int16
>>without losing precision. Naturally, you probably want the function to operate
>>in higher precision, but that's not really information that the ufunc machinery
>>knows about.
> According to your theory long (i8) integers should cast to long doubles, but
> dtype('<f8')

Out of curiosity, what does array(0, dtype=longdouble).dtype give you on your

The relevant function here is select_types() in ufuncobject.c.

> Given that python's floating point object is a double, I think it
> would be natural to cast integer arguments to double for all sizes.  I
> would also think that in choosing the precision for a function it is
> also important that the output fits into data type.  I find the
> following unfortunate:
> 5.2214696897641443e+173
> inf

I prefer consistent, predictable rules that are dependent on the input, not the
output. If I want my outputs to be double precision, I will cast appopriately.

Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the NumPy-Discussion mailing list