-
Notifications
You must be signed in to change notification settings - Fork 238
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
cJSON_CreateNumber with unsigned number #38
Comments
Internally all numbers are handled as double and only floating point numbers are supported in the JSON output anyways, so there is no point in adding additional functions for signed and unsigned integers. According to RFC 7159, the internal representation of JSON numbers are implementation defined, but it's suggesting the use of 64 bit doubles. cJSON represents numbers internally as Because numbers are stored as 64 bit doubles can represent integers with up to 53 bit without any problems, if they get larger you will loose precision. |
Let me explain why this requirement? |
I wonder why these mcJSON *CreateUintArray(unsigned int * uints, size_t array_size) {
mcJSON *json_array = cJSON_CreateArray();
for (size_t i = 0; i < array_size; i++) {
mcJSON *number = cJSON_CreateNumber((double)uints[i]);
cJSON_AddItemToArray(json_array, number);
}
return json_array;
} Storing numbers as doubles is a good tradeoff for most users of cJSON I guess, so you would probably have to change it yourself. But you can add an issue here, maybe DaveGamble will do something about. See DaveGamble/cJSON#14 for reference. |
I actually did that already... I thought maybe having such function in library itself would be helpful. Now I think its based on ones requirement if they need it or not. What about long long and unsigned long long? convert to string? Another question: I see some difference in this repo and DaveGamble's repo. Which one is the latest? |
This repository didn't see any changes since Dave Gamble opened his repository. So Dave's is the latest. |
OK thanks I will look into it. |
cJSON_CreateNumber does not take care if number is unsigned. It always assume the input value is signed. There is no way to handle this. Maybe different function and different type identifier?
e.g. cJSON_SNumber and cJSON_UNumber something...
The text was updated successfully, but these errors were encountered: