this is a sample for mbed(LPC1768)
serialization_lib/double_conversion.h@0:3163adfd2cf1, 2015-11-19 (annotated)
- Committer:
- 1
- Date:
- Thu Nov 19 10:17:55 2015 +0800
- Revision:
- 0:3163adfd2cf1
????????????????????????
1.callback
2.thread
3.auto-connect,time-up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
1 | 0:3163adfd2cf1 | 1 | /* AVR-GCC does not have real double datatype. Instead its double |
1 | 0:3163adfd2cf1 | 2 | * is equal to float, i.e. 32 bit value. If you need to communicate |
1 | 0:3163adfd2cf1 | 3 | * with other systems that use double in their .proto files, you |
1 | 0:3163adfd2cf1 | 4 | * need to do some conversion. |
1 | 0:3163adfd2cf1 | 5 | * |
1 | 0:3163adfd2cf1 | 6 | * These functions use bitwise operations to mangle floats into doubles |
1 | 0:3163adfd2cf1 | 7 | * and then store them in uint64_t datatype. |
1 | 0:3163adfd2cf1 | 8 | */ |
1 | 0:3163adfd2cf1 | 9 | |
1 | 0:3163adfd2cf1 | 10 | #ifndef DOUBLE_CONVERSION |
1 | 0:3163adfd2cf1 | 11 | #define DOUBLE_CONVERSION |
1 | 0:3163adfd2cf1 | 12 | |
1 | 0:3163adfd2cf1 | 13 | #include <stdint.h> |
1 | 0:3163adfd2cf1 | 14 | |
1 | 0:3163adfd2cf1 | 15 | /* Convert native 4-byte float into a 8-byte double. */ |
1 | 0:3163adfd2cf1 | 16 | extern uint64_t float_to_double(float value); |
1 | 0:3163adfd2cf1 | 17 | |
1 | 0:3163adfd2cf1 | 18 | /* Convert 8-byte double into native 4-byte float. |
1 | 0:3163adfd2cf1 | 19 | * Values are rounded to nearest, 0.5 away from zero. |
1 | 0:3163adfd2cf1 | 20 | * Overflowing values are converted to Inf or -Inf. |
1 | 0:3163adfd2cf1 | 21 | */ |
1 | 0:3163adfd2cf1 | 22 | extern float double_to_float(uint64_t value); |
1 | 0:3163adfd2cf1 | 23 | |
1 | 0:3163adfd2cf1 | 24 | |
1 | 0:3163adfd2cf1 | 25 | #endif |
1 | 0:3163adfd2cf1 | 26 |