Documentation
Tools for embedded systems
|
API for the qFP16 Fixed-point math library. More...
Data Structures | |
struct | qFP16_Settings_t |
A Q16.16 fixed-point settings object. More... | |
Macros | |
#define | qFP16_Constant(x) |
A macro for defining a fixed-point constant value. | |
Typedefs | |
typedef int32_t | qFP16_t |
Fixed-point Q16.16 type with width of exactly 32 bits. | |
Functions | |
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. | |
void | qFP16_SettingsSelect (qFP16_Settings_t *const instance) |
Select the provided setting instance to perform fixed-point operations. | |
int | qFP16_FPToInt (const qFP16_t x) |
Returns the fixed-point value x converted to int. | |
qFP16_t | qFP16_IntToFP (const int x) |
Returns the int value x converted to fixed-point q16.16. | |
qFP16_t | qFP16_FloatToFP (const float x) |
Returns the float value x converted to fixed-point q16.16. | |
float | qFP16_FPToFloat (const qFP16_t x) |
Returns the fixed-point value x converted to float. | |
qFP16_t | qFP16_DoubleToFP (const double x) |
Returns the double value x converted to fixed-point q16.16. | |
double | qFP16_FPToDouble (const qFP16_t x) |
Returns the fixed-point value x converted to double. | |
qFP16_t | qFP16_Abs (const qFP16_t x) |
Returns the absolute value of x. | |
qFP16_t | qFP16_Floor (const qFP16_t x) |
Returns the largest integer value less than or equal to x. | |
qFP16_t | qFP16_Ceil (const qFP16_t x) |
Returns the smallest integer value greater than or equal to x. | |
qFP16_t | qFP16_Round (const qFP16_t x) |
Returns the nearest integer value of the fixed-point argument x. | |
qFP16_t | qFP16_Add (const qFP16_t X, const qFP16_t Y) |
Returns the fixed-point addition x + y. | |
qFP16_t | qFP16_Sub (const qFP16_t X, const qFP16_t Y) |
Returns the fixed-point subtraction x - y. | |
qFP16_t | qFP16_Mul (const qFP16_t x, const qFP16_t y) |
Returns the fixed-point product operation x * y. | |
qFP16_t | qFP16_Div (const qFP16_t x, const qFP16_t y) |
Returns the fixed-point division operation x / y. | |
qFP16_t | qFP16_Mod (const qFP16_t x, const qFP16_t y) |
Returns the fixed-point modulo operation x % y. | |
qFP16_t | qFP16_Sqrt (qFP16_t x) |
Returns the fixed-point square root of x. | |
qFP16_t | qFP16_Exp (qFP16_t x) |
Returns the fixed-point value of e raised to the xth power. | |
qFP16_t | qFP16_Log (qFP16_t x) |
Returns the fixed-point natural logarithm (base-e logarithm) of x. | |
qFP16_t | qFP16_Log2 (const qFP16_t x) |
Returns the fixed-point log base 2 of x. | |
qFP16_t | qFP16_RadToDeg (const qFP16_t x) |
Converts angle units from radians to degrees. | |
qFP16_t | qFP16_DegToRad (const qFP16_t x) |
Converts angle units from degrees to radians. | |
qFP16_t | qFP16_WrapToPi (qFP16_t x) |
Wrap the fixed-point angle in radians to [−pi pi]. | |
qFP16_t | qFP16_WrapTo180 (qFP16_t x) |
Wrap the fixed-point angle in degrees to [−180 180]. | |
qFP16_t | qFP16_Sin (qFP16_t x) |
Computes the fixed-point sine of the radian angle x. | |
qFP16_t | qFP16_Cos (qFP16_t x) |
Computes the fixed-point cosine of the radian angle x. | |
qFP16_t | qFP16_Tan (qFP16_t x) |
Computes the fixed-point tangent of the radian angle x. | |
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 determine the correct quadrant. | |
qFP16_t | qFP16_Atan (qFP16_t x) |
Computes the fixed-point arc tangent of x in radians. | |
qFP16_t | qFP16_Asin (qFP16_t x) |
Computes the fixed-point arc sine of x in radians. | |
qFP16_t | qFP16_Acos (qFP16_t x) |
Computes the fixed-point arc cosine of x in radians. | |
qFP16_t | qFP16_Cosh (qFP16_t x) |
Computes the fixed-point hyperbolic cosine of x. | |
qFP16_t | qFP16_Sinh (qFP16_t x) |
Computes the fixed-point hyperbolic sine of x. | |
qFP16_t | qFP16_Tanh (qFP16_t x) |
Computes the fixed-point hyperbolic tangent of x. | |
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 elements are the coefficients (in descending powers) of an nth-degree polynomial. | |
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) | |
qFP16_t | qFP16_Pow (const qFP16_t x, const qFP16_t y) |
Returns x raised to the power of y. (x^y) | |
char * | qFP16_FPToA (const qFP16_t num, char *str, int decimals) |
Converts the fixed-point value to a formatted string. | |
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 value as a qFP16_t. The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a fixed-point numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this function. | |
Variables | |
const struct _qFP16_const_s | qFP16 |
Fixed-point Q16.16 constants. | |
API for the qFP16 Fixed-point math library.
For a brief description of this module, please read Fixed-Point Q16.16 library
#define qFP16_Constant | ( | x | ) |
A macro for defining a fixed-point constant value.
[in] | x | A literal value |
Returns the absolute value of x.
[in] | x | The fixed-point(q16.16) value. |
Computes the fixed-point arc cosine of x in radians.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Returns the fixed-point addition x + y.
[in] | X | The fixed-point(q16.16) value. |
[in] | Y | The fixed-point(q16.16) value. |
qFP16.overflow
when an operation overflow is detected. Computes the fixed-point arc sine of x in radians.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Computes the fixed-point arc tangent of x in radians.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Computes the fixed-point arc tangent in radians of y / x based on the signs of both values to determine the correct quadrant.
[in] | y | The fixed-point(q16.16) value representing an x-coordinate. |
[in] | x | The fixed-point(q16.16) value representing an y-coordinate. |
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 value as a qFP16_t. The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a fixed-point numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this function.
[in] | s | The string beginning with the representation of a floating-point number. |
qFP16.overflow
. If the converted value would be out of the range of representable values by a fixed-point Q16.16, the function returns qFP16.overflow
. Returns the smallest integer value greater than or equal to x.
[in] | x | The fixed-point(q16.16) value. |
Computes the fixed-point cosine of the radian angle x.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Computes the fixed-point hyperbolic cosine of x.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
. If the function saturates, returns QFP16_EXP_MAX or QFP16_EXP_MIN. Converts angle units from degrees to radians.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in degrees. |
Returns the fixed-point division operation x / y.
[in] | x | The fixed-point(q16.16) value. |
[in] | y | The fixed-point(q16.16) value. |
qFP16.overflow
when an operation overflow is detected. qFP16_t qFP16_DoubleToFP | ( | const double | x | ) |
Returns the double value x converted to fixed-point q16.16.
[in] | x | The double precision floating-point value. |
Returns the fixed-point value of e raised to the xth power.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
when an operation overflow is detected. qFP16_t qFP16_FloatToFP | ( | const float | x | ) |
Returns the float value x converted to fixed-point q16.16.
[in] | x | The floating-point value. |
Returns the largest integer value less than or equal to x.
[in] | x | The fixed-point(q16.16) value. |
char * qFP16_FPToA | ( | const qFP16_t | num, |
char * | str, | ||
int | decimals ) |
Converts the fixed-point value to a formatted string.
[in] | num | The fixed-point(q16.16) value to be converted to string. |
[in] | str | Array in memory where to store the resulting null-terminated string. |
[in] | decimals | Number of decimals to show in the string representation. |
double qFP16_FPToDouble | ( | const qFP16_t | x | ) |
Returns the fixed-point value x converted to double.
[in] | x | The fixed-point(q16.16) value. |
float qFP16_FPToFloat | ( | const qFP16_t | x | ) |
Returns the fixed-point value x converted to float.
[in] | x | The fixed-point(q16.16) value. |
int qFP16_FPToInt | ( | const qFP16_t | x | ) |
Returns the fixed-point value x converted to int.
[in] | x | The fixed-point(q16.16) value. |
qFP16_t qFP16_IntToFP | ( | const int | x | ) |
Returns the int value x converted to fixed-point q16.16.
[in] | x | The integer value. |
Returns x raised to the power of the integer part of y. (x^y)
[in] | x | The fixed-point(q16.16) base value. |
[in] | y | The fixed-point(q16.16) power value. Only the integer part is taken |
qFP16.overflow
when an operation overflow is detected. Returns the fixed-point natural logarithm (base-e logarithm) of x.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
Returns the fixed-point log base 2 of x.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
Returns the fixed-point modulo operation x % y.
[in] | x | The fixed-point(q16.16) value. |
[in] | y | The fixed-point(q16.16) value. |
Returns the fixed-point product operation x * y.
[in] | x | The fixed-point(q16.16) value. |
[in] | y | The fixed-point(q16.16) value. |
qFP16.overflow
when an operation overflow is detected. Evaluates the fixed-point polynomial p at the point x. The argument p is a vector of length n+1 whose elements are the coefficients (in descending powers) of an nth-degree polynomial.
[in] | p | Polynomial coefficients, specified as a fixed-point(q16.16) array. |
[in] | n | The number of elements of the fixed-point array p. |
[in] | x | The fixed-point(q16.16) value to evaluate the polynomial. |
qFP16.overflow
. Returns x raised to the power of y. (x^y)
[in] | x | The fixed-point(q16.16) base value. |
[in] | y | The fixed-point(q16.16) power value. |
qFP16.overflow
when an operation overflow is detected. Converts angle units from radians to degrees.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Returns the nearest integer value of the fixed-point argument x.
[in] | x | The fixed-point(q16.16) value. |
void qFP16_SettingsSelect | ( | qFP16_Settings_t *const | instance | ) |
Select the provided setting instance to perform fixed-point operations.
[in] | instance | A pointer to the fixed-point settings instance. Pass NULL to use the default settings. |
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.
[in] | instance | A pointer to the fixed-point settings instance |
[in] | min | The minimal value allowed for the output. |
[in] | max | The maximal value allowed for the output. |
[in] | rounding | Enable rounding mode. |
[in] | saturate | Enable saturation mode. |
Computes the fixed-point sine of the radian angle x.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Computes the fixed-point hyperbolic sine of x.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
. If the function saturates, returns QFP16_EXP_MAX or QFP16_EXP_MIN. Returns the fixed-point square root of x.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
. Returns the fixed-point subtraction x - y.
[in] | X | The fixed-point(q16.16) value. |
[in] | Y | The fixed-point(q16.16) value. |
qFP16.overflow
when an operation overflow is detected. Computes the fixed-point tangent of the radian angle x.
[in] | x | The fixed-point(q16.16) value representing an angle expressed in radians. |
Computes the fixed-point hyperbolic tangent of x.
[in] | x | The fixed-point(q16.16) value. |
qFP16.overflow
. If the function saturates, returns QFP16_EXP_MAX or QFP16_EXP_MIN. Wrap the fixed-point angle in degrees to [−180 180].
[in] | x | The fixed-point(q16.16) value representing an angle expressed in degrees. |