-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Float issue with py-ubjson file #25
Comments
I looked into this, it looks like py-ubjson saved the floating point (double in this case) in the Big-endian format, even the host machine is a little-endian machine. To show this, you can run this in matlab:
and then dump the hex data from the output file:
in comparison, the hex dump for the py-ubjson output is shown here:
the big-endian double is evident in the first half of the second row. The UBJSON specs Draft-12 is not exactly clear on the byte orders for floats. It does say explicitly that all integer values are saved in the Big-endian format, but for floats (d and D), the only thing mentioned was IEEE 754 compliant. http://ubjson.org/type-reference/value-types/#numeric-byte-order-endianness However, AFAIK, IEEE 754 does not specify Endianness. UBJSON spec does say "all numeric values be written in Big-Endian order" in this document: but it is very brief and non-specific. The only specific specs are the big-endian integers. I am going to get clarifications from ubjson's maintainer. If d/D are indeed meant to saved in the big-endian format, then I will remove the "id<=5" from line https://github.com/fangq/jsonlab/blob/master/loadubjson.m#L317. |
Hi,
I am trying to import in Matlab a ubj file generated with py-ubjson.
Everything works fine, except for float?
Any idea why?
in python:
import ubjson
d = {'string': 'test', 'int': 123456,'pi':3.1415}
ubjson.dump(d,open('test.ubj','w'))
in Matlab:
s = loadubjson('test.ubj'')
s =
int: 123456
pi: 1.0965e+227
string: [116 101 115 116]
The text was updated successfully, but these errors were encountered: