[Numpy-discussion] Custom floating point representation to IEEE 754 double

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Feb 26 06:37:06 EST 2014


On 26 February 2014 00:35, Daniele Nicolodi <daniele at grinta.net> wrote:
>
> "simpler" in my original email has to be read as involving less
> operations and thus more efficient, not simpler to understand, indeed it
> is already a simple implementation of the definition. What I would like
> to know is if there are some smart shortcuts to make the computation
> more efficient.

Sorry I misunderstood your question. How about this:

def tofloat2(data):
   data = frombytes(data)
   return float(data & 0x0fffffffffffff) * 2 ** ((data >> 52) - 35)

That's roughly how you'd do it in C except for the 2**exponent part.
I'm not sure what Cython would do with that. If exponent is positive
then you can replace that with 1<<exponent or if negative divide by
1>>-exponent.


Oscar



More information about the NumPy-Discussion mailing list