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.rst
+31-7Lines changed: 31 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,21 +93,31 @@ Conversion/Casting:
93
93
// Direct casting is also supported
94
94
printf("(int32_t)fp1 = %i\n", (int32_t)fp1); // Prints "(int32_t)fp1 = 2"
95
95
printf("(double)fp1 = %.2f\n", (double)fp1); // Prints "(double)fp1 = 2.22"
96
-
97
96
98
-
Overflows
99
-
---------
97
+
String/Stream Support:
100
98
101
-
:code:`FpS8, FpS16, FpS32` are protected from intermediary overflows. :code:`FpS64` is not, due to the lack of a :code:`int128_t` type on most embeded platforms.
99
+
:code:`FpS` provides a :code:`ToString()` method, as well as supporting a :code:`ostream` (e.g. :code:`std::cout`).
102
100
103
-
On any 32-bit architecture, :code:`FpS64` numbers will be slower than :code:`FpS64` numbers. Use only if 32-bit numbers don't offer the range/precision required.
101
+
.. code:: cpp
102
+
103
+
FpS32 fp1(4.87, 8);
104
+
printf(fp1.ToString());
105
+
std::cout << fp1 << std::endl; // Prints 4.87
104
106
105
107
The "Fast" Fixed-Point Library (FpF)
106
108
------------------------------------
107
109
108
-
The number of fractional bits is given as a template parameter (e.g. :code:`FpF<int32_t, 12>(3.4)` will create the number 3.4 with 12 bits of decimal precision). It is not stored in the fixed-point object. This gives the fastest possible arithmetic speeds, at the expense of loosing some functionality and a tad more code space.
110
+
The number of fractional bits is given as a template parameter (e.g. :code:`FpF32<12>(3.4)` will create the number 3.4 with 12 bits of fractional precision). It is not stored in the fixed-point object. This gives the fastest possible arithmetic speeds, at the expense of loosing some functionality and a tad more code space.
111
+
112
+
Arithmetic operations between two FpF objects that have a different template parameter (fractional precision) is not directly supported. Instead, you will have to convert one of the FpF objects to the same fraction precision first, and then do the arithmetic operation.
113
+
114
+
Overflows
115
+
---------
116
+
117
+
:code:`FpS8, FpS16, FpS32` are protected from intermediary overflows. :code:`FpS64` is not, due to the lack of a :code:`int128_t` type on most embeded platforms.
118
+
119
+
On any 32-bit architecture, :code:`FpS64` numbers will be slower than :code:`FpS64` numbers. Use only if 32-bit numbers don't offer the range/precision required.
109
120
110
-
You have to be aware that when adding numbers with different Q, you have to perform the bit-shifting yourself. Also, if you want to convert a fast fixed-point number to a double, you cannot use a cast (e.g. :code:`(double)myFp32fNum` won't work, you have to use provided functions (e.g. :code:`Fix32ToDouble(myFp32fNum);`).
111
121
112
122
Benchmarking
113
123
============
@@ -116,6 +126,20 @@ This library contains a benchmarking program in :code:`benchmark/` which runs op
116
126
117
127
The benchmarking is compared to software-based float arithmetic (using the custom header SoftFloat.hpp), since most benchmarking will be run on a development computer which has an FPU which will be used if float + float was written in code. If benchmarking on a device which does not have an FPU, you should compare the fixed-point operations against the native software float arithmetic implementation instead. Software-based 32-bit float addition and multiplication are performed and compared with the equivalent fixed-point operations.
118
128
129
+
These benchmark results were computed on a x64 Ubuntu machine running inside a virtual machine. 100k samples were taken for each type of test, and the average time provided.
0 commit comments