AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches
fp_def.h
Go to the documentation of this file.
1/*************************************************************************/
37#ifndef FP_DEF_H
38#define FP_DEF_H
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*!***************************************************************************
44 * @defgroup argus_fp Fixed Point Math
45 * @ingroup argus_util
46 *
47 * @brief A basic math library for fixed point number in the Qx.y fomat.
48 *
49 * @details This module contains common fixed point type definitions as
50 * well as some basic math algorithms. All types are based on
51 * integer types. The number are defined with the Q number format.
52 *
53 * - For a description of the Q number format refer to:
54 * https://en.wikipedia.org/wiki/Q_(number_format)
55 * - Another resource for fixed point math in C might be found at
56 * http://www.eetimes.com/author.asp?section_id=36&doc_id=1287491
57 * .
58 *
59 * @warning This definitions are not portable and work only with
60 * little-endian systems!
61 *
62 * @addtogroup argus_fp
63 * @{
64 *****************************************************************************/
65
66#include <stdint.h>
67
68/*******************************************************************************
69 ***** Unsigned 8-Bit Values ***********************************************
70 ******************************************************************************/
71
72/*******************************************************************************
73 ***** UQ6.2
74 ******************************************************************************/
75/*!***************************************************************************
76 * @brief Unsigned fixed point number: UQ6.2
77 * @details An unsigned fixed point number format based on the 8-bit unsigned
78 * integer type with 6 integer and 2 fractional bits.
79 * - Range: 0 .. 63.75
80 * - Granularity: 0.25
81 *****************************************************************************/
82typedef uint8_t uq6_2_t;
83
85#define UQ6_2_MAX ((uq6_2_t)UINT8_MAX)
86
88#define UQ6_2_ONE ((uq6_2_t)(1U<<2U))
89
90
91
92/*******************************************************************************
93 ***** UQ4.4
94 ******************************************************************************/
95/*!***************************************************************************
96 * @brief Unsigned fixed point number: UQ4.4
97 * @details An unsigned fixed point number format based on the 8-bit unsigned
98 * integer type with 4 integer and 4 fractional bits.
99 * - Range: 0 .. 15.9375
100 * - Granularity: 0.0625
101 *****************************************************************************/
102typedef uint8_t uq4_4_t;
103
105#define UQ4_4_MAX ((uq4_4_t)UINT8_MAX)
106
108#define UQ4_4_ONE ((uq4_4_t)(1U<<4U))
109
110
111
112/*******************************************************************************
113 ***** UQ2.6
114 ******************************************************************************/
115/*!***************************************************************************
116 * @brief Unsigned fixed point number: UQ2.6
117 * @details An unsigned fixed point number format based on the 8-bit unsigned
118 * integer type with 2 integer and 6 fractional bits.
119 * - Range: 0 .. 3.984375
120 * - Granularity: 0.015625
121 *****************************************************************************/
122typedef uint8_t uq2_6_t;
123
125#define UQ2_6_MAX ((uq2_6_t)UINT8_MAX)
126
128#define UQ2_6_ONE ((uq2_6_t)(1U<<6U))
129
130
131
132/*******************************************************************************
133 ***** UQ1.7
134 ******************************************************************************/
135/*!***************************************************************************
136 * @brief Unsigned fixed point number: UQ1.7
137 * @details An unsigned fixed point number format based on the 8-bit unsigned
138 * integer type with 1 integer and 7 fractional bits.
139 * - Range: 0 .. 1.9921875
140 * - Granularity: 0.0078125
141 *****************************************************************************/
142typedef uint8_t uq1_7_t;
143
145#define UQ1_7_MAX ((uq1_7_t)UINT8_MAX)
146
148#define UQ1_7_ONE ((uq1_7_t)(1U<<7U))
149
150
151
152/*******************************************************************************
153 ***** UQ0.8
154 ******************************************************************************/
155/*!***************************************************************************
156 * @brief Unsigned fixed point number: UQ0.8
157 * @details An unsigned fixed point number format based on the 8-bit unsigned
158 * integer type with 1 integer and 7 fractional bits.
159 * - Range: 0 .. 0.99609375
160 * - Granularity: 0.00390625
161 *****************************************************************************/
162typedef uint8_t uq0_8_t;
163
165#define UQ0_8_MAX ((uq0_8_t)UINT8_MAX)
166
167
168
169/*******************************************************************************
170 ***** Signed 8-Bit Values *************************************************
171 ******************************************************************************/
172
173/*******************************************************************************
174 ***** Q3.4
175 ******************************************************************************/
176/*!***************************************************************************
177 * @brief Signed fixed point number: Q3.4
178 * @details A signed fixed point number format based on the 8-bit signed
179 * integer type with 3 integer and 4 fractional bits.
180 * - Range: -8 ... 7.9375
181 * - Granularity: 0.0625
182 *****************************************************************************/
183typedef int8_t q3_4_t;
184
186#define Q3_4_MIN ((q3_4_t)INT8_MIN)
187
189#define Q3_4_MAX ((q3_4_t)INT8_MAX)
190
192#define UQ3_4_ONE ((q3_4_t)(1 << 4))
193
194
195/*******************************************************************************
196 ***** Q1.6
197 ******************************************************************************/
198/*!***************************************************************************
199 * @brief Signed fixed point number: Q1.6
200 * @details A signed fixed point number format based on the 8-bit signed
201 * integer type with 1 integer and 6 fractional bits.
202 * - Range: -2 ... 1.984375
203 * - Granularity: 0.015625
204 *****************************************************************************/
205typedef int8_t q1_6_t;
206
208#define Q1_6_MIN ((q1_6_t)INT8_MIN)
209
211#define Q1_6_MAX ((q1_6_t)INT8_MAX)
212
214#define UQ1_6_ONE ((q1_6_t)(1 << 4))
215
216
217/*******************************************************************************
218 ***** Unsigned 16-Bit Values **********************************************
219 ******************************************************************************/
220
221/*******************************************************************************
222 ***** UQ12.4
223 ******************************************************************************/
224/*!***************************************************************************
225 * @brief Unsigned fixed point number: UQ12.4
226 * @details An unsigned fixed point number format based on the 16-bit unsigned
227 * integer type with 12 integer and 4 fractional bits.
228 * - Range: 0 ... 4095.9375
229 * - Granularity: 0.0625
230 *****************************************************************************/
231typedef uint16_t uq12_4_t;
232
234#define UQ12_4_MAX ((uq12_4_t)UINT16_MAX)
235
237#define UQ12_4_ONE ((uq12_4_t)(1U<<4U))
238
239
240
241/*******************************************************************************
242 ***** UQ10.6
243 ******************************************************************************/
244/*!***************************************************************************
245 * @brief Unsigned fixed point number: UQ10.6
246 * @details An unsigned fixed point number format based on the 16-bit unsigned
247 * integer type with 10 integer and 6 fractional bits.
248 * - Range: 0 ... 1023.984375
249 * - Granularity: 0.015625
250 *****************************************************************************/
251typedef uint16_t uq10_6_t;
252
254#define UQ10_6_MAX ((uq10_6_t)UINT16_MAX)
255
257#define UQ10_6_ONE ((uq10_6_t)(1U << 6U))
258
259
260
261/*******************************************************************************
262 ***** UQ1.15
263 ******************************************************************************/
264/*!***************************************************************************
265 * @brief Unsigned fixed point number: UQ1.15
266 * @details An unsigned fixed point number format based on the 16-bit unsigned
267 * integer type with 1 integer and 15 fractional bits.
268 * - Range: 0 .. 1.999969
269 * - Granularity: 0.000031
270 *****************************************************************************/
271typedef uint16_t uq1_15_t;
272
274#define UQ1_15_MAX ((uq1_15_t)UINT16_MAX)
275
277#define UQ1_15_ONE ((uq1_15_t)(1U << 15U))
278
279
280
281/*******************************************************************************
282 ***** UQ0.16
283 ******************************************************************************/
284/*!***************************************************************************
285 * @brief Unsigned fixed point number: UQ0.16
286 * @details An unsigned fixed point number format based on the 16-bit unsigned
287 * integer type with 0 integer and 16 fractional bits.
288 * - Range: 0 .. 0.9999847412109375
289 * - Granularity: 1.52587890625e-5
290 *****************************************************************************/
291typedef uint16_t uq0_16_t;
292
294#define UQ0_16_MAX ((uq0_16_t)UINT16_MAX)
295
296
297
298/*******************************************************************************
299 ***** Signed 16-Bit Values ************************************************
300 ******************************************************************************/
301
302/*******************************************************************************
303 ***** Q11.4
304 ******************************************************************************/
305/*!***************************************************************************
306 * @brief Signed fixed point number: Q11.4
307 * @details A signed fixed point number format based on the 16-bit signed
308 * integer type with 11 integer and 4 fractional bits.
309 * - Range: -2048 ... 2047.9375
310 * - Granularity: 0.0625
311 *****************************************************************************/
312typedef int16_t q11_4_t;
313
315#define Q11_4_MIN ((q11_4_t)INT16_MIN)
316
318#define Q11_4_MAX ((q11_4_t)INT16_MAX)
319
321#define Q11_4_ONE ((q11_4_t)(1 << 4))
322
323
324
325/*******************************************************************************
326 ***** Q7.8
327 ******************************************************************************/
328/*!***************************************************************************
329 * @brief Signed fixed point number: Q7.8
330 * @details A signed fixed point number format based on the 16-bit signed
331 * integer type with 7 integer and 8 fractional bits.
332 * - Range: -128 .. 127.99609375
333 * - Granularity: 0.00390625
334 *****************************************************************************/
335typedef int16_t q7_8_t;
336
338#define Q7_8_MIN ((q7_8_t)INT16_MIN)
339
341#define Q7_8_MAX ((q7_8_t)INT16_MAX)
342
344#define Q7_8_ONE ((q7_8_t)(1 << 8))
345
346
347
348/*******************************************************************************
349 ***** Q3.12
350 ******************************************************************************/
351/*!***************************************************************************
352 * @brief Signed fixed point number: Q3.12
353 * @details A signed fixed point number format based on the 16-bit integer
354 * type with 3 integer and 12 fractional bits.
355 * - Range: -8 .. 7.99975586
356 * - Granularity: 0.00024414
357 *****************************************************************************/
358typedef int16_t q3_12_t;
359
361#define Q3_12_MIN ((q3_12_t)INT16_MIN)
362
364#define Q3_12_MAX ((q3_12_t)INT16_MAX)
365
367#define Q3_12_ONE ((q3_12_t)(1 << 12))
368
369
370
371/*******************************************************************************
372 ***** Q0.15
373 ******************************************************************************/
374/*!***************************************************************************
375 * @brief Signed fixed point number: Q0.15
376 * @details A signed fixed point number format based on the 16-bit integer
377 * type with 0 integer and 15 fractional bits.
378 * - Range: -1 .. 0.999969482
379 * - Granularity: 0.000030518
380 *****************************************************************************/
381typedef int16_t q0_15_t;
382
384#define Q0_15_MIN ((q0_15_t)INT16_MIN)
385
387#define Q0_15_MAX ((q0_15_t)INT16_MAX)
388
389
390
391/*******************************************************************************
392 ***** Unsigned 32-Bit Values **********************************************
393 ******************************************************************************/
394
395/*******************************************************************************
396 ***** UQ28.4
397 ******************************************************************************/
398/*!***************************************************************************
399 * @brief Unsigned fixed point number: UQ28.4
400 * @details An unsigned fixed point number format based on the 32-bit unsigned
401 * integer type with 28 integer and 4 fractional bits.
402 * - Range: 0 ... 268435455.9375
403 * - Granularity: 0.0625
404 *****************************************************************************/
405typedef uint32_t uq28_4_t;
406
408#define UQ28_4_MAX ((uq28_4_t)UINT32_MAX)
409
411#define UQ28_4_ONE ((uq28_4_t)(1U<<4U))
412
413
414
415/*******************************************************************************
416 ***** UQ16.16
417 ******************************************************************************/
418/*!***************************************************************************
419 * @brief Unsigned fixed point number: UQ16.16
420 * @details An unsigned fixed point number format based on the 32-bit unsigned
421 * integer type with 16 integer and 16 fractional bits.
422 * - Range: 0 ... 65535.999984741
423 * - Granularity: 0.000015259
424 *****************************************************************************/
425typedef uint32_t uq16_16_t;
426
428#define UQ16_16_MAX ((uq16_16_t)UINT32_MAX)
429
431#define UQ16_16_ONE ((uq16_16_t)(1U << 16U))
432
434#define UQ16_16_E (0x2B7E1U)
435
436
437
438/*******************************************************************************
439 ***** UQ10.22
440 ******************************************************************************/
441/*!***************************************************************************
442 * @brief Unsigned fixed point number: UQ10.22
443 * @details An unsigned fixed point number format based on the 32-bit unsigned
444 * integer type with 10 integer and 22 fractional bits.
445 * - Range: 0 ... 1023.99999976158
446 * - Granularity: 2.38418579101562E-07
447 *****************************************************************************/
448typedef uint32_t uq10_22_t;
449
451#define UQ10_22_MAX ((uq10_22_t)UINT32_MAX)
452
454#define UQ10_22_ONE ((uq10_22_t)(1U << 22U))
455
456
457
458/*******************************************************************************
459 ***** Signed 32-Bit Values ************************************************
460 ******************************************************************************/
461
462/*******************************************************************************
463 ***** Q27.4
464 ******************************************************************************/
465/*!***************************************************************************
466 * @brief Signed fixed point number: Q27.4
467 * @details A signed fixed point number format based on the 32-bit signed
468 * integer type with 27 integer and 4 fractional bits.
469 * - Range: -134217728 ... 134217727.9375
470 * - Granularity: 0.0625
471 *****************************************************************************/
472typedef int32_t q27_4_t;
473
475#define Q27_4_MIN ((q27_4_t)INT32_MIN)
476
478#define Q27_4_MAX ((q27_4_t)INT32_MAX)
479
481#define UQ27_4_ONE ((q27_4_t)(1 << 4))
482
483
484
485/*******************************************************************************
486 ***** Q16.15
487 ******************************************************************************/
488/*!***************************************************************************
489 * @brief Signed fixed point number: Q16.15
490 * @details A signed fixed point number format based on the 32-bit integer
491 * type with 16 integer and 15 fractional bits.
492 * - Range: -65536 .. 65536.999969482
493 * - Granularity: 0.000030518
494 *****************************************************************************/
495typedef int32_t q16_15_t;
496
498#define Q16_15_MIN ((q16_15_t)INT32_MIN)
499
501#define Q16_15_MAX ((q16_15_t)INT32_MAX)
502
503
504
505/*******************************************************************************
506 ***** Q15.16
507 ******************************************************************************/
508/*!***************************************************************************
509 * @brief Signed fixed point number: Q15.16
510 * @details A signed fixed point number format based on the 32-bit integer
511 * type with 15 integer and 16 fractional bits.
512 * - Range: -32768 .. 32767.99998
513 * - Granularity: 1.52588E-05
514 *****************************************************************************/
515typedef int32_t q15_16_t;
516
518#define Q15_16_MIN ((q15_16_t)INT32_MIN)
519
521#define Q15_16_MAX ((q15_16_t)INT32_MAX)
522
524#define Q15_16_ONE ((q15_16_t)(1 << 16))
525
526
527
528/*******************************************************************************
529 ***** Q9.22
530 ******************************************************************************/
531/*!***************************************************************************
532 * @brief Signed fixed point number: Q9.22
533 * @details A signed fixed point number format based on the 32-bit integer
534 * type with 9 integer and 22 fractional bits.
535 * - Range: -512 ... 511.9999998
536 * - Granularity: 2.38418579101562E-07
537 *****************************************************************************/
538typedef int32_t q9_22_t;
539
541#define Q9_22_MIN ((q9_22_t)INT32_MIN)
542
544#define Q9_22_MAX ((q9_22_t)INT32_MAX)
545
547#define Q9_22_ONE ((q9_22_t)(1 << 22))
548
549
550
552#ifdef __cplusplus
553} // extern "C"
554#endif
555#endif /* FP_DEF_H */
int8_t q1_6_t
Signed fixed point number: Q1.6.
Definition fp_def.h:205
uint8_t uq1_7_t
Unsigned fixed point number: UQ1.7.
Definition fp_def.h:142
int16_t q3_12_t
Signed fixed point number: Q3.12.
Definition fp_def.h:358
int8_t q3_4_t
Signed fixed point number: Q3.4.
Definition fp_def.h:183
uint8_t uq6_2_t
Unsigned fixed point number: UQ6.2.
Definition fp_def.h:82
uint16_t uq0_16_t
Unsigned fixed point number: UQ0.16.
Definition fp_def.h:291
uint32_t uq16_16_t
Unsigned fixed point number: UQ16.16.
Definition fp_def.h:425
uint8_t uq2_6_t
Unsigned fixed point number: UQ2.6.
Definition fp_def.h:122
int32_t q9_22_t
Signed fixed point number: Q9.22.
Definition fp_def.h:538
uint32_t uq28_4_t
Unsigned fixed point number: UQ28.4.
Definition fp_def.h:405
uint8_t uq0_8_t
Unsigned fixed point number: UQ0.8.
Definition fp_def.h:162
int16_t q0_15_t
Signed fixed point number: Q0.15.
Definition fp_def.h:381
uint16_t uq10_6_t
Unsigned fixed point number: UQ10.6.
Definition fp_def.h:251
uint16_t uq1_15_t
Unsigned fixed point number: UQ1.15.
Definition fp_def.h:271
uint32_t uq10_22_t
Unsigned fixed point number: UQ10.22.
Definition fp_def.h:448
uint8_t uq4_4_t
Unsigned fixed point number: UQ4.4.
Definition fp_def.h:102
int32_t q16_15_t
Signed fixed point number: Q16.15.
Definition fp_def.h:495
int32_t q27_4_t
Signed fixed point number: Q27.4.
Definition fp_def.h:472
int16_t q7_8_t
Signed fixed point number: Q7.8.
Definition fp_def.h:335
int32_t q15_16_t
Signed fixed point number: Q15.16.
Definition fp_def.h:515
uint16_t uq12_4_t
Unsigned fixed point number: UQ12.4.
Definition fp_def.h:231
int16_t q11_4_t
Signed fixed point number: Q11.4.
Definition fp_def.h:312