[Numpy-discussion] float32 to float64 casting

Gökhan Sever gokhansever at gmail.com
Fri Nov 16 16:53:07 EST 2012

Thanks for the explanations.

For either case, I was expecting to get float32 as a resulting data type.
Since, float32 is large enough to contain the result. I am wondering if
changing casting rule this way, requires a lot of modification in the NumPy
code. Maybe as an alternative to the current casting mechanism?

I like the way that NumPy can convert to float64. As if these data-types
are continuation of each other. But just the conversation might happen too
early --at least in my opinion, as demonstrated in my example.

For instance comparing this example to IDL surprises me:

I16 np.float32(5555)*5e38
O16 2.7774999999999998e+42

I17 (np.float32(5555)*5e38).dtype
O17 dtype('float64')

IDL> help, 5e38*float(5555)
<Expression>    FLOAT     =           Inf

In IDL, the expression doesn't get converted to DOUBLE. Perhaps, its a
design decision.

On Thu, Nov 15, 2012 at 8:24 PM, Gökhan Sever <gokhansever at gmail.com> wrote:

> Hello,
> Could someone briefly explain why are these two operations are casting my
> float32 arrays to float64?
> I1 (np.arange(5, dtype='float32')).dtype
> O1 dtype('float32')
> I2 (100000*np.arange(5, dtype='float32')).dtype
> O2 dtype('float64')
> I3 (np.arange(5, dtype='float32')[0]).dtype
> O3 dtype('float32')
> I4 (1*np.arange(5, dtype='float32')[0]).dtype
> O4 dtype('float64')
> Thanks.
> --
> Gökhan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20121116/1dc72674/attachment.html>

More information about the NumPy-Discussion mailing list