Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qlibs::fp16 Class Reference

Fixed-point Q16.16 type with width of exactly 32 bits. More...

#include <fp16.hpp>

Public Member Functions

constexpr fp16 ()
 
 fp16 (const fp16 &other)
 
bool isOverflow (void) const noexcept
 Check for (q16.16) fixed-point overflow.
 
bool isExpMax (void) const noexcept
 Check for (q16.16) fixed-point fp16::exp() operation reaches the EXP_MAX value.
 
fp16Raw_t raw (void) const noexcept
 Get the (q16.16) raw integer value from x.
 

Static Public Member Functions

static int toInt (const fp16 &x) noexcept
 Returns the fixed-point value x converted to int.
 
static float toFloat (const fp16 &x) noexcept
 Returns the fixed-point value x converted to float.
 
static double toDouble (const fp16 &x) noexcept
 Returns the fixed-point value x converted to double.
 
static fp16 from (const int x) noexcept
 Returns the int value x converted to fixed-point q16.16.
 
static fp16 from (const float x) noexcept
 Returns the float value x converted to fixed-point q16.16.
 
static fp16 from (const double x) noexcept
 Returns the double value x converted to fixed-point q16.16.
 
static fp16 floor (const fp16 &x) noexcept
 Returns the largest integer value less than or equal to x.
 
static fp16 ceil (const fp16 &x) noexcept
 
static fp16 rounding (const fp16 &x) noexcept
 Returns the nearest integer value of the fixed-point argument x.
 
static fp16 absolute (const fp16 &x) noexcept
 Returns the absolute value of x.
 
static fp16 sqrt (const fp16 &x) noexcept
 Returns the fixed-point square root of x.
 
static fp16 exp (const fp16 &x) noexcept
 Returns the fixed-point value of e raised to the xth power.
 
static fp16 log (const fp16 &x) noexcept
 Returns the fixed-point natural logarithm (base-e logarithm) of x.
 
static fp16 log2 (const fp16 &x) noexcept
 Returns the fixed-point log base 2 of x.
 
static fp16 radToDeg (const fp16 &x) noexcept
 Converts angle units from radians to degrees.
 
static fp16 degToRad (const fp16 &x) noexcept
 Converts angle units from degrees to radians.
 
static fp16 wrapToPi (const fp16 &x) noexcept
 Wrap the fixed-point angle in radians to [−pi pi].
 
static fp16 wrapTo180 (const fp16 &x) noexcept
 Wrap the fixed-point angle in degrees to [−180 180].
 
static fp16 sin (const fp16 &x) noexcept
 Computes the fixed-point sine of the radian angle x.
 
static fp16 cos (const fp16 &x) noexcept
 Computes the fixed-point cosine of the radian angle x.
 
static fp16 tan (const fp16 &x) noexcept
 Computes the fixed-point tangent of the radian angle x.
 
static fp16 atan2 (const fp16 &y, const fp16 &x) noexcept
 Computes the fixed-point arc tangent in radians of y / x based on the signs of both values to determine the correct quadrant.
 
static fp16 atan (const fp16 &x) noexcept
 Computes the fixed-point arc tangent of x in radians.
 
static fp16 asin (const fp16 &x) noexcept
 Computes the fixed-point arc sine of x in radians.
 
static fp16 acos (const fp16 &x) noexcept
 Computes the fixed-point arc cosine of x in radians.
 
static fp16 cosh (const fp16 &x) noexcept
 Computes the fixed-point hyperbolic cosine of x.
 
static fp16 sinh (const fp16 &x) noexcept
 Computes the fixed-point hyperbolic sine of x.
 
static fp16 tanh (const fp16 &x) noexcept
 Computes the fixed-point hyperbolic tangent of x.
 
static fp16 pow (const fp16 &x, const fp16 &y) noexcept
 Returns x raised to the power of y. (x^y)
 
static char * toASCII (const fp16 &x, char *str, int decimals) noexcept
 Converts the fixed-point value to a formatted string.
 

Detailed Description

Fixed-point Q16.16 type with width of exactly 32 bits.

Constructor & Destructor Documentation

◆ fp16() [1/2]

qlibs::fp16::fp16 ( )
inlineconstexpr

◆ fp16() [2/2]

qlibs::fp16::fp16 ( const fp16 & other)
inline

Member Function Documentation

◆ absolute()

static fp16 qlibs::fp16::absolute ( const fp16 & x)
inlinestaticnoexcept

Returns the absolute value of x.

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

◆ acos()

static fp16 qlibs::fp16::acos ( const fp16 & x)
inlinestaticnoexcept

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.

◆ asin()

static fp16 qlibs::fp16::asin ( const fp16 & x)
inlinestaticnoexcept

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.

◆ atan()

static fp16 qlibs::fp16::atan ( const fp16 & x)
inlinestaticnoexcept

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.

◆ atan2()

static fp16 qlibs::fp16::atan2 ( const fp16 & y,
const fp16 & x )
inlinestaticnoexcept

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.

◆ ceil()

static fp16 qlibs::fp16::ceil ( const fp16 & x)
inlinestaticnoexcept

◆ cos()

static fp16 qlibs::fp16::cos ( const fp16 & x)
inlinestaticnoexcept

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.

◆ cosh()

static fp16 qlibs::fp16::cosh ( const fp16 & x)
inlinestaticnoexcept

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 overflow. If the function saturates, returns EXP_MAX or EXP_MIN.

◆ degToRad()

static fp16 qlibs::fp16::degToRad ( const fp16 & x)
inlinestaticnoexcept

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.

◆ exp()

static fp16 qlibs::fp16::exp ( const fp16 & x)
inlinestaticnoexcept

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. overflow when an operation overflow is detected.

◆ floor()

static fp16 qlibs::fp16::floor ( const fp16 & x)
inlinestaticnoexcept

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.

◆ from() [1/3]

static fp16 qlibs::fp16::from ( const double x)
inlinestaticnoexcept

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.

◆ from() [2/3]

static fp16 qlibs::fp16::from ( const float x)
inlinestaticnoexcept

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.

◆ from() [3/3]

static fp16 qlibs::fp16::from ( const int x)
inlinestaticnoexcept

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.

◆ isExpMax()

bool qlibs::fp16::isExpMax ( void ) const
inlinenoexcept

Check for (q16.16) fixed-point fp16::exp() operation reaches the EXP_MAX value.

Returns
true if the fixed-point has reached EXP_MAX, otherwise false.

◆ isOverflow()

bool qlibs::fp16::isOverflow ( void ) const
inlinenoexcept

Check for (q16.16) fixed-point overflow.

Returns
true if the fixed-point has overflowed otherwise false.

◆ log()

static fp16 qlibs::fp16::log ( const fp16 & x)
inlinestaticnoexcept

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 returns overflow

◆ log2()

static fp16 qlibs::fp16::log2 ( const fp16 & x)
inlinestaticnoexcept

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 overflow

◆ pow()

static fp16 qlibs::fp16::pow ( const fp16 & x,
const fp16 & y )
inlinestaticnoexcept

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. overflow when an operation overflow is detected.

◆ radToDeg()

static fp16 qlibs::fp16::radToDeg ( const fp16 & x)
inlinestaticnoexcept

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.

◆ raw()

fp16Raw_t qlibs::fp16::raw ( void ) const
inlinenoexcept

Get the (q16.16) raw integer value from x.

Returns
The raw integer value that represents the fixed-point.

◆ rounding()

static fp16 qlibs::fp16::rounding ( const fp16 & x)
inlinestaticnoexcept

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.

◆ sin()

static fp16 qlibs::fp16::sin ( const fp16 & x)
inlinestaticnoexcept

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.

◆ sinh()

static fp16 qlibs::fp16::sinh ( const fp16 & x)
inlinestaticnoexcept

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 overflow. If the function saturates, returns EXP_MAX or EXP_MIN.

◆ sqrt()

static fp16 qlibs::fp16::sqrt ( const fp16 & x)
inlinestaticnoexcept

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 overflow.

◆ tan()

static fp16 qlibs::fp16::tan ( const fp16 & x)
inlinestaticnoexcept

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.

◆ tanh()

static fp16 qlibs::fp16::tanh ( const fp16 & x)
inlinestaticnoexcept

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 overflow. If the function saturates, returns EXP_MAX or EXP_MIN.

◆ toASCII()

static char * qlibs::fp16::toASCII ( const fp16 & x,
char * str,
int decimals )
inlinestaticnoexcept

Converts the fixed-point value to a formatted string.

Parameters
[in]xThe 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

◆ toDouble()

double fp16::toDouble ( const fp16 & x)
staticnoexcept

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.

◆ toFloat()

float fp16::toFloat ( const fp16 & x)
staticnoexcept

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.

◆ toInt()

int fp16::toInt ( const fp16 & x)
staticnoexcept

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.

◆ wrapTo180()

static fp16 qlibs::fp16::wrapTo180 ( const fp16 & x)
inlinestaticnoexcept

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.

◆ wrapToPi()

static fp16 qlibs::fp16::wrapToPi ( const fp16 & x)
inlinestaticnoexcept

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.