Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qfp16.h
1
9#ifndef QFP16_H
10#define QFP16_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16 #include <stdint.h>
17 #include <stdlib.h>
18
25 typedef int32_t qFP16_t;
26
28 struct _qFP16_const_s //skipcq: CXX-E2000
29 {
30 const qFP16_t
31 f_e, /* [ e ] The base of natural logarithms, e.*/
32 f_log2e, /* [log2(e)] The base 2 logarithm of e.*/
33 f_log10e, /* [log10(e)] The base 10 logarithm of e*/
34 f_ln2, /* [ln(2)] The natural logarithm of 2*/
35 f_ln10, /* [ln(10)] The natural logarithm of 10*/
36 f_pi, /* [pi] The circumference of a circle with diameter 1*/
37 f_pi_2, /* [pi/2] Half of pi */
38 f_2pi, /* [ 2*pi ] Twice pì*/
39 f_pi_4, /* [pi/4] A quarter of pi */
40 f_1_pi, /* [1/pi] The inverse of pi.*/
41 f_2_pi, /* [2/pi] Twice the inverse of pi*/
42 f_2_sqrtpi, /* [2/sqrt(pi)] The inverse of the square root of π.*/
43 f_sqrt2, /* [sqrt(2)] The square root of 2*/
44 f_sqrt1_2, /* [1/sqrt(2)] The inverse of the square root of 2*/
45 epsilon,
46 max,
47 overflow,
48 one, /* [ 1 ] */
49 one_half, /* [ 1/2 ] */
50 f_180_pi, /* [ 180/pi ] */
51 f_pi_180, /* [ pi/180 ] */
52 f_180, /* [ 180 ] */
53 f_360; /* [ 360 ] */
54 };
60 extern const struct _qFP16_const_s qFP16; //skipcq: CXX-E2000
61
69 #define qFP16_Constant(x) \
70 ( (qFP16_t)( ( (x) >= 0 ) ? ( (x) * 65536.0F + 0.5F ) \
71 : ( (x) * 65536.0F - 0.5F ) ) ) \
72
78 typedef struct
79 {
81 qFP16_t min, max;
82 uint8_t rounding, saturate;
85
95 int qFP16_SettingsSet( qFP16_Settings_t * const instance,
96 qFP16_t min,
97 qFP16_t max,
98 uint8_t rounding,
99 uint8_t saturate );
100
108 void qFP16_SettingsSelect( qFP16_Settings_t * const instance );
109
115 int qFP16_FPToInt( const qFP16_t x );
116
122 qFP16_t qFP16_IntToFP( const int x );
123
129 qFP16_t qFP16_FloatToFP( const float x );
130
136 float qFP16_FPToFloat( const qFP16_t x );
137
143 qFP16_t qFP16_DoubleToFP( const double x );
144
150 double qFP16_FPToDouble( const qFP16_t x );
151
157 qFP16_t qFP16_Abs( const qFP16_t x );
158
165 qFP16_t qFP16_Floor( const qFP16_t x );
166
172 qFP16_t qFP16_Ceil( const qFP16_t x );
173
179 qFP16_t qFP16_Round( const qFP16_t x );
180
188 qFP16_t qFP16_Add( const qFP16_t X,
189 const qFP16_t Y );
190
198 qFP16_t qFP16_Sub( const qFP16_t X,
199 const qFP16_t Y );
200
208 qFP16_t qFP16_Mul( const qFP16_t x,
209 const qFP16_t y );
210
218 qFP16_t qFP16_Div( const qFP16_t x,
219 const qFP16_t y );
220
227 qFP16_t qFP16_Mod( const qFP16_t x,
228 const qFP16_t y );
229
237
245
253
260 qFP16_t qFP16_Log2( const qFP16_t x );
261
268 qFP16_t qFP16_RadToDeg( const qFP16_t x );
269
276 qFP16_t qFP16_DegToRad( const qFP16_t x );
277
286
295
303
311
319
328 qFP16_t qFP16_Atan2( const qFP16_t y,
329 const qFP16_t x );
330
338
346
354
363
372
381
393 qFP16_t qFP16_Polyval( const qFP16_t * const p,
394 const size_t n,
395 const qFP16_t x );
396
405 qFP16_t qFP16_IPow( const qFP16_t x,
406 const qFP16_t y );
407
415 qFP16_t qFP16_Pow( const qFP16_t x,
416 const qFP16_t y );
417
428 char* qFP16_FPToA( const qFP16_t num,
429 char *str,
430 int decimals );
431
449 qFP16_t qFP16_AToFP( const char *s );
450
453#ifdef __cplusplus
454}
455#endif
456
457#endif
qFP16_t qFP16_Mod(const qFP16_t x, const qFP16_t y)
Returns the fixed-point modulo operation x % y.
Definition qfp16.c:358
qFP16_t qFP16_Sqrt(qFP16_t x)
Returns the fixed-point square root of x.
Definition qfp16.c:370
qFP16_t qFP16_Atan2(const qFP16_t y, const qFP16_t x)
Computes the fixed-point arc tangent in radians of y / x based on the signs of both values to determi...
Definition qfp16.c:607
char * qFP16_FPToA(const qFP16_t num, char *str, int decimals)
Converts the fixed-point value to a formatted string.
Definition qfp16.c:806
int32_t qFP16_t
Fixed-point Q16.16 type with width of exactly 32 bits.
Definition qfp16.h:25
qFP16_t qFP16_Polyval(const qFP16_t *const p, const size_t n, const qFP16_t x)
Evaluates the fixed-point polynomial p at the point x. The argument p is a vector of length n+1 whose...
Definition qfp16.c:734
qFP16_t qFP16_Exp(qFP16_t x)
Returns the fixed-point value of e raised to the xth power.
Definition qfp16.c:425
qFP16_t qFP16_Floor(const qFP16_t x)
Returns the largest integer value less than or equal to x.
Definition qfp16.c:200
qFP16_t qFP16_Round(const qFP16_t x)
Returns the nearest integer value of the fixed-point argument x.
Definition qfp16.c:214
qFP16_t qFP16_Cos(qFP16_t x)
Computes the fixed-point cosine of the radian angle x.
Definition qfp16.c:592
int qFP16_SettingsSet(qFP16_Settings_t *const instance, qFP16_t min, qFP16_t max, uint8_t rounding, uint8_t saturate)
Set settings for the fixed-point API.
Definition qfp16.c:88
qFP16_t qFP16_Ceil(const qFP16_t x)
Returns the smallest integer value greater than or equal to x.
Definition qfp16.c:206
qFP16_t qFP16_Div(const qFP16_t x, const qFP16_t y)
Returns the fixed-point division operation x / y.
Definition qfp16.c:298
int qFP16_FPToInt(const qFP16_t x)
Returns the fixed-point value x converted to int.
Definition qfp16.c:120
qFP16_t qFP16_Sinh(qFP16_t x)
Computes the fixed-point hyperbolic sine of x.
Definition qfp16.c:683
qFP16_t qFP16_DoubleToFP(const double x)
Returns the double value x converted to fixed-point q16.16.
Definition qfp16.c:166
qFP16_t qFP16_Abs(const qFP16_t x)
Returns the absolute value of x.
Definition qfp16.c:186
qFP16_t qFP16_AToFP(const char *s)
Parses the C string s, interpreting its content as a fixed-point (q16.16) number and returns its valu...
Definition qfp16.c:860
qFP16_t qFP16_Atan(qFP16_t x)
Computes the fixed-point arc tangent of x in radians.
Definition qfp16.c:636
qFP16_t qFP16_Add(const qFP16_t X, const qFP16_t Y)
Returns the fixed-point addition x + y.
Definition qfp16.c:219
qFP16_t qFP16_Tan(qFP16_t x)
Computes the fixed-point tangent of the radian angle x.
Definition qfp16.c:597
qFP16_t qFP16_IPow(const qFP16_t x, const qFP16_t y)
Returns x raised to the power of the integer part of y. (x^y)
Definition qfp16.c:755
qFP16_t qFP16_RadToDeg(const qFP16_t x)
Converts angle units from radians to degrees.
Definition qfp16.c:533
qFP16_t qFP16_Log(qFP16_t x)
Returns the fixed-point natural logarithm (base-e logarithm) of x.
Definition qfp16.c:469
qFP16_t qFP16_FloatToFP(const float x)
Returns the float value x converted to fixed-point q16.16.
Definition qfp16.c:146
qFP16_t qFP16_IntToFP(const int x)
Returns the int value x converted to fixed-point q16.16.
Definition qfp16.c:141
void qFP16_SettingsSelect(qFP16_Settings_t *const instance)
Select the provided setting instance to perform fixed-point operations.
Definition qfp16.c:110
const struct _qFP16_const_s qFP16
Fixed-point Q16.16 constants.
qFP16_t qFP16_Acos(qFP16_t x)
Computes the fixed-point arc cosine of x in radians.
Definition qfp16.c:654
qFP16_t qFP16_WrapToPi(qFP16_t x)
Wrap the fixed-point angle in radians to [−pi pi].
Definition qfp16.c:543
qFP16_t qFP16_Sin(qFP16_t x)
Computes the fixed-point sine of the radian angle x.
Definition qfp16.c:571
qFP16_t qFP16_Pow(const qFP16_t x, const qFP16_t y)
Returns x raised to the power of y. (x^y)
Definition qfp16.c:783
double qFP16_FPToDouble(const qFP16_t x)
Returns the fixed-point value x converted to double.
Definition qfp16.c:179
qFP16_t qFP16_Cosh(qFP16_t x)
Computes the fixed-point hyperbolic cosine of x.
Definition qfp16.c:659
qFP16_t qFP16_Sub(const qFP16_t X, const qFP16_t Y)
Returns the fixed-point subtraction x - y.
Definition qfp16.c:233
qFP16_t qFP16_Asin(qFP16_t x)
Computes the fixed-point arc sine of x in radians.
Definition qfp16.c:641
qFP16_t qFP16_WrapTo180(qFP16_t x)
Wrap the fixed-point angle in degrees to [−180 180].
Definition qfp16.c:557
qFP16_t qFP16_Log2(const qFP16_t x)
Returns the fixed-point log base 2 of x.
Definition qfp16.c:505
qFP16_t qFP16_DegToRad(const qFP16_t x)
Converts angle units from degrees to radians.
Definition qfp16.c:538
qFP16_t qFP16_Tanh(qFP16_t x)
Computes the fixed-point hyperbolic tangent of x.
Definition qfp16.c:710
qFP16_t qFP16_Mul(const qFP16_t x, const qFP16_t y)
Returns the fixed-point product operation x * y.
Definition qfp16.c:247
float qFP16_FPToFloat(const qFP16_t x)
Returns the fixed-point value x converted to float.
Definition qfp16.c:159
A Q16.16 fixed-point settings object.
Definition qfp16.h:79