You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-5Lines changed: 11 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,10 @@ The number of bits needed under the hood for the types implemented in this libra
10
10
11
11
This library was original made for [Mozzi](https://sensorium.github.io/Mozzi/).
12
12
13
+
## Installation
14
+
15
+
FixMath can be installed from the [Arduino Library Manager](https://www.arduino.cc/reference/en/libraries/fixmath/) or manually by downloading it (button "Code/Download Zip"), uncompressing it into your "libraries" folders and renamming it "FixMath".
16
+
13
17
14
18
15
19
## Documentation
@@ -31,8 +35,10 @@ Like standard C(++) types, the fixed point numbers defined here are following so
31
35
- Fixed types can be constructed from and converted to standard C types:
32
36
-`UFix<NI,NF>(T value)` will convert the `value` to a `UFix`. If T is an integer type the final number will have a fractional part equal to zero. This can be used as a standard type, for example: `UFix<8,8> a = 15;` or `UFix<8,8> b = 200.25;`
33
37
- same for `SFix`
34
-
-`UFix<NI,NF>::fromRaw(T value)` will set the *internal* value of the `UFix`. For example `UFix<7,1>::fromRaw(16);` is actually 8
38
+
-`UFix<NI,NF>::fromRaw(T value)` will set the *internal* value of the `UFix`. For example `UFix<7,1>::fromRaw(16);` is actually 8. `T` has to be an integer type for getting the expected behavior.
35
39
- same for `SFix`
40
+
-`UFixAuto<const T N>()` will return a `UFix<NI,0>` where `NI` is automatically computed to be the smallest needed to represent the **integer**`N`. For instance: `auto a = UFixAuto<3>();` returns a `UFix<2,0>`. This is determined at compile-time hence `N` has to be a constant
41
+
-`SFixAuto<const T N>()` same for `SFix`
36
42
-`UFix<NI,NF>.toFloat()` returns the value as a `float`
37
43
- same for `SFix`
38
44
-`UFix<NI,NF>.asRaw()` returns the internal value
@@ -92,10 +98,10 @@ More specifically on the returned types of the operations between fixed point ma
92
98
-`SFix<NI,NF>.asFloat()` returns the value as a `float`
93
99
-`UFix<NI,NF>.asRaw()` returns the internal value
94
100
-`SFix<NI,NF>.asRaw()` returns the internal value
95
-
-`T.toUFraction()` returns `UFix<0,NF>` with `NF` the number of bits of `T` (`uint8_t` leads to `NF=8`bits).
96
-
-`T.toSFraction()` returns `SFix<0,NF>` with `NF` the number of bits of `T` (`int8_t` leads to `NF=7`bits).
97
-
-`T.toUInt()` returns `UFix<NI,0>` with `NI` the number of bits of `T` (`uint8_t` leads to `NI=8`bits).
98
-
-`T.toSInt()` returns `SFix<NI,>` with `NI` the number of bits of `T` (`int8_t` leads to `NI=7`bits).
101
+
-`toUFraction(T)` returns `UFix<0,NF>` with `NF` the number of bits of `T` (`uint8_t` leads to `NF=8`bits).
102
+
-`toSFraction(T)` returns `SFix<0,NF>` with `NF` the number of bits of `T` (`int8_t` leads to `NF=7`bits).
103
+
-`toUInt(T)` returns `UFix<NI,0>` with `NI` the number of bits of `T` (`uint8_t` leads to `NI=8`bits).
104
+
-`toSInt(T)` returns `SFix<NI,>` with `NI` the number of bits of `T` (`int8_t` leads to `NI=7`bits).
99
105
100
106
Note on division:
101
107
The division is not implemented. This is a deliberate choice made for two reasons:
0 commit comments