Repository navigation
Commit d39140b
Round scaled floats before serializing to integers
Casting a scaled float directly to an integer truncates values such as
0.59 at scale 100 to 58. This causes configuration read-backs and repeated
save/read cycles to lose precision.
Use lroundf in buffer_append_float16 and buffer_append_float32 in all
three buffer.c implementations, covering the package and example copies.
This matches VESC Tool's nearest-integer rounding for either sign.
Validated every signed 16-bit encoding at scales 1, 10, 100, 1000, 10000
and 100000 through ten round trips, plus larger 32-bit samples and signed
halfway cases, against each copy with a temporary host harness. All pass;
each original implementation fails the round-trip check.1 parent fd0708b commit d39140b
3 files changed
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
0 commit comments