32-bit scalar float API¶
- group Scalar 32-bit floating-point API
Functions
-
static inline float_s64_t float_s32_to_float_s64(const float_s32_t x)¶
Convert a float_s32_t to a float_s64_t.
- Parameters:
x – [in] Input value
- Returns:
float_s64_trepresentation ofx
-
static inline float float_s32_to_f32(const float_s32_t x)¶
Convert a float_s32_t to an IEEE754
float.- Parameters:
x – [in] Input value
- Returns:
floatrepresentation ofx
-
static inline double float_s32_to_f64(const float_s32_t x)¶
Convert a float_s32_t to an IEEE754
double.- Parameters:
x – [in] Input value
- Returns:
doublerepresentation ofx
- static inline float_s32_t float_s32_use_exponent(
- const float_s32_t x,
- const exponent_t new_exp,
Rescale a float_s32_t to use a specified exponent.
Returns a new float_s32_t representing the same value as \(x\) (with possible precision loss) but with the exponent set to \(new\_exp\). The mantissa is arithmetic-right-shifted by \(new\_exp - x.exp\) bits.
If \(new\_exp > x.exp\), the mantissa is shifted right and precision may be lost. If \(new\_exp \le x.exp\), the mantissa is shifted left and zero bits are inserted at the least-significant end. If the shift overflows, the mantissa is saturated to
INT32_MAXorINT32_MIN.- Operation Performed
- \[\begin{split}\begin{aligned} & a.mant \leftarrow x.mant \gg \left(new\_exp - x.exp\right) \\ & a.exp \leftarrow new\_exp \end{aligned}\end{split}\]
- Parameters:
x – [in] Input value \(x\)
new_exp – [in] Desired exponent for the result
- Returns:
float_s32_t with exponent set to \(new\_exp\)
- static inline int32_t float_s32_to_s32(
- const float_s32_t x,
- const exponent_t out_exp,
Convert a float_s32_t to a fixed-point
int32_twith a specified exponent.Returns the
int32_tvalue \(a\) such that \(a \cdot 2^{out\_exp} \approx x\). The result is \(x.mant\) arithmetic-right-shifted by \(out\_exp - x.exp\) bits.- Operation Performed
- \[\begin{aligned} & a \leftarrow x.mant \gg \left(out\_exp - x.exp\right) \end{aligned}\]
- Parameters:
x – [in] Input value \(x\)
out_exp – [in] Exponent of the output fixed-point representation
- Returns:
Fixed-point integer \(a\) such that \(a \cdot 2^{out\_exp} \approx x\)
-
float_s32_t float_s32_mul(const float_s32_t x, const float_s32_t y)¶
Multiply two float_s32_t together.
The inputs \(x\) and \(y\) are multiplied together for a result \(a\), which is returned.
- Operation Performed
- \[\begin{aligned} & a \leftarrow x \cdot y \end{aligned}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
- Returns:
The product of \(x\) and \(y\)
-
float_s32_t float_s32_add(const float_s32_t x, const float_s32_t y)¶
Add two float_s32_t together.
The inputs \(x\) and \(y\) are added together for a result \(a\), which is returned.
- Operation Performed
- \[\begin{aligned} & a \leftarrow x + y \end{aligned}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
- Returns:
The sum of \(x\) and \(y\)
-
float_s32_t float_s32_sub(const float_s32_t x, const float_s32_t y)¶
Subtract one float_s32_t from another.
The input \(y\) is subtracted from the input \(x\) for a result \(a\), which is returned.
- Operation Performed
- \[\begin{aligned} & a \leftarrow x - y \end{aligned}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
- Returns:
The difference of \(x\) and \(y\)
-
float_s32_t float_s32_div(const float_s32_t x, const float_s32_t y)¶
Divide one float_s32_t from another.
The input \(x\) is divided by the input \(y\) for a result \(a\), which is returned.
- Operation Performed
- \[\begin{aligned} & a \leftarrow \frac{x}{y} \end{aligned}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
- Throws ET_ARITHMETIC:
if \(Y\) is \(0\)
- Returns:
The result of \(x / y\)
-
float_s32_t float_s32_abs(const float_s32_t x)¶
Get the absolute value of a float_s32_t.
\(a\), the absolute value of \(x\) is returned.
- Operation Performed
- \[\begin{aligned} & a \leftarrow \left| x \right| \end{aligned}\]
- Parameters:
x – [in] Input operand \(x\)
- Returns:
The absolute value of \(x\)
-
unsigned float_s32_gt(const float_s32_t x, const float_s32_t y)¶
Determine whether one float_s32_t is greater than another.
The inputs \(x\) and \(y\) are compared. The result \(a\) is true iff \(x\) is greater than \(y\) and false otherwise. \(a\) is returned.
- Operation Performed
- \[\begin{split}\begin{aligned} & a \leftarrow \begin{cases} 1 & x > y \\ 0 & otherwise \end{cases} \end{aligned}\end{split}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
- Returns:
1 iff \(x > y\); 0 otherwise
-
unsigned float_s32_gte(const float_s32_t x, const float_s32_t y)¶
Determine whether one float_s32_t is greater or equal to another.
The inputs \(x\) and \(y\) are compared. The result \(a\) is true iff \(x\) is greater than or equal to \(y\) and false otherwise. \(a\) is returned.
- Operation Performed
- \[\begin{split}\begin{aligned} & a \leftarrow \begin{cases} 1 & x \geq y \\ 0 & otherwise \end{cases} \end{aligned}\end{split}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
- Returns:
1 iff \(x \geq y\); 0 otherwise
- float_s32_t float_s32_ema(
- const float_s32_t x,
- const float_s32_t y,
- const uq2_30 coef,
Update an exponential moving average.
This function updates an exponential moving average by applying a single new sample. \(x\) is taken as the previous EMA state, with \(y\) as the new sample. The EMA coefficient \(\alpha\) is applied to the term including \(x\).
coefis a fixed-point value in a UQ2.30 format (i.e. has an implied exponent of \(-30\)), and should be in the range \(0 \leq \alpha \leq 1\).- Operation Performed
- \[\begin{aligned} & a \leftarrow \alpha \cdot x + (1 - \alpha) \cdot y \end{aligned}\]
- Parameters:
x – [in] Input operand \(x\)
y – [in] Input operand \(y\)
coef – [in] EMA coefficient \(\alpha\) encoded in UQ2.30 format
- Returns:
The new EMA state
-
float_s32_t float_s32_sqrt(const float_s32_t x)¶
Get the square root of a float_s32_t.
This function computes the square root of \(x\). The result, \(a\) is returned.
The precision with which \(a\) is computed is configurable via the XMATH_BFP_SQRT_DEPTH_S32 configuration parameter. It indicates the number of most significant bits to be calculated.
- Operation Performed
- \[\begin{aligned} & a \leftarrow \sqrt{x} \end{aligned}\]
See also
Warning
\(x\) must be non-negative to get a correct result.
- Parameters:
x – [in] Input operand \(x\)
- Returns:
The square root of \(x\)
-
float_s32_t float_s32_exp(const float_s32_t x)¶
Compute \(e^x\).
This function computes \(e^x\) for real input \(x\).
If \(x\) is known to be in the interval \(\left[-0.5,0.5\right]\),
q30_exp_small()(which is used internally by this function) may be used instead for a speed boost.- Operation Performed
- \[\begin{aligned} & y \leftarrow e^x \end{aligned}\]
- Parameters:
x – [in] Input \(x\)
- Returns:
\(y\)
-
static inline float_s64_t float_s32_to_float_s64(const float_s32_t x)¶