AVR-LibC
2.3.0git
Standard C library for AVR-GCC
|
AVR-LibC Documentation |
![]() ![]() |
AVR-LibC Development Pages |
||||
Main Page |
User Manual |
Library Reference |
FAQ |
Example Projects |
File List |
Index |
Macros | |
#define | FXTOA_ALL 0x1f |
#define | FXTOA_ROUND 0x00 |
#define | FXTOA_TRUNC 0x80 |
#define | FXTOA_NTZ 0x40 |
#define | FXTOA_DOT 0x00 |
#define | FXTOA_COMMA 0x20 |
ASCII Conversions (not in ISO/IEC TR18037) | |
char * | hktoa (short accum x, char *buf, unsigned char mode) |
char * | hrtoa (short fract x, char *buf, unsigned char mode) |
char * | ktoa (accum x, char *buf, unsigned char mode) |
char * | rtoa (fract x, char *buf, unsigned char mode) |
char * | uhktoa (unsigned short accum x, char *buf, unsigned char mode) |
char * | uhrtoa (unsigned short fract x, char *buf, unsigned char mode) |
char * | uktoa (unsigned accum x, char *buf, unsigned char mode) |
char * | urtoa (unsigned fract x, char *buf, unsigned char mode) |
Absolute Value | |
short fract | abshr (short fract val) |
fract | absr (fract val) |
long fract | abslr (long fract val) |
long long fract | absllr (long long fract val) |
short accum | abshk (short accum val) |
accum | absk (accum val) |
long accum | abslk (long accum val) |
long long accum | absllk (long long accum val) |
Bit-Conversions to Integer | |
signed char | bitshr (short fract val) |
unsigned char | bitsuhr (unsigned short fract val) |
int | bitsr (fract val) |
unsigned int | bitsur (unsigned fract val) |
long | bitslr (long fract val) |
unsigned long | bitsulr (unsigned long fract val) |
long long | bitsllr (long long fract val) |
unsigned long long | bitsullr (unsigned long long fract val) |
int | bitshk (short accum val) |
unsigned int | bitsuhk (unsigned short accum val) |
long | bitsk (accum val) |
unsigned long | bitsuk (unsigned accum val) |
long long | bitslk (long accum val) |
unsigned long long | bitsulk (unsigned long accum val) |
long long | bitsllk (long long accum val) |
unsigned long long | bitsullk (unsigned long long accum val) |
Bit-Conversions to Fixed-Point | |
short fract | hrbits (signed char val) |
unsigned short fract | uhrbits (unsigned char val) |
fract | rbits (int val) |
unsigned fract | urbits (unsigned int val) |
long fract | lrbits (long val) |
unsigned long fract | ulrbits (unsigned long val) |
long long fract | llrbits (long long val) |
unsigned long long fract | ullrbits (unsigned long long val) |
short accum | hkbits (int val) |
unsigned short accum | uhkbits (unsigned int val) |
accum | kbits (long val) |
unsigned accum | ukbits (unsigned long val) |
long accum | lkbits (long long val) |
unsigned long accum | ulkbits (unsigned long long val) |
long long accum | llkbits (long long val) |
unsigned long long accum | ullkbits (unsigned long long val) |
Count Left-Shift | |
int | countlshr (short fract val) |
int | countlsuhr (unsigned short fract val) |
int | countlsr (fract val) |
int | countlsur (unsigned fract val) |
int | countlslr (long fract val) |
int | countlsulr (unsigned long fract val) |
int | countlsllr (long long fract val) |
int | countlsullr (unsigned long long fract val) |
int | countlshk (short accum val) |
int | countlsuhk (unsigned short accum val) |
int | countlsk (accum val) |
int | countlsuk (unsigned accum val) |
int | countlslk (long accum val) |
int | countlsulk (unsigned long accum val) |
int | countlsllk (long long accum val) |
int | countlsullk (unsigned long long accum val) |
Division | |
fract | rdivi (int num, int denom) |
long fract | lrdivi (long int num, long int denom) |
unsigned fract | urdivi (unsigned int num, unsigned int denom) |
unsigned long fract | ulrdivi (unsigned long int num, unsigned long int denom) |
Rounding | |
short fract | roundhr (short fract val, int bit) |
unsigned short fract | rounduhr (unsigned short fract val, int bit) |
fract | roundr (fract val, int bit) |
unsigned fract | roundur (unsigned fract val, int bit) |
long fract | roundlr (long fract val, int bit) |
unsigned long fract | roundulr (unsigned long fract val, int bit) |
long long fract | roundllr (long long fract val, int bit) |
unsigned long long fract | roundullr (unsigned long long fract val, int bit) |
short accum | roundhk (short accum val, int bit) |
unsigned short accum | rounduhk (unsigned short accum val, int bit) |
accum | roundk (accum val, int bit) |
unsigned accum | rounduk (unsigned accum val, int bit) |
long accum | roundlk (long accum val, int bit) |
unsigned long accum | roundulk (unsigned long accum val, int bit) |
long long accum | roundllk (long long accum val, int bit) |
unsigned long long accum | roundullk (unsigned long long accum val, int bit) |
Square Root and Transcendental Functions | |
accum | acosk (accum x) |
unsigned accum | acosuk (unsigned accum x) |
accum | asink (accum x) |
unsigned accum | asinuk (unsigned accum x) |
accum | atank (accum x) |
unsigned accum | atanuk (unsigned accum x) |
unsigned fract | atanur (unsigned fract x) |
accum | exp2k (accum x) |
unsigned accum | exp2uk (unsigned accum x) |
unsigned fract | exp2m1ur (unsigned fract x) |
accum | log2uk (unsigned accum x) |
short accum | log2uhk (unsigned short accum x) |
unsigned short fract | log21puhr (unsigned short fract x) |
unsigned fract | log21pur (unsigned fract x) |
accum | cospi2k (accum deg) |
accum | sinpi2k (accum deg) |
fract | sinuhk_deg (unsigned short accum deg) |
fract | cosuhk_deg (unsigned short accum deg) |
unsigned fract | sinpi2ur (unsigned fract x) |
short fract | sqrthr (short fract radic) |
unsigned short fract | sqrtuhr (unsigned short fract radic) |
unsigned fract | sqrtur (unsigned fract radic) |
Type-Generic Functions | |
type | absfx (type val) |
int | countlsfx (type val) |
type | roundfx (type val, int bit) |
As an extension, GNU C supports fixed-point types as defined in the N1169 draft of ISO/IEC DTR 18037.
Two groups of fixed-point data types are added:
Const Suffix | Type | Size | Q-Format |
---|---|---|---|
hr | short fract | 1 | s.7 |
r | fract | 2 | s.15 |
lr | long fract | 4 | s.31 |
llr | long long fract | 8 | s.63 |
hk | short accum | 2 | s8.7 |
k | accum | 4 | s16.15 |
lk | long accum | 8 | s32.31 |
llk | long long accum | 8 | s16.47 |
uhr | unsigned short fract | 1 | 0.8 |
ur | unsigned fract | 2 | 0.16 |
ulr | unsigned long fract | 4 | 0.32 |
ullr | unsigned long long fract | 8 | 0.64 |
uhk | unsigned short accum | 2 | 8.8 |
uk | unsigned accum | 4 | 16.16 |
ulk | unsigned long accum | 8 | 32.32 |
ullk | unsigned long long accum | 8 | 16.48 |
long
long
fixed-point types are avr-gcc extensions.See also some benchmarks.
#define FXTOA_ALL 0x1f |
Include all significant digits in the result of a fixed-point to decimal ASCII conversion. The result has no trailing zeros.
To be used in the mode parameter of such a conversion. For details and examples, see uktoa().
#define FXTOA_COMMA 0x20 |
The fixed-point to decimal ASCII conversion routines use a comma (,
) for the decimal point.
For details and examples, see uktoa().
#define FXTOA_DOT 0x00 |
The fixed-point to decimal ASCII conversion routines use a dot (.
) for the decimal point. This is the default, i.e. FXTOA_DOT can be omitted.
For details, and examples, see uktoa().
#define FXTOA_NTZ 0x40 |
A flag to select that the result of a fixed-point to decimal ASCII conversion has no trailing zeros.
To be used in the mode parameter of such a conversion. For details and examples, see uktoa().
#define FXTOA_ROUND 0x00 |
A flag to select rounding to nearest in a fixed-point to decimal ASCII conversion. Rounding mode is the default, i.e. FXTOA_ROUND can be omitted.
To be used in the mode parameter of such a conversion. For details and examples, see uktoa().
#define FXTOA_TRUNC 0x80 |
A flag to select truncation (rounding to zero) in a fixed-point to decimal ASCII conversion.
To be used in the mode parameter of such a conversion. For details and examples, see uktoa().
type absfx | ( | type | val | ) |
Computes the absolute value of fixed-point value val
. When the result does not fit into the range of the return type, the result is saturated.
short accum abshk | ( | short accum | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
short fract abshr | ( | short fract | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
accum absk | ( | accum | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
long accum abslk | ( | long accum | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
long long accum absllk | ( | long long accum | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
long long fract absllr | ( | long long fract | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
long fract abslr | ( | long fract | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
fract absr | ( | fract | val | ) |
Computes the absolute value of val
. When the result does not fit into the range of the return type, the result is saturated.
accum acosk | ( | accum | x | ) |
Compute the arcus cosine of x
. The returned value is in the range [0, π]. For invalid values of x
the returned value is −65536 = kbits (0x80000000).
The absolute error is bounded by 5.5·10−5 ≈ 2−14.1.
unsigned accum acosuk | ( | unsigned accum | x | ) |
Compute the arcus cosine of x
. The returned value is in the range [0, π/2]. For invalid values of x
the returned value is 32768 = ukbits (0x80000000).
The absolute error is bounded by 4.6·10−5 ≈ 2−14.4.
accum asink | ( | accum | x | ) |
Compute the arcus sine of x
. The returned value is in the range [−π/2, π/2]. For invalid values of x
the returned value is −65536 = kbits (0x80000000).
The absolute error is bounded by 5.1·10−5 ≈ 2−14.
unsigned accum asinuk | ( | unsigned accum | x | ) |
Compute the arcus sine of x
. The returned value is in the range [0, π/2]. For invalid values of x
the returned value is 32768 = ukbits (0x80000000).
The absolute error is bounded by 4.5·10−5 ≈ 2−14.4.
accum atank | ( | accum | x | ) |
Compute the arcus tangent of x
. The returned value is in the range (−π/2, π/2≈1.5708).
unsigned accum atanuk | ( | unsigned accum | x | ) |
Compute the arcus tangent of x
. The returned value is in the range [0, π/2≈1.5708).
unsigned fract atanur | ( | unsigned fract | x | ) |
Compute the arcus tangent of x
. The returned value is in the range [0, π/4≈0.7854].
The absolute error is bounded by 2.6·10−5 ≈ 2−15. The worst case execution time (WCET) is around 210 cycles when MUL is available, and around 1000 cycles when MUL is not available (measured with avr-gcc v15).
int bitshk | ( | short accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
signed char bitshr | ( | short fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
long bitsk | ( | accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
long long bitslk | ( | long accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
long long bitsllk | ( | long long accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
long long bitsllr | ( | long long fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
long bitslr | ( | long fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
int bitsr | ( | fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned int bitsuhk | ( | unsigned short accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned char bitsuhr | ( | unsigned short fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned long bitsuk | ( | unsigned accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned long long bitsulk | ( | unsigned long accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned long long bitsullk | ( | unsigned long long accum | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned long long bitsullr | ( | unsigned long long fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned long bitsulr | ( | unsigned long fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
unsigned int bitsur | ( | unsigned fract | val | ) |
Return an integer value of the same size and signedness, and with the same bit representation like val
.
accum cospi2k | ( | accum | deg | ) |
Cosine of x·π/2
radians.
The absolute error is bounded by 4.6·10−5 ≈ 2−14.4. The worst case execution time (WCET) is around 300 cycles when MUL is available, and around 1400 cycles when MUL is not available.
fract cosuhk_deg | ( | unsigned short accum | deg | ) |
Cosine of the angle deg where deg is specified in degrees, i.e. in the range [0°, 256°). The returned value is in the range (−1, +1), i.e. is never −1.
The absolute error is bounded by 6.5·10−5 ≈ 2−13.9. The worst case execution time (WCET) is around 90 cycles.
int countlsfx | ( | type | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlshk | ( | short accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlshr | ( | short fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsk | ( | accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlslk | ( | long accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsllk | ( | long long accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsllr | ( | long long fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlslr | ( | long fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsr | ( | fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsuhk | ( | unsigned short accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsuhr | ( | unsigned short fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsuk | ( | unsigned accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsulk | ( | unsigned long accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsullk | ( | unsigned long long accum | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsullr | ( | unsigned long long fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsulr | ( | unsigned long fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. int countlsur | ( | unsigned fract | val | ) |
val
is non-zero, the return value is the largest integer k
for which the expression val << k
does not overflow.val
is zero, an integer value is returned that is at least as large as N - 1
, where N
is the total number of bits of the type of the argument. accum exp2k | ( | accum | x | ) |
unsigned fract exp2m1ur | ( | unsigned fract | x | ) |
Compute 2x − 1. The returned value is in the range [0, 1).
The absolute error is bounded by 2.2·10−5 ≈ 2−15.4. The worst case execution time (WCET) is around 200 cycles when MUL is available, and around 1000 cycles when MUL is not available (measured with avr-gcc v15).
unsigned accum exp2uk | ( | unsigned accum | x | ) |
short accum hkbits | ( | int | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
char * hktoa | ( | short accum | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().
short fract hrbits | ( | signed char | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
char * hrtoa | ( | short fract | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().
accum kbits | ( | long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
char * ktoa | ( | accum | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().
long accum lkbits | ( | long long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
long long accum llkbits | ( | long long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
long long fract llrbits | ( | long long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
unsigned short fract log21puhr | ( | unsigned short fract | x | ) |
Return log2(1 + x
), the logarithm to base 2 of the value 1 + x
. The result is in the range [0, 1).
The absolute error is bounded by 4.3·10−3 ≈ 2−7.5. The worst case execution time (WCET) is around 25 cycles when MUL is available, and around 340 cycles when MUL is not available.
unsigned fract log21pur | ( | unsigned fract | x | ) |
Return log2(1 + x
), the logarithm to base 2 of the value 1 + x
. The result is in the range [0, 1).
The absolute error is bounded by 3·10−5 ≈ 2−15. The worst case execution time (WCET) is around 250 cycles when MUL is available, and around 1300 cycles when MUL is not available.
short accum log2uhk | ( | unsigned short accum | x | ) |
Return log2(x
), the logarithm to base 2 of the value x
. The returned value for x
= 0 is −128.
The absolute error is bounded by 8·10−3 ≈ 2−7. The worst case execution time (WCET) is around 60 cycles plus the WCET of log21puhr().
accum log2uk | ( | unsigned accum | x | ) |
Returns log2(x
), the logarithm to base 2 of the value x
. The returned value for x
= 0 is −32768.
The absolute error is bounded by 4.5·10−5 ≈ 2−14.5. The worst case execution time (WCET) is around 150 cycles more than the WCET of log21pur().
long fract lrbits | ( | long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
long fract lrdivi | ( | long int | num, |
long int | denom | ||
) |
The lrdivi() function computes the value of num/denom
and returns the result of the long fract type. The return value is rounded towards zero, and is saturated on overflow. If denom
is zero, the behavior is undefined.
fract rbits | ( | int | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
fract rdivi | ( | int | num, |
int | denom | ||
) |
The rdivi() function computes the value num/denom
and returns the result of the fract
type. The return value is rounded towards zero, and is saturated on overflow. If denom
is zero, the behavior is undefined.
type roundfx | ( | type | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
short accum roundhk | ( | short accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
short fract roundhr | ( | short fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
accum roundk | ( | accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
long accum roundlk | ( | long accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
long long accum roundllk | ( | long long accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
long long fract roundllr | ( | long long fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
long fract roundlr | ( | long fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
fract roundr | ( | fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
unsigned short accum rounduhk | ( | unsigned short accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
unsigned short fract rounduhr | ( | unsigned short fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
unsigned accum rounduk | ( | unsigned accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
unsigned long accum roundulk | ( | unsigned long accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
unsigned long long accum roundullk | ( | unsigned long long accum | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
As an extension, bit
may be in the range −IBIT < bit < FBIT
. For example, bit = −1
rounds to an even value.
unsigned long long fract roundullr | ( | unsigned long long fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
unsigned long fract roundulr | ( | unsigned long fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
unsigned fract roundur | ( | unsigned fract | val, |
int | bit | ||
) |
Round val
to bit
fractional bits. When the result does not fit into the range of the return type, the result is saturated.
char * rtoa | ( | fract | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().
accum sinpi2k | ( | accum | deg | ) |
Sine of x·π/2
radians.
The absolute error is bounded by 4.6·10−5 ≈ 2−14.4. The worst case execution time (WCET) is around 300 cycles when MUL is available, and around 1400 cycles when MUL is not available.
unsigned fract sinpi2ur | ( | unsigned fract | x | ) |
Sine of x·π/2
radians. The returned value is in the range [0, 1).
The absolute error is bounded by 2.9·10−5 ≈ 2−15. The worst case execution time (WCET) is around 260 cycles when MUL is available, and around 1400 cycles when MUL is not available.
fract sinuhk_deg | ( | unsigned short accum | deg | ) |
Sine of the angle deg where deg is specified in degrees, i.e. in the range [0°, 256°). The returned value is in the range (−1, +1), i.e. is never −1.
The absolute error is bounded by 6.5·10−5 ≈ 2−13.9. The worst case execution time (WCET) is around 70 cycles.
short fract sqrthr | ( | short fract | radic | ) |
Square root of the value radic
rounded down.
unsigned short fract sqrtuhr | ( | unsigned short fract | radic | ) |
Square root of the value radic
rounded down. The result is in the range [0, 1).
The absolute error is in the range [−3.9·10−3 ≈ 2−8, 0]. The worst case execution time (WCET) is around 120 cycles.
unsigned fract sqrtur | ( | unsigned fract | radic | ) |
Square root of the value radic
. The result is in the range [0, 1).
The absolute error is in the range [−1.5·10−5 ≈ 2−16, 0]. The worst case execution time (WCET) is around 320 cycles.
unsigned short accum uhkbits | ( | unsigned int | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
char * uhktoa | ( | unsigned short accum | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().
unsigned short fract uhrbits | ( | unsigned char | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
char * uhrtoa | ( | unsigned short fract | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().
unsigned accum ukbits | ( | unsigned long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
char * uktoa | ( | unsigned accum | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
The format of the output is controlled by the mode parameter. It is composed from the format flags below together with Digs, the number of fractional digits. The mode
is the ORed result from Digs and a combination of FXTOA_ALL, FXTOA_ROUND or FXTOA_TRUNC, FXTOA_DOT or FXTOA_COMMA, and FXTOA_NTZ, like in:
Include all significant digits. Digs will be ignored.
Round to nearest for Digs fractional digits. Rounding for Digs ≥ 5 has no effect, i.e. for such Digs values the rounded result will be the same like the truncated result. Rounding mode is the default, i.e. FXTOA_ROUND can be omitted.
Like FXTOA_ALL, but truncate the result (round to zero) after Digs fractional digits.
The decimal point is a dot (.). This is the default, i.e. FXTOA_DOT can be omitted.
,). Value | Mode | Result |
---|---|---|
1.8uk | 0 | "2" |
1.8uk | 1 | "1.8" |
1.8uk | 2 | "1.80" |
1.8uk | 3 | "1.800" |
1.8uk | FXTOA_NTZ | 0 | "2" |
1.8uk | FXTOA_NTZ | 1 | "1.8" |
1.8uk | FXTOA_NTZ | 2 | "1.8" |
1.8uk | FXTOA_NTZ | 3 | "1.8" |
1.8uk | FXTOA_TRUNC | FXTOA_COMMA | 0 | "1" |
1.8uk | FXTOA_TRUNC | FXTOA_COMMA | 1 | "1,7" |
1.8uk | FXTOA_TRUNC | FXTOA_COMMA | 2 | "1,79" |
1.8uk | FXTOA_TRUNC | FXTOA_COMMA | 3 | "1,799" |
1.8uk | FXTOA_ALL | "1.79998779296875" |
The following table helps with providing enough memory in buf.
Notice that the required size of buf is independent of FXTOA_NTZ. This is the case since with FXTOA_NTZ the required buffer size may be larger that the size of the returned string.
Type | Function | FXTOA_ALL | All other Modes | Exact Maximal Value | |
---|---|---|---|---|---|
unsigned accum | uktoa | 23 | 7 + Digs | 216−2−16 | 65535.9999847412109375 |
accum | ktoa | 23 | 8 + Digs | 216−2−15 | 65535.999969482421875 |
unsigned short accum | uhktoa | 13 | 5 + Digs | 28−2−8 | 255.99609375 |
short accum | hktoa | 13 | 6 + Digs | 28−2−7 | 255.9921875 |
unsigned fract | urtoa | 19 | 3 + Digs | 1−2−16 | 0.9999847412109375 |
fract | rtoa | 19 | 4 + Digs | 1−2−15 | 0.999969482421875 |
unsigned short fract | uhrtoa | 11 | 3 + Digs | 1−2−8 | 0.99609375 |
short fract | hrtoa | 11 | 4 + Digs | 1−2−7 | 0.9921875 |
unsigned long accum ulkbits | ( | unsigned long long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
unsigned long long accum ullkbits | ( | unsigned long long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
unsigned long long fract ullrbits | ( | unsigned long long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
unsigned long fract ulrbits | ( | unsigned long | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
unsigned long fract ulrdivi | ( | unsigned long int | num, |
unsigned long int | denom | ||
) |
The ulrdivi() function computes the value of num/denom
and returns the result of the unsigned long fract
type. The return value is rounded towards zero, and is saturated on overflow. If denom
is zero, the behavior is undefined.
unsigned fract urbits | ( | unsigned int | val | ) |
Return a fixed-point value of the same size and signedness, and with the same bit representation like val
.
unsigned fract urdivi | ( | unsigned int | num, |
unsigned int | denom | ||
) |
The urdivi() function computes the value num/denom
and returns the result of the unsigned
fract
type. The return value is rounded towards zero, and is saturated on overflow. If denom
is zero, the behavior is undefined.
char * urtoa | ( | unsigned fract | x, |
char * | buf, | ||
unsigned char | mode | ||
) |
Convert fixed-point value x
to a decimal ASCII representation. The result is written to buf
, and the user is responsible for providing enough memory in buf
. Returns buf
.
For the meaning of mode
, and for the (maximal) number of character written by this function, see uktoa().