1

There're strange thing in pack/unpack floating point data in array. It changes one of last digits of number:

from struct import *
data = pack("<f", 1096037602)
print unpack("<f", data)
> 1096037632

What factor in implementation of floating point causes it?

Alexander Teut
  • 323
  • 1
  • 3
  • 14
  • 1
    Well, [floating point math isn't perfectly accurate](http://stackoverflow.com/questions/588004/is-floating-point-math-broken). – TigerhawkT3 Jul 29 '15 at 06:53
  • Check also http://stackoverflow.com/questions/16165488/packing-and-unpacking-binary-float-in-python – user2314737 Jul 29 '15 at 07:06

1 Answers1

3

The f format character (almost always) implies a 32-bit IEEE floating point type. The 32-bit IEEE floating point type only uses 23 bits for the mantissa. Your number requires 31 bits.

casevh
  • 11,093
  • 1
  • 24
  • 35
  • use ```d``` format to use ```double``` (in python, ```float(8)```). check this : https://docs.python.org/2/library/struct.html#format-characters – changhwan Jul 29 '15 at 07:07