Fixmath
1.4
|
Fixed-point math library. More...
Go to the source code of this file.
Data Structures | |
struct | fx_rdiv_t |
Typedefs | |
typedef int32_t | fixed_t |
Functions | |
int | fx_clz (uint32_t word) |
int | fx_ctz (uint32_t word) |
int | fx_bitcount (uint32_t word) |
fixed_t | fx_itox (int32_t ival, unsigned frac) |
fixed_t | fx_ftox (float fval, unsigned frac) |
fixed_t | fx_dtox (double dval, unsigned frac) |
fixed_t | fx_xtox (fixed_t xval, unsigned frac1, unsigned frac2) |
int32_t | fx_xtoi (fixed_t xval, unsigned frac) |
float | fx_xtof (fixed_t xval, unsigned frac) |
double | fx_xtod (fixed_t xval, unsigned frac) |
int32_t | fx_roundx (fixed_t xval, unsigned frac) |
int32_t | fx_ceilx (fixed_t xval, unsigned frac) |
int32_t | fx_floorx (fixed_t xval, unsigned frac) |
fixed_t | fx_addx (fixed_t x1, fixed_t x2) |
fixed_t | fx_subx (fixed_t x1, fixed_t x2) |
fixed_t | fx_mulx (fixed_t x1, fixed_t x2, unsigned frac) |
fixed_t | fx_divx (fixed_t x1, fixed_t x2, unsigned frac) |
fixed_t | fx_rdivx (fixed_t xval, const fx_rdiv_t *rdiv) |
int | fx_itoa (char *str, int32_t val) |
int | fx_xtoa (char *str, fixed_t xval, unsigned frac, unsigned digits) |
fixed_t | fx_invx (fixed_t xval, unsigned frac, fx_rdiv_t *rdiv) |
fixed_t | fx_sqrtx (fixed_t xval, unsigned frac) |
fixed_t | fx_isqrtx (fixed_t xval, unsigned frac, fx_rdiv_t *rdiv) |
fixed_t | fx_expx (fixed_t xval, unsigned frac) |
fixed_t | fx_exp2x (fixed_t xval, unsigned frac) |
fixed_t | fx_exp10x (fixed_t xval, unsigned frac) |
fixed_t | fx_logx (fixed_t xval, unsigned frac) |
fixed_t | fx_log2x (fixed_t xval, unsigned frac) |
fixed_t | fx_log10x (fixed_t xval, unsigned frac) |
fixed_t | fx_powx (fixed_t xval, unsigned xfrac, fixed_t yval, unsigned yfrac) |
fixed_t | fx_sinx (fixed_t xval, unsigned frac) |
fixed_t | fx_cosx (fixed_t xval, unsigned frac) |
Fixed-point math library.
typedef int32_t fixed_t |
The fixed-point data type.
int fx_clz | ( | uint32_t | word | ) |
Count the number of leading zeros in a 32-bit word. Note that fx_clz(0) is undefined.
word | The source word. |
int fx_ctz | ( | uint32_t | word | ) |
Count the number of trailing zeros in a 32-bit word. Note that fx_ctz(0) is undefined.
word | The source word. |
int fx_bitcount | ( | uint32_t | word | ) |
Count the number of bits set in a 32-bit word.
word | The source word. |
fixed_t fx_itox | ( | int32_t | ival, |
unsigned | frac | ||
) |
Integer to fixed-point conversion.
ival | Integer value. |
frac | The number of fixed-point fractional bits desired. |
fixed_t fx_ftox | ( | float | fval, |
unsigned | frac | ||
) |
Single precision float to fixed-point conversion. The error is within 1 ulp.
fval | Single-precision float value. |
frac | The number of fixed-point fractional bits desired. |
fixed_t fx_dtox | ( | double | dval, |
unsigned | frac | ||
) |
Double precision float to fixed-point conversion. The error is within 1/2 ulp.
dval | Double-precision float value. |
frac | The number of fixed-point fractional bits desired. |
Fixed-point format conversion. The error is within 1/2 ulp.
xval | Fixed-point value with frac1 fractional bits. |
frac1 | The number of fractional in original representation. |
frac2 | The number of fractional bits resired. |
int32_t fx_xtoi | ( | fixed_t | xval, |
unsigned | frac | ||
) |
Fixed-point to integer conversion.
This is equal to fx_floorx().
xval | Fixed-point value. |
frac | The number of fractional bits. |
float fx_xtof | ( | fixed_t | xval, |
unsigned | frac | ||
) |
Fixed-point to single precision float conversion. The error is within 1/2 ulp.
xval | Fixed-point value. |
frac | The number of fractional bits. |
double fx_xtod | ( | fixed_t | xval, |
unsigned | frac | ||
) |
Fixed-point to double precision float conversion. The error is within 1/2 ulp.
xval | Fixed-point value. |
frac | The number of fractional bits. |
int32_t fx_roundx | ( | fixed_t | xval, |
unsigned | frac | ||
) |
Round a fixed-point number to the nearest integer.
xval | Fixed-point value. |
frac | The number of fractional bits. |
int32_t fx_ceilx | ( | fixed_t | xval, |
unsigned | frac | ||
) |
Round a fixed-point number up to the nearest integer.
xval | Fixed-point value. |
frac | The number of fractional bits in xval. |
int32_t fx_floorx | ( | fixed_t | xval, |
unsigned | frac | ||
) |
Round a fixed-point number down to the nearest integer.
xval | Fixed-point value. |
frac | The number of fractional bits in xval. |
Fixed-point addition. The terms must have the same number of fractional bits. This operation expands to a regular add operation.
x1 | First fixed-point term. |
x2 | Second fixed-point term. |
Fixed-point subtraction. The terms must have the same number of fractional bits. This operation expands to a regular add operation.
x1 | First fixed-point term. |
x2 | Second fixed-point term. |
Fixed-point multiply. The error is within 1/2 ulp. The number of fraction bits in the result is f1 + f2 - frac, where f1 and f2 are the number of fraction bits of x1 and x2, respectively. Thus, if both f1 and f2 are equal to frac, the number of fraction bits in the result will also be frac.
x1 | First fixed-point factor. |
x2 | Second fixed-point factor. |
frac | Number of fraction bits, see explaination above. |
Fixed-point divide. The error is within 1/2 ulp. The number of fraction bits in the result is f1 - f2 + frac, where f1 and f2 are the number of fraction bits of x1 and x2, respectively. Thus, if both f1 and f2 are equal to frac, the number of fraction bits in the result will also be frac.
x1 | Fixed-point numerator. |
x2 | Fixed-point denominator. |
frac | Number of fraction bits, see explaination above. |
Fixed-point divide by reciprocal multiplication.
xval | Fixed-point numerator. |
rdiv | A reciprocal division factor, obtained from either fx_invx() or fx_isqrtx(). |
int fx_itoa | ( | char * | str, |
int32_t | val | ||
) |
Integer to ASCII string conversion.
str | The string buffer to use. It must be long enough to hold the string value, i.e. at least 12 bytes in the worst case. |
val | The integral number to convert. |
int fx_xtoa | ( | char * | str, |
fixed_t | xval, | ||
unsigned | frac, | ||
unsigned | digits | ||
) |
Fixed-point to ASCII string conversion. The number is converted to the format [-]d.ddd[e+00]. If the precision (digits) is zero, no decimal point appears. If the exponent is zero, no exponent appears.
str | The string buffer to use. It must be long enough to hold the string value, i.e. at least 8 + digits bytes. |
xval | The fixed-point number to convert. |
frac | The number of fractional bits. |
digits | The number of digits to the right of the decimal point. |
Fixed-point inverse value. The error is within 4 ulp if frac is less than 31, 7 ulp otherwise. If the input is out-of-range (zero), then errno is set to EDOM.
xval | A non-zero fixed-point value. |
frac | The number of fractional bits. |
rdiv | Optional reciprocal division multiplier. |
Fixed-point square root. The error is within 2 ulp if frac is less than 31, and within 4 ulp otherwise. If the input is out-of-range (negative), then errno is set to EDOM.
xval | A non-zero fixed-point value. |
frac | The number of fractional bits. |
Fixed-point inverse square root. The error is within 2 ulp if frac is less than 31, and within 3 ulp otherwise. If the input is out-of-range (negative or zero), then errno is set to EDOM.
xval | A non-zero fixed-point value. |
frac | The number of fractional bits. |
rdiv | Optional reciprocal division multiplier. |
Fixed-point natural exponential. The error is within 2 ulp. If frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point base-2 exponential. The error is within 2 ulp. If frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point base-10 exponential. The error is within 2 ulp. If frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point natural logarithm. The error is within 2 ulp. If xval is negative or zero or frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point base-2 logarithm. The error is within 2 ulp. If xval is negative or zero or frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point base-10 logarithm. The error is within 2 ulp. If xval is negative or zero or frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point power function. The error is bounded by C1 |yval| xval yval + C2, where C1 and C2 are approximately 1 and 5 ulp, respectively. If either xfrac or yfrac is greater than 31, or xval is negative, or xval is zero and yval is negative, then errno is set to EDOM.
xval | The base in fixed-point format. |
xfrac | The number of fractional bits for the base. |
yval | The exponent in fixed-point format. |
yfrac | The number of fractional bits for the exponent. |
Fixed-point sine. The error is within 3 ulp if frac is less than 31, and within 4 ulp otherwise. If frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |
Fixed-point cosine. The error is within 3 ulp if frac is less than 31, and within 4 ulp otherwise. If frac is greater than 31, then errno is set to EDOM.
xval | A fixed-point value. |
frac | The number of fractional bits. |