From f47410ea4b8ae43e19facd378be4cf1073e1813b Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 13 Sep 2013 12:59:31 +0300 Subject: Move examples into subfolders, add READMEs --- examples/using_double_on_avr/double_conversion.h | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/using_double_on_avr/double_conversion.h (limited to 'examples/using_double_on_avr/double_conversion.h') diff --git a/examples/using_double_on_avr/double_conversion.h b/examples/using_double_on_avr/double_conversion.h new file mode 100644 index 0000000..62b6a8a --- /dev/null +++ b/examples/using_double_on_avr/double_conversion.h @@ -0,0 +1,26 @@ +/* AVR-GCC does not have real double datatype. Instead its double + * is equal to float, i.e. 32 bit value. If you need to communicate + * with other systems that use double in their .proto files, you + * need to do some conversion. + * + * These functions use bitwise operations to mangle floats into doubles + * and then store them in uint64_t datatype. + */ + +#ifndef DOUBLE_CONVERSION +#define DOUBLE_CONVERSION + +#include + +/* Convert native 4-byte float into a 8-byte double. */ +extern uint64_t float_to_double(float value); + +/* Convert 8-byte double into native 4-byte float. + * Values are rounded to nearest, 0.5 away from zero. + * Overflowing values are converted to Inf or -Inf. + */ +extern float double_to_float(uint64_t value); + + +#endif + -- cgit 1.2.3-korg