Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
Makefile | D | 22-Nov-2023 | 594 | 25 | 14 | |
README.txt | D | 22-Nov-2023 | 1 KiB | 26 | 18 | |
decode_double.c | D | 22-Nov-2023 | 765 | 34 | 24 | |
double_conversion.c | D | 22-Nov-2023 | 2.6 KiB | 124 | 87 | |
double_conversion.h | D | 22-Nov-2023 | 749 | 27 | 6 | |
doubleproto.proto | D | 23-Nov-2023 | 358 | 16 | 12 | |
encode_double.c | D | 22-Nov-2023 | 599 | 26 | 16 | |
test_conversions.c | D | 22-Nov-2023 | 1.6 KiB | 57 | 44 |
README.txt
1Nanopb example "using_double_on_avr" 2==================================== 3 4Some processors/compilers, such as AVR-GCC, do not support the double 5datatype. Instead, they have sizeof(double) == 4. Because protocol 6binary format uses the double encoding directly, this causes trouble 7if the protocol in .proto requires double fields. 8 9This directory contains a solution to this problem. It uses uint64_t 10to store the raw wire values, because its size is correct on all 11platforms. The file double_conversion.c provides functions that 12convert these values to/from floats, without relying on compiler 13support. 14 15To use this method, you need to make some modifications to your code: 16 171) Change all 'double' fields into 'fixed64' in the .proto. 18 192) Whenever writing to a 'double' field, use float_to_double(). 20 213) Whenever reading a 'double' field, use double_to_float(). 22 23The conversion routines are as accurate as the float datatype can 24be. Furthermore, they should handle all special values (NaN, inf, denormalized 25numbers) correctly. There are testcases in test_conversions.c. 26