-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
64-bit integer support? #162
Comments
er....I also met this problem. |
Besides living with the inaccuracy of big numbers greater 2^53 or dividing the 64bit number into two 32-bit numbers, there is also the possibility to add raw values, e.g.:
|
For the record we're still using a patched cjson.[ch] in iperf3 in the year 2024 (8 years later) because we really do need and use a 64-bit integer type for our measurements and statistics. It's too bad the core cJSON project doesn't want to implement this feature, but that's totally the project maintainers' decision (and I don't implement all the enhancement requests people send into iperf3 either). In any case we're grateful to everyone involved with cJSON for making it available to the community. |
@bmah888 Just in case you didn't know, it seems to me like your implementation supports 53 bits, but not 64-bit integers. It's not enough to replace their 32-bit int logic with 64-bit logic because lots of places push everything through a double, causing very large integers to lose precision in the lower bits. For instance, parsing makes use of 'strtod' but you'll want integer parsing when no decimal point is seen, so that you can directly get a 64-bit integer instead of retrieving it from a double, which will lose precision for integers larger than 53-bits. Same when the number is being set, it must not go through a double. The whole implementation is a bit of a brain teaser anyway with the way they handle ints and doubles, and how they compare them to figure out whether the value is a decimal or not. I'm simply replacing this with a union where I tag whether the number is a double or int. Much simpler. |
On the iperf3 project (https://github.com/esnet/iperf), we use a version of cJSON that's been modified to support 64-bit integers. It introduces a dependency on
stdint.h
but is otherwise fairly straightforward. Is there any interest in supporting this functionality in the main cJSON sources? Thanks!The text was updated successfully, but these errors were encountered: