supla-device
Loading...
Searching...
No Matches
IEEE754tools.h
1// Copyright (C) TBD
2//
3// FILE: IEEE754tools.h
4// AUTHOR: Rob Tillaart
5// VERSION: 0.1.00
6// PURPOSE: IEEE754 tools
7//
8// http://playground.arduino.cc//Main/IEEE754tools
9//
10// Released to the public domain
11// not tested, use with care
12//
13
14#ifndef SRC_SUPLA_IEEE754TOOLS_H_
15#define SRC_SUPLA_IEEE754TOOLS_H_
16
17// IEEE754 float layout;
18struct IEEEfloat {
19 uint32_t m:23;
20 uint8_t e:8;
21 uint8_t s:1;
22};
23
24// for packing and unpacking a float
25typedef union _FLOATCONV {
26 IEEEfloat p;
27 float f;
28 uint8_t b[4];
30
31// Arduino UNO double layout:
32// the UNO has no 64 bit double, it is only able to map 23 bits of the mantisse
33// a filler is added.
34struct _DBL {
35 uint32_t filler:29;
36 uint32_t m:23;
37 uint16_t e:11;
38 uint8_t s:1;
39};
40
41
42// for packing and unpacking a double
43typedef union _DBLCONV {
44 // IEEEdouble p;
45 _DBL p;
46 double d; // !! is a 32bit float for UNO.
47 uint8_t b[8];
48} _DBLCONV;
49
50//
51// converts a float to a packed array of 8 bytes representing a 64 bit double
52// restriction exponent and mantisse.
53//
54// float; array of 8 bytes; LSBFIRST; MSBFIRST
55//
56// void float2DoublePacked(float number, byte* bar, int byteOrder=LSBFIRST);
57
58
59#endif // SRC_SUPLA_IEEE754TOOLS_H_
Definition IEEE754tools.h:18
Definition IEEE754tools.h:34
Definition IEEE754tools.h:43
Definition IEEE754tools.h:25