[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
>
>>>>sin(array(0,'i8')).dtype
>
> dtype('<f8')
Out of curiosity, what does array(0, dtype=longdouble).dtype give you on your
platform?
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:
>
>>>>exp(400)
>
> 5.2214696897641443e+173
>
>>>>exp(array(400,'h'))
>
> 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