11//
22// FILE: float16.cpp
33// AUTHOR: Rob Tillaart
4- // VERSION: 0.1.5
4+ // VERSION: 0.1.7
55// PURPOSE: library for Float16s for Arduino
66// URL: http://en.wikipedia.org/wiki/Half-precision_floating-point_format
77//
8- // HISTORY:
9- // 0.1.00 2015-03-10 initial version
10- // 0.1.01 2015-03-12 make base conversion separate functions
11- // 0.1.02 2015-03-14 getting rounding right
12- // 0.1.03
13- // 0.1.4 2021-11-26 setup repo to get it working again.
14- // still experimental.
15- // 0.1.5 2021-12-02 add basic math, optimize compare operators
16- // 0.1.6 2021-12-18 update library.json, license, minor edits
8+ // HISTORY: see changelog.md
179
1810
1911#include " float16.h"
@@ -27,15 +19,13 @@ float16::float16(double f)
2719 _value = f32tof16 (f);
2820}
2921
30-
3122// PRINTING
3223size_t float16::printTo (Print& p) const
3324{
3425 double d = this ->f16tof32 (_value);
3526 return p.print (d, _decimals);
3627};
3728
38-
3929double float16::toDouble () const
4030{
4131 return f16tof32 (_value);
@@ -51,7 +41,6 @@ bool float16::operator == (const float16 &f)
5141 return (_value == f._value );
5242}
5343
54-
5544bool float16::operator != (const float16 &f)
5645{
5746 return (_value != f._value );
@@ -111,46 +100,39 @@ float16 float16::operator + (const float16 &f)
111100 return float16 (this ->toDouble () + f.toDouble ());
112101}
113102
114-
115103float16 float16::operator - (const float16 &f)
116104{
117105 return float16 (this ->toDouble () - f.toDouble ());
118106}
119107
120-
121108float16 float16::operator * (const float16 &f)
122109{
123110 return float16 (this ->toDouble () * f.toDouble ());
124111}
125112
126-
127113float16 float16::operator / (const float16 &f)
128114{
129115 return float16 (this ->toDouble () / f.toDouble ());
130116}
131117
132-
133118float16& float16::operator += (const float16 &f)
134119{
135120 *this = this ->toDouble () + f.toDouble ();
136121 return *this ;
137122}
138123
139-
140124float16& float16::operator -= (const float16 &f)
141125{
142126 *this = this ->toDouble () - f.toDouble ();
143127 return *this ;
144128}
145129
146-
147130float16& float16::operator *= (const float16 &f)
148131{
149132 *this = this ->toDouble () * f.toDouble ();
150133 return *this ;
151134}
152135
153-
154136float16& float16::operator /= (const float16 &f)
155137{
156138 *this = this ->toDouble () / f.toDouble ();
@@ -170,7 +152,6 @@ int float16::sign()
170152 return 0 ;
171153}
172154
173-
174155bool float16::isZero ()
175156{
176157 return ((_value & 0x7FFF ) == 0x0000 );
@@ -231,7 +212,6 @@ float float16::f16tof32(uint16_t _value) const
231212 return sgn ? -f : f;
232213}
233214
234-
235215uint16_t float16::f32tof16 (float f) const
236216{
237217 uint32_t t = *(uint32_t *) &f;
0 commit comments