[Numpy-discussion] IEEE floating point arithmetics

Charles R Harris charlesr.harris at gmail.com
Sat May 26 14:55:54 EDT 2007


On 5/26/07, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
>
>
> On 5/26/07, lorenzo bolla <lbolla at gmail.com> wrote:
> >
> > Hi all.
> > I have to work with floating point arithmetics and I found a module
> > called "double module" (http://symptotic.com/mj/double/public/double-module.html )
> > that does what I'd like. Basically, I would like to find the nearest smaller
> > and bigger floating point numbers, given a "real" real number (the function
> > doubleToLongBits<http://symptotic.com/mj/double/public/double-module.html#doubleToLongBits> can
> > be used to do just that.).
> > Is there something similar in numpy?
> > In other words: is there a way, in numpy, to convert a floating point
> > number to its binary representation and back?
> >
>
> I don't quite understand what problem you are trying to solve. Python
> doubles are, I believe, the same as the C doubles supported by the hardware,
> i.e., IEEE754 doubles. Correct me if I am wrong. If you just what the same
> bits in a long, do
>
> In [5]: float64(3.0).view(int64)
> Out[5]: 4613937818241073152
>
> To see it in hex:
>
> In [6]: hex(float64(3.0).view(int64))
> Out[6]: '0x4008000000000000L'
>
> Note that you need to keep endianess in mind to interpret the results.
>

In particular, my machine is little endian, meaning that the low order bits
are stored first. It seems that Hex always prints with the high order bits
first, so on my machine the bits are in the reverse order of the hex
display.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070526/5ee53e8d/attachment.html>


More information about the NumPy-Discussion mailing list