Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qFP16

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.
 

Detailed Description

API for the qFP16 Fixed-point math library.

For a brief description of this module, please read Fixed-Point Q16.16 library

Macro Definition Documentation

◆ qFP16_Constant

#define qFP16_Constant ( x)

A macro for defining a fixed-point constant value.

Note
You should only use this for constant values. For runtime-conversions use qFP16_IntToFP(), qFP16_FloatToFP() or qFP16_DoubleToFP() instead.
Parameters
[in]xA literal value
Returns
The literal argument x converted to fixed-point(qFP16_t).

Function Documentation

◆ qFP16_Abs()

qFP16_t qFP16_Abs ( const qFP16_t x)

Returns the absolute value of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns the absolute value of x.

◆ qFP16_Acos()

qFP16_t qFP16_Acos ( qFP16_t x)

Computes the fixed-point arc cosine of x in radians.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns arc cosine of x.

◆ qFP16_Add()

qFP16_t qFP16_Add ( const qFP16_t X,
const qFP16_t Y )

Returns the fixed-point addition x + y.

Parameters
[in]XThe fixed-point(q16.16) value.
[in]YThe fixed-point(q16.16) value.
Returns
This function returns the addition operation x+y. qFP16.overflow when an operation overflow is detected.

◆ qFP16_Asin()

qFP16_t qFP16_Asin ( qFP16_t x)

Computes the fixed-point arc sine of x in radians.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns arc sine of x.

◆ qFP16_Atan()

qFP16_t qFP16_Atan ( qFP16_t x)

Computes the fixed-point arc tangent of x in radians.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns arc tangent of x.

◆ qFP16_Atan2()

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.

Parameters
[in]yThe fixed-point(q16.16) value representing an x-coordinate.
[in]xThe fixed-point(q16.16) value representing an y-coordinate.
Returns
This function returns the principal arc tangent of y/x, in the interval [-pi,+pi] radians.

◆ qFP16_AToFP()

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.

Parameters
[in]sThe string beginning with the representation of a floating-point number.
Returns
On success, the function returns the converted floating point number as a fixed-point value. If no valid conversion could be performed, the function returns zero (0.0) or 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 .

◆ qFP16_Ceil()

qFP16_t qFP16_Ceil ( const qFP16_t x)

Returns the smallest integer value greater than or equal to x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns the smallest integral value not less than x.

◆ qFP16_Cos()

qFP16_t qFP16_Cos ( qFP16_t x)

Computes the fixed-point cosine of the radian angle x.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns cosine of x.

◆ qFP16_Cosh()

qFP16_t qFP16_Cosh ( qFP16_t x)

Computes the fixed-point hyperbolic cosine of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns hyperbolic cosine of x. If overflow detected returns qFP16.overflow. If the function saturates, returns QFP16_EXP_MAX or QFP16_EXP_MIN.

◆ qFP16_DegToRad()

qFP16_t qFP16_DegToRad ( const qFP16_t x)

Converts angle units from degrees to radians.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in degrees.
Returns
This function returns the angle converted in radians.

◆ qFP16_Div()

qFP16_t qFP16_Div ( const qFP16_t x,
const qFP16_t y )

Returns the fixed-point division operation x / y.

Parameters
[in]xThe fixed-point(q16.16) value.
[in]yThe fixed-point(q16.16) value.
Returns
This function returns the product operation x/y. qFP16.overflow when an operation overflow is detected.

◆ qFP16_DoubleToFP()

qFP16_t qFP16_DoubleToFP ( const double x)

Returns the double value x converted to fixed-point q16.16.

Parameters
[in]xThe double precision floating-point value.
Returns
This function returns x converted to fixed-point q16.16.

◆ qFP16_Exp()

qFP16_t qFP16_Exp ( qFP16_t x)

Returns the fixed-point value of e raised to the xth power.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns the exponential value of x. qFP16.overflow when an operation overflow is detected.

◆ qFP16_FloatToFP()

qFP16_t qFP16_FloatToFP ( const float x)

Returns the float value x converted to fixed-point q16.16.

Parameters
[in]xThe floating-point value.
Returns
This function returns x converted to fixed-point q16.16.

◆ qFP16_Floor()

qFP16_t qFP16_Floor ( const qFP16_t x)

Returns the largest integer value less than or equal to x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns the largest integral value not greater than x.

◆ qFP16_FPToA()

char * qFP16_FPToA ( const qFP16_t num,
char * str,
int decimals )

Converts the fixed-point value to a formatted string.

Parameters
[in]numThe fixed-point(q16.16) value to be converted to string.
[in]strArray in memory where to store the resulting null-terminated string.
[in]decimalsNumber of decimals to show in the string representation.
Note
: Max decimal allowed = 5
Returns
A pointer to the resulting null-terminated string, same as parameter str

◆ qFP16_FPToDouble()

double qFP16_FPToDouble ( const qFP16_t x)

Returns the fixed-point value x converted to double.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns x converted to double.

◆ qFP16_FPToFloat()

float qFP16_FPToFloat ( const qFP16_t x)

Returns the fixed-point value x converted to float.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns x converted to float.

◆ qFP16_FPToInt()

int qFP16_FPToInt ( const qFP16_t x)

Returns the fixed-point value x converted to int.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns x converted to int.

◆ qFP16_IntToFP()

qFP16_t qFP16_IntToFP ( const int x)

Returns the int value x converted to fixed-point q16.16.

Parameters
[in]xThe integer value.
Returns
This function returns x converted to fixed-point q16.16.

◆ qFP16_IPow()

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)

Parameters
[in]xThe fixed-point(q16.16) base value.
[in]yThe fixed-point(q16.16) power value. Only the integer part is taken
Returns
This function returns the result of raising x to the power y. qFP16.overflow when an operation overflow is detected.

◆ qFP16_Log()

qFP16_t qFP16_Log ( qFP16_t x)

Returns the fixed-point natural logarithm (base-e logarithm) of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns natural logarithm of x. For negative values returnsqFP16.overflow

◆ qFP16_Log2()

qFP16_t qFP16_Log2 ( const qFP16_t x)

Returns the fixed-point log base 2 of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns log base 2 of x. For negative values returns qFP16.overflow

◆ qFP16_Mod()

qFP16_t qFP16_Mod ( const qFP16_t x,
const qFP16_t y )

Returns the fixed-point modulo operation x % y.

Parameters
[in]xThe fixed-point(q16.16) value.
[in]yThe fixed-point(q16.16) value.
Returns
This function returns the modulo operation xy.

◆ qFP16_Mul()

qFP16_t qFP16_Mul ( const qFP16_t x,
const qFP16_t y )

Returns the fixed-point product operation x * y.

Parameters
[in]xThe fixed-point(q16.16) value.
[in]yThe fixed-point(q16.16) value.
Returns
This function returns the product operation x*y. qFP16.overflow when an operation overflow is detected.

◆ qFP16_Polyval()

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.

Parameters
[in]pPolynomial coefficients, specified as a fixed-point(q16.16) array.
[in]nThe number of elements of the fixed-point array p.
[in]xThe fixed-point(q16.16) value to evaluate the polynomial.
Returns
This function returns the polynomial evaluation p(x). If overflow detected returns qFP16.overflow.

◆ qFP16_Pow()

qFP16_t qFP16_Pow ( const qFP16_t x,
const qFP16_t y )

Returns x raised to the power of y. (x^y)

Parameters
[in]xThe fixed-point(q16.16) base value.
[in]yThe fixed-point(q16.16) power value.
Returns
This function returns the result of raising x to the power y. qFP16.overflow when an operation overflow is detected.

◆ qFP16_RadToDeg()

qFP16_t qFP16_RadToDeg ( const qFP16_t x)

Converts angle units from radians to degrees.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns the angle converted in degrees.

◆ qFP16_Round()

qFP16_t qFP16_Round ( const qFP16_t x)

Returns the nearest integer value of the fixed-point argument x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns the nearest integral value of x.

◆ qFP16_SettingsSelect()

void qFP16_SettingsSelect ( qFP16_Settings_t *const instance)

Select the provided setting instance to perform fixed-point operations.

Parameters
[in]instanceA pointer to the fixed-point settings instance. Pass NULL to use the default settings.
Returns
none.

◆ qFP16_SettingsSet()

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.

Parameters
[in]instanceA pointer to the fixed-point settings instance
[in]minThe minimal value allowed for the output.
[in]maxThe maximal value allowed for the output.
[in]roundingEnable rounding mode.
[in]saturateEnable saturation mode.
Returns
1 on success, otherwise return 0.

◆ qFP16_Sin()

qFP16_t qFP16_Sin ( qFP16_t x)

Computes the fixed-point sine of the radian angle x.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns sine of x.

◆ qFP16_Sinh()

qFP16_t qFP16_Sinh ( qFP16_t x)

Computes the fixed-point hyperbolic sine of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns hyperbolic sine of x. If overflow detected returns qFP16.overflow. If the function saturates, returns QFP16_EXP_MAX or QFP16_EXP_MIN.

◆ qFP16_Sqrt()

qFP16_t qFP16_Sqrt ( qFP16_t x)

Returns the fixed-point square root of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns the square root of x. For negative numbers, returns qFP16.overflow .

◆ qFP16_Sub()

qFP16_t qFP16_Sub ( const qFP16_t X,
const qFP16_t Y )

Returns the fixed-point subtraction x - y.

Parameters
[in]XThe fixed-point(q16.16) value.
[in]YThe fixed-point(q16.16) value.
Returns
This function returns the subtraction operation x-y. qFP16.overflow when an operation overflow is detected.

◆ qFP16_Tan()

qFP16_t qFP16_Tan ( qFP16_t x)

Computes the fixed-point tangent of the radian angle x.

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns tangent of x.

◆ qFP16_Tanh()

qFP16_t qFP16_Tanh ( qFP16_t x)

Computes the fixed-point hyperbolic tangent of x.

Parameters
[in]xThe fixed-point(q16.16) value.
Returns
This function returns hyperbolic tangent of x. If overflow detected returns qFP16.overflow. If the function saturates, returns QFP16_EXP_MAX or QFP16_EXP_MIN.

◆ qFP16_WrapTo180()

qFP16_t qFP16_WrapTo180 ( qFP16_t x)

Wrap the fixed-point angle in degrees to [−180 180].

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in degrees.
Returns
This function returns the wrapped angle in the range [−180, 180] of x.

◆ qFP16_WrapToPi()

qFP16_t qFP16_WrapToPi ( qFP16_t x)

Wrap the fixed-point angle in radians to [−pi pi].

Parameters
[in]xThe fixed-point(q16.16) value representing an angle expressed in radians.
Returns
This function returns the wrapped angle in the range [−pi, pi] of x.