MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / float16

Class float16

libraries/float16/float16.h:18–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17
18class float16: public Printable
19{
20 public:
21 // Constructors
22 float16(void) { _value = 0x0000; };
23 float16(double f);
24 float16(const float16 &f) { _value = f._value; };
25
26 // Conversion
27 double toDouble(void) const;
28 // access the 2 byte representation.
29 uint16_t getBinary() { return _value; };
30 void setBinary(uint16_t u) { _value = u; };
31
32 // Printable
33 size_t printTo(Print& p) const;
34 void setDecimals(uint8_t d) { _decimals = d; };
35 uint8_t getDecimals() { return _decimals; };
36
37 // equalities
38 bool operator == (const float16& f);
39 bool operator != (const float16& f);
40
41 bool operator > (const float16& f);
42 bool operator >= (const float16& f);
43 bool operator < (const float16& f);
44 bool operator <= (const float16& f);
45
46 // negation
47 float16 operator - ();
48
49 // basic math
50 float16 operator + (const float16& f);
51 float16 operator - (const float16& f);
52 float16 operator * (const float16& f);
53 float16 operator / (const float16& f);
54
55 float16& operator += (const float16& f);
56 float16& operator -= (const float16& f);
57 float16& operator *= (const float16& f);
58 float16& operator /= (const float16& f);
59
60 // math helper functions
61 int sign(); // 1 = positive 0 = zero -1 = negative.
62 bool isZero();
63// bool isNaN();
64 bool isInf();
65
66
67 // CORE CONVERSION
68 // should be private but for testing...
69 float f16tof32(uint16_t) const;
70 uint16_t f32tof16(float) const;
71
72
73 private:
74 uint8_t _decimals = 4;
75 uint16_t _value;

Callers 4

operator +Method · 0.85
operator -Method · 0.85
operator *Method · 0.85
operator /Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected