summaryrefslogtreecommitdiffstats
path: root/examples/using_double_on_avr/double_conversion.h
blob: 62b6a8ae8d33720076641ce5c392602c80b77f16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 <stdint.h>

/* 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