AVR-LibC  2.3.0
Standard C library for AVR-GCC
 

AVR-LibC Manual

AVR-LibC Sources

Main Page

User Manual

Lib­rary Refe­rence

FAQ

Exam­ple Pro­jects

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 accum sqrthk (short accum radic)
 
short fract sqrthr (short fract radic)
 
accum sqrtk (accum radic)
 
long fract sqrtlr (long fract radic)
 
fract sqrtr (fract radic)
 
unsigned short accum sqrtuhk (unsigned short accum radic)
 
unsigned short fract sqrtuhr (unsigned short fract radic)
 
unsigned accum sqrtuk (unsigned accum radic)
 
unsigned long fract sqrtulr (unsigned long 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)
 

Functions reading from PROGMEM

static short fract pgm_read_hr (const short fract *addr)
 
static unsigned short fract pgm_read_uhr (const unsigned short fract *addr)
 
static fract pgm_read_r (const fract *addr)
 
static unsigned fract pgm_read_ur (const unsigned fract *addr)
 
static long fract pgm_read_lr (const long fract *addr)
 
static unsigned long fract pgm_read_ulr (const unsigned long fract *addr)
 
static long long fract pgm_read_llr (const long long fract *addr)
 
static unsigned long long fract pgm_read_ullr (const unsigned long long fract *addr)
 
static short accum pgm_read_hk (const short accum *addr)
 
static unsigned short accum pgm_read_uhk (const unsigned short accum *addr)
 
static accum pgm_read_k (const accum *addr)
 
static unsigned accum pgm_read_uk (const unsigned accum *addr)
 
static long accum pgm_read_lk (const long accum *addr)
 
static unsigned long accum pgm_read_ulk (const unsigned long accum *addr)
 
static long long accum pgm_read_llk (const long long accum *addr)
 
static unsigned long long accum pgm_read_ullk (const unsigned long long accum *addr)
 

Functions reading from PROGMEM_FAR

static short fract pgm_read_hr_far (uint_farptr_t addr)
 
static unsigned short fract pgm_read_uhr_far (uint_farptr_t addr)
 
static fract pgm_read_r_far (uint_farptr_t addr)
 
static unsigned fract pgm_read_ur_far (uint_farptr_t addr)
 
static long fract pgm_read_lr_far (uint_farptr_t addr)
 
static unsigned long fract pgm_read_ulr_far (uint_farptr_t addr)
 
static long long fract pgm_read_llr_far (uint_farptr_t addr)
 
static unsigned long long fract pgm_read_ullr_far (uint_farptr_t addr)
 
static short accum pgm_read_hk_far (uint_farptr_t addr)
 
static unsigned short accum pgm_read_uhk_far (uint_farptr_t addr)
 
static accum pgm_read_k_far (uint_farptr_t addr)
 
static unsigned accum pgm_read_uk_far (uint_farptr_t addr)
 
static long accum pgm_read_lk_far (uint_farptr_t addr)
 
static unsigned long accum pgm_read_ulk_far (uint_farptr_t addr)
 
static long long accum pgm_read_llk_far (uint_farptr_t addr)
 
static unsigned long long accum pgm_read_ullk_far (uint_farptr_t addr)
 

EEPROM Read Functions

short fract eeprom_read_hr (const short fract *__p)
 
unsigned short fract eeprom_read_uhr (const unsigned short fract *__p)
 
fract eeprom_read_r (const fract *__p)
 
unsigned fract eeprom_read_ur (const unsigned fract *__p)
 
long fract eeprom_read_lr (const long fract *__p)
 
unsigned long fract eeprom_read_ulr (const unsigned long fract *__p)
 
long long fract eeprom_read_llr (const long long fract *__p)
 
unsigned long long fract eeprom_read_ullr (const unsigned long long fract *__p)
 
short accum eeprom_read_hk (const short accum *__p)
 
unsigned short accum eeprom_read_uhk (const unsigned short accum *__p)
 
accum eeprom_read_k (const accum *__p)
 
unsigned accum eeprom_read_uk (const unsigned accum *__p)
 
long accum eeprom_read_lk (const long accum *__p)
 
unsigned long accum eeprom_read_ulk (const unsigned long accum *__p)
 
long long accum eeprom_read_llk (const long long accum *__p)
 
unsigned long long accum eeprom_read_ullk (const unsigned long long accum *__p)
 

EEPROM Write Functions

void eeprom_write_hr (short fract *__p, short fract __value)
 
void eeprom_write_uhr (unsigned short fract *__p, unsigned short fract __value)
 
void eeprom_write_r (fract *__p, fract __value)
 
void eeprom_write_ur (unsigned fract *__p, unsigned fract __value)
 
void eeprom_write_lr (long fract *__p, long fract __value)
 
void eeprom_write_ulr (unsigned long fract *__p, unsigned long fract __value)
 
void eeprom_write_llr (long long fract *__p, long long fract __value)
 
void eeprom_write_ullr (unsigned long long fract *__p, unsigned long long fract __value)
 
void eeprom_write_hk (short accum *__p, short accum __value)
 
void eeprom_write_uhk (unsigned short accum *__p, unsigned short accum __value)
 
void eeprom_write_k (accum *__p, accum __value)
 
void eeprom_write_uk (unsigned accum *__p, unsigned accum __value)
 
void eeprom_write_lk (long accum *__p, long accum __value)
 
void eeprom_write_ulk (unsigned long accum *__p, unsigned long accum __value)
 
void eeprom_write_llk (long long accum *__p, long long accum __value)
 
void eeprom_write_ullk (unsigned long long accum *__p, unsigned long long accum __value)
 

EEPROM Update Functions

void eeprom_update_hr (short fract *__p, short fract __value)
 
void eeprom_update_uhr (unsigned short fract *__p, unsigned short fract __value)
 
void eeprom_update_r (fract *__p, fract __value)
 
void eeprom_update_ur (unsigned fract *__p, unsigned fract __value)
 
void eeprom_update_lr (long fract *__p, long fract __value)
 
void eeprom_update_ulr (unsigned long fract *__p, unsigned long fract __value)
 
void eeprom_update_llr (long long fract *__p, long long fract __value)
 
void eeprom_update_ullr (unsigned long long fract *__p, unsigned long long fract __value)
 
void eeprom_update_hk (short accum *__p, short accum __value)
 
void eeprom_update_uhk (unsigned short accum *__p, unsigned short accum __value)
 
void eeprom_update_k (accum *__p, accum __value)
 
void eeprom_update_uk (unsigned accum *__p, unsigned accum __value)
 
void eeprom_update_lk (long accum *__p, long accum __value)
 
void eeprom_update_ulk (unsigned long accum *__p, unsigned long accum __value)
 
void eeprom_update_llk (long long accum *__p, long long accum __value)
 
void eeprom_update_ullk (unsigned long long accum *__p, unsigned long long accum __value)
 

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 Epsilon
hr short fract 1s.7 7.81·10-3
r fract 2s.15 3.05·10-5
lr long fract 4s.31 4.66·10-10
llr long long fract 8s.631.08·10-19
hk short accum 2s8.7 7.81·10-3
k accum 4s16.15 3.05·10-5
lk long accum 8s32.31 4.66·10-10
llk long long accum 8s16.47 7.11·10-15
uhr unsigned short fract 10.8 3.91·10-3
ur unsigned fract 20.16 1.53·10-5
ulr unsigned long fract 40.32 2.33·10-10
ullrunsigned long long fract80.64 5.42·10-20
uhk unsigned short accum 28.8 3.91·10-3
uk unsigned accum 416.161.53·10-5
ulk unsigned long accum 832.322.33·10-10
ullkunsigned long long accum 816.483.55·10-15
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.

◆ eeprom_read_hk()

short accum eeprom_read_hk ( const short accum *  __p)

Read a short accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_hr()

short fract eeprom_read_hr ( const short fract *  __p)

Read a short fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_k()

accum eeprom_read_k ( const accum *  __p)

Read an accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_lk()

long accum eeprom_read_lk ( const long accum *  __p)

Read a long accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_llk()

long long accum eeprom_read_llk ( const long long accum *  __p)

Read a long long accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_llr()

long long fract eeprom_read_llr ( const long long fract *  __p)

Read a long long fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_lr()

long fract eeprom_read_lr ( const long fract *  __p)

Read a long fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_r()

fract eeprom_read_r ( const fract *  __p)

Read a fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_uhk()

unsigned short accum eeprom_read_uhk ( const unsigned short accum *  __p)

Read an unsigned short accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_uhr()

unsigned short fract eeprom_read_uhr ( const unsigned short fract *  __p)

Read an unsigned short fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_uk()

unsigned accum eeprom_read_uk ( const unsigned accum *  __p)

Read an unsigned accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_ulk()

unsigned long accum eeprom_read_ulk ( const unsigned long accum *  __p)

Read an unsigned long accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_ullk()

unsigned long long accum eeprom_read_ullk ( const unsigned long long accum *  __p)

Read an unsigned long long accum from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_ullr()

unsigned long long fract eeprom_read_ullr ( const unsigned long long fract *  __p)

Read an unsigned long long fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_ulr()

unsigned long fract eeprom_read_ulr ( const unsigned long fract *  __p)

Read an unsigned long fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_read_ur()

unsigned fract eeprom_read_ur ( const unsigned fract *  __p)

Read an unsigned fract from EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_hk()

void eeprom_update_hk ( short accum *  __p,
short accum  __value 
)

Update a short accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_hr()

void eeprom_update_hr ( short fract *  __p,
short fract  __value 
)

Update a short fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_k()

void eeprom_update_k ( accum *  __p,
accum  __value 
)

Update an accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_lk()

void eeprom_update_lk ( long accum *  __p,
long accum  __value 
)

Update a long accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_llk()

void eeprom_update_llk ( long long accum *  __p,
long long accum  __value 
)

Update a long long accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_llr()

void eeprom_update_llr ( long long fract *  __p,
long long fract  __value 
)

Update a long long fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_lr()

void eeprom_update_lr ( long fract *  __p,
long fract  __value 
)

Update a long fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_r()

void eeprom_update_r ( fract *  __p,
fract  __value 
)

Update a fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_uhk()

void eeprom_update_uhk ( unsigned short accum *  __p,
unsigned short accum  __value 
)

Update an unsigned short accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_uhr()

void eeprom_update_uhr ( unsigned short fract *  __p,
unsigned short fract  __value 
)

Update an unsigned short fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_uk()

void eeprom_update_uk ( unsigned accum *  __p,
unsigned accum  __value 
)

Update an unsigned accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_ulk()

void eeprom_update_ulk ( unsigned long accum *  __p,
unsigned long accum  __value 
)

Update an unsigned long accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_ullk()

void eeprom_update_ullk ( unsigned long long accum *  __p,
unsigned long long accum  __value 
)

Update an unsigned long long accum at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_ullr()

void eeprom_update_ullr ( unsigned long long fract *  __p,
unsigned long long fract  __value 
)

Update an unsigned long long fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_ulr()

void eeprom_update_ulr ( unsigned long fract *  __p,
unsigned long fract  __value 
)

Update an unsigned long fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_update_ur()

void eeprom_update_ur ( unsigned fract *  __p,
unsigned fract  __value 
)

Update an unsigned fract at EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_hk()

void eeprom_write_hk ( short accum *  __p,
short accum  __value 
)

Write a short accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_hr()

void eeprom_write_hr ( short fract *  __p,
short fract  __value 
)

Write a short fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_k()

void eeprom_write_k ( accum *  __p,
accum  __value 
)

Write an accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_lk()

void eeprom_write_lk ( long accum *  __p,
long accum  __value 
)

Write a long accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_llk()

void eeprom_write_llk ( long long accum *  __p,
long long accum  __value 
)

Write a long long accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_llr()

void eeprom_write_llr ( long long fract *  __p,
long long fract  __value 
)

Write a long long fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_lr()

void eeprom_write_lr ( long fract *  __p,
long fract  __value 
)

Write a long fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_r()

void eeprom_write_r ( fract *  __p,
fract  __value 
)

Write a fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_uhk()

void eeprom_write_uhk ( unsigned short accum *  __p,
unsigned short accum  __value 
)

Write an unsigned short accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_uhr()

void eeprom_write_uhr ( unsigned short fract *  __p,
unsigned short fract  __value 
)

Write an unsigned short fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_uk()

void eeprom_write_uk ( unsigned accum *  __p,
unsigned accum  __value 
)

Write an unsigned accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_ulk()

void eeprom_write_ulk ( unsigned long accum *  __p,
unsigned long accum  __value 
)

Write an unsigned long accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_ullk()

void eeprom_write_ullk ( unsigned long long accum *  __p,
unsigned long long accum  __value 
)

Write an unsigned long long accum to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_ullr()

void eeprom_write_ullr ( unsigned long long fract *  __p,
unsigned long long fract  __value 
)

Write an unsigned long long fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_ulr()

void eeprom_write_ulr ( unsigned long fract *  __p,
unsigned long fract  __value 
)

Write an unsigned long fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ eeprom_write_ur()

void eeprom_write_ur ( unsigned fract *  __p,
unsigned fract  __value 
)

Write an unsigned fract to EEPROM address __p.

Since
AVR-LibC v2.3

◆ 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

◆ pgm_read_hk()

static short accum pgm_read_hk ( const short accum *  addr)
inlinestatic

Read a short accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_hk_far()

static short accum pgm_read_hk_far ( uint_farptr_t  addr)
inlinestatic

Read a short accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_hr()

static short fract pgm_read_hr ( const short fract *  addr)
inlinestatic

Read a short fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_hr_far()

static short fract pgm_read_hr_far ( uint_farptr_t  addr)
inlinestatic

Read a short fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_k()

static accum pgm_read_k ( const accum *  addr)
inlinestatic

Read an accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_k_far()

static accum pgm_read_k_far ( uint_farptr_t  addr)
inlinestatic

Read an accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_lk()

static long accum pgm_read_lk ( const long accum *  addr)
inlinestatic

Read a long accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_lk_far()

static long accum pgm_read_lk_far ( uint_farptr_t  addr)
inlinestatic

Read a long accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_llk()

static long long accum pgm_read_llk ( const long long accum *  addr)
inlinestatic

Read a long long accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_llk_far()

static long long accum pgm_read_llk_far ( uint_farptr_t  addr)
inlinestatic

Read a long long accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_llr()

static long long fract pgm_read_llr ( const long long fract *  addr)
inlinestatic

Read a long long fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_llr_far()

static long long fract pgm_read_llr_far ( uint_farptr_t  addr)
inlinestatic

Read a long long fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_lr()

static long fract pgm_read_lr ( const long fract *  addr)
inlinestatic

Read a long fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_lr_far()

static long fract pgm_read_lr_far ( uint_farptr_t  addr)
inlinestatic

Read a long fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_r()

static fract pgm_read_r ( const fract *  addr)
inlinestatic

Read a fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_r_far()

static fract pgm_read_r_far ( uint_farptr_t  addr)
inlinestatic

Read a fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_uhk()

static unsigned short accum pgm_read_uhk ( const unsigned short accum *  addr)
inlinestatic

Read an unsigned short accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_uhk_far()

static unsigned short accum pgm_read_uhk_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned short accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_uhr()

static unsigned short fract pgm_read_uhr ( const unsigned short fract *  addr)
inlinestatic

Read an unsigned short fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_uhr_far()

static unsigned short fract pgm_read_uhr_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned short fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_uk()

static unsigned accum pgm_read_uk ( const unsigned accum *  addr)
inlinestatic

Read an unsigned accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_uk_far()

static unsigned accum pgm_read_uk_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ulk()

static unsigned long accum pgm_read_ulk ( const unsigned long accum *  addr)
inlinestatic

Read an unsigned long accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ulk_far()

static unsigned long accum pgm_read_ulk_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned long accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ullk()

static unsigned long long accum pgm_read_ullk ( const unsigned long long accum *  addr)
inlinestatic

Read an unsigned long long accum from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ullk_far()

static unsigned long long accum pgm_read_ullk_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned long long accum from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ullr()

static unsigned long long fract pgm_read_ullr ( const unsigned long long fract *  addr)
inlinestatic

Read an unsigned long long fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ullr_far()

static unsigned long long fract pgm_read_ullr_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned long long fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ulr()

static unsigned long fract pgm_read_ulr ( const unsigned long fract *  addr)
inlinestatic

Read an unsigned long fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ulr_far()

static unsigned long fract pgm_read_ulr_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned long fract from far address addr. The address is in the program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ur()

static unsigned fract pgm_read_ur ( const unsigned fract *  addr)
inlinestatic

Read an unsigned fract from 16-bit address addr. The address is in the lower 64 KiB of program memory.

Since
AVR-LibC v2.3

◆ pgm_read_ur_far()

static unsigned fract pgm_read_ur_far ( uint_farptr_t  addr)
inlinestatic

Read an unsigned fract from far address addr. The address is in the program memory.

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

◆ sqrthk()

short accum sqrthk ( short accum  radic)

Square root of the value radic. Negative values are returned unchanged. The worst case execution time (WCET) is around 310 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

◆ sqrtk()

accum sqrtk ( accum  radic)

Square root of the value radic. Negative values are returned unchanged. The worst case execution time (WCET) is around 640 cycles.

Since
AVR-LibC v2.3

◆ sqrtlr()

long fract sqrtlr ( long fract  radic)

Square root of the value radic. Negative values are returned unchanged. The worst case execution time (WCET) is around 1080 cycles.

Since
AVR-LibC v2.3

◆ sqrtr()

fract sqrtr ( fract  radic)

Square root of the value radic. Negative values are returned unchanged. The worst case execution time (WCET) is around 320 cycles.

Since
AVR-LibC v2.3

◆ sqrtuhk()

unsigned short accum sqrtuhk ( unsigned short accum  radic)

Square root of the value radic rounded down. The worst case execution time (WCET) is around 300 cycles.

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

◆ sqrtuk()

unsigned accum sqrtuk ( unsigned accum  radic)

Square root of the value radic. The worst case execution time (WCET) is around 620 cycles.

Since
AVR-LibC v2.3

◆ sqrtulr()

unsigned long fract sqrtulr ( unsigned long fract  radic)

Square root of the value radic. The result is in the range [0, 1). The worst case execution time (WCET) is around 1060 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:146
#define FXTOA_ROUND
Definition: stdfix-avrlibc.h:128
  • 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