Skip to content

Conversation

@mutatrum
Copy link
Collaborator

@mutatrum mutatrum commented Nov 17, 2025

cJSON has no support for floats. So when cJSON_CreateNumber or cJSON_AddNumberToObject is called with a float, it's upcast to double. However, this introduces precision artifacts. This PR adds two helper methods that make sure the upcast double is limited to 7 decimals, which limits superfluous digits. Upside is smaller JSON, especially for the statistics.

An example:

Before: "power": 17.9117431640625,

After: "power": 18.4124756,

This is done for all floats. In some cases it cases very annoying artifacts, f.e. the float value 0.1 ends up as 0.10000000149011612 in the JSON.

I'm not super happy with the code, as it's easy to forget about this with new fields, but not sure how to make that better.

@github-actions
Copy link

Test Results

19 tests  ±0   19 ✅ ±0   0s ⏱️ ±0s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 4fd98f2. ± Comparison against base commit 05e5fc0.

@mutatrum mutatrum added enhancement New feature or request api change Changes the REST API labels Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the REST API enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant