AVR-LibC  2.3.0git
Standard C library for AVR-GCC
 

AVR-LibC Documen­tation

AVR-LibC Development Pages

Main Page

User Manual

Library Refe­rence

FAQ

Example Projects

File List

Index

Loading...
Searching...
No Matches
Macros
<stdfix.h>: ISO/IEC TR 18037 Fixed-Point Arithmetic

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)
 

Detailed Description

#include <stdfix.h>

As an extension, GNU C supports fixed-point types as defined in the N1169 draft of ISO/IEC DTR 18037.

Since
avr-gcc v4.8

Two groups of fixed-point data types are added:

Fixed-Point Type Layout
Const Suffix Type Size Q-Format
hr short fract 1s.7
r fract 2s.15
lr long fract 4s.31
llr long long fract 8s.63
hk short accum 2s8.7
k accum 4s16.15
lk long accum 8s32.31
llk long long accum 8s16.47
uhr unsigned short fract 10.8
ur unsigned fract 20.16
ulr unsigned long fract 40.32
ullrunsigned long long fract80.64
uhk unsigned short accum 28.8
uk unsigned accum 416.16
ulk unsigned long accum 832.32
ullkunsigned long long accum 816.48
Remarks
  • Upper case constant suffixes are also supported.
  • The long long fixed-point types are avr-gcc extensions.

See also some benchmarks.

Macro Definition Documentation

◆ FXTOA_ALL

#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().

Since
AVR-LibC v2.3

◆ FXTOA_COMMA

#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().

Since
AVR-LibC v2.3

◆ FXTOA_DOT

#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().

Since
AVR-LibC v2.3

◆ FXTOA_NTZ

#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().

Since
AVR-LibC v2.3

◆ FXTOA_ROUND

#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().

Since
AVR-LibC v2.3

◆ FXTOA_TRUNC

#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().

Since
AVR-LibC v2.3

Function Documentation

◆ absfx()

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.

◆ abshk()

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.

◆ abshr()

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.

◆ absk()

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.

◆ abslk()

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.

◆ absllk()

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.

◆ absllr()

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.

◆ abslr()

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.

◆ absr()

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.

◆ acosk()

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.

Since
AVR-LibC v2.3

◆ acosuk()

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.

Since
AVR-LibC v2.3

◆ asink()

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.

Since
AVR-LibC v2.3

◆ asinuk()

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.

Since
AVR-LibC v2.3

◆ atank()

accum atank ( accum  x)

Compute the arcus tangent of x. The returned value is in the range (−π/2, π/2≈1.5708).

Since
AVR-LibC v2.3

◆ atanuk()

unsigned accum atanuk ( unsigned accum  x)

Compute the arcus tangent of x. The returned value is in the range [0, π/2≈1.5708).

Since
AVR-LibC v2.3

◆ atanur()

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

Since
AVR-LibC v2.3

◆ bitshk()

int bitshk ( short accum  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitshr()

signed char bitshr ( short fract  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitsk()

long bitsk ( accum  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitslk()

long long bitslk ( long accum  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitsllk()

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.

◆ bitsllr()

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.

◆ bitslr()

long bitslr ( long fract  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitsr()

int bitsr ( fract  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitsuhk()

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.

◆ bitsuhr()

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.

◆ bitsuk()

unsigned long bitsuk ( unsigned accum  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ bitsulk()

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.

◆ bitsullk()

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.

◆ bitsullr()

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.

◆ bitsulr()

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.

◆ bitsur()

unsigned int bitsur ( unsigned fract  val)

Return an integer value of the same size and signedness, and with the same bit representation like val.

◆ cospi2k()

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.

Since
AVR-LibC v2.3

◆ cosuhk_deg()

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.

Since
AVR-LibC v2.3

◆ countlsfx()

int countlsfx ( type  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlshk()

int countlshk ( short accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlshr()

int countlshr ( short fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsk()

int countlsk ( accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlslk()

int countlslk ( long accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsllk()

int countlsllk ( long long accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsllr()

int countlsllr ( long long fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlslr()

int countlslr ( long fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsr()

int countlsr ( fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsuhk()

int countlsuhk ( unsigned short accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsuhr()

int countlsuhr ( unsigned short fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsuk()

int countlsuk ( unsigned accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsulk()

int countlsulk ( unsigned long accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsullk()

int countlsullk ( unsigned long long accum  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsullr()

int countlsullr ( unsigned long long fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsulr()

int countlsulr ( unsigned long fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ countlsur()

int countlsur ( unsigned fract  val)
  • If val is non-zero, the return value is the largest integer k for which the expression val << k does not overflow.
  • If 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.

◆ exp2k()

accum exp2k ( accum  x)

Compute 2x with saturation.

The WCET is at least the one of exp2m1ur().

Since
AVR-LibC v2.3

◆ exp2m1ur()

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

Since
AVR-LibC v2.3

◆ exp2uk()

unsigned accum exp2uk ( unsigned accum  x)

Compute 2x with saturation.

The WCET is at least the one of exp2m1ur().

Since
AVR-LibC v2.3

◆ hkbits()

short accum hkbits ( int  val)

Return a fixed-point value of the same size and signedness, and with the same bit representation like val.

◆ hktoa()

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().

Since
AVR-LibC v2.3

◆ hrbits()

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.

◆ hrtoa()

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().

Since
AVR-LibC v2.3

◆ kbits()

accum kbits ( long  val)

Return a fixed-point value of the same size and signedness, and with the same bit representation like val.

◆ ktoa()

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().

Since
AVR-LibC v2.3

◆ lkbits()

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.

◆ llkbits()

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.

◆ llrbits()

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.

◆ log21puhr()

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.

Since
AVR-LibC v2.3

◆ log21pur()

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.

Since
AVR-LibC v2.3

◆ log2uhk()

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().

Since
AVR-LibC v2.3

◆ log2uk()

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().

Since
AVR-LibC v2.3

◆ lrbits()

long fract lrbits ( long  val)

Return a fixed-point value of the same size and signedness, and with the same bit representation like val.

◆ lrdivi()

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.

Since
AVR-LibC v2.3

◆ rbits()

fract rbits ( int  val)

Return a fixed-point value of the same size and signedness, and with the same bit representation like val.

◆ rdivi()

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.

Since
AVR-LibC v2.3

◆ roundfx()

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.

◆ roundhk()

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.

◆ roundhr()

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.

◆ roundk()

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.

◆ roundlk()

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.

◆ roundllk()

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.

◆ roundllr()

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.

◆ roundlr()

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.

◆ roundr()

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.

◆ rounduhk()

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.

◆ rounduhr()

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.

◆ rounduk()

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.

◆ roundulk()

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.

◆ roundullk()

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.

◆ roundullr()

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.

◆ roundulr()

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.

◆ roundur()

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.

◆ rtoa()

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().

Since
AVR-LibC v2.3

◆ sinpi2k()

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.

Since
AVR-LibC v2.3

◆ sinpi2ur()

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.

Since
AVR-LibC v2.3

◆ sinuhk_deg()

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.

Since
AVR-LibC v2.3

◆ sqrthr()

short fract sqrthr ( short fract  radic)

Square root of the value radic rounded down.

Since
AVR-LibC v2.3

◆ sqrtuhr()

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.

Since
AVR-LibC v2.3

◆ sqrtur()

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.

Since
AVR-LibC v2.3

◆ uhkbits()

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.

◆ uhktoa()

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().

Since
AVR-LibC v2.3

◆ uhrbits()

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.

◆ uhrtoa()

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().

Since
AVR-LibC v2.3

◆ ukbits()

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.

◆ uktoa()

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:

uktoa (x, buf, FXTOA_ROUND | FXTOA_NTZ | Digs);
char * uktoa(unsigned accum x, char *buf, unsigned char mode)
#define FXTOA_NTZ
Definition: stdfix-avrlibc.h:136
#define FXTOA_ROUND
Definition: stdfix-avrlibc.h:118
  • Supported values for Digs are in the range 0...30.
FXTOA_ALL

Include all significant digits. Digs will be ignored.

FXTOA_ROUND

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.

FXTOA_TRUNC

Like FXTOA_ALL, but truncate the result (round to zero) after Digs fractional digits.

FXTOA_NTZ
• With FXTOA_NTZ the result has no trailing zeros. When the result represents an integral value, then no decimal point and no fractional digits are present.
• Without FXTOA_NTZ and with FXTOA_ROUND or FXTOA_TRUNC, the result has the specified number of fractional digits.
• FXTOA_NTZ has no effect with FXTOA_ALL.
• FXTOA_NTZ has no effect on the required buffer size.
FXTOA_DOT

The decimal point is a dot (.). This is the default, i.e. FXTOA_DOT can be omitted.

FXTOA_COMMA
The decimal point is a comma (,).
Examples
Value Mode Result
1.8uk0"2"
1.8uk1"1.8"
1.8uk2"1.80"
1.8uk3"1.800"
1.8ukFXTOA_NTZ | 0"2"
1.8ukFXTOA_NTZ | 1"1.8"
1.8ukFXTOA_NTZ | 2"1.8"
1.8ukFXTOA_NTZ | 3"1.8"
1.8ukFXTOA_TRUNC | FXTOA_COMMA | 0"1"
1.8ukFXTOA_TRUNC | FXTOA_COMMA | 1"1,7"
1.8ukFXTOA_TRUNC | FXTOA_COMMA | 2"1,79"
1.8ukFXTOA_TRUNC | FXTOA_COMMA | 3"1,799"
1.8ukFXTOA_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.

Maximum Number of Bytes written to buf
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
Since
AVR-LibC v2.3

◆ ulkbits()

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.

◆ ullkbits()

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.

◆ ullrbits()

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.

◆ ulrbits()

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.

◆ ulrdivi()

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.

Since
AVR-LibC v2.3

◆ urbits()

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.

◆ urdivi()

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.

Since
AVR-LibC v2.3

◆ urtoa()

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().

Since
AVR-LibC v2.3