<stdfix.h>
[added with TR18037]
accum
· fract
· sat
· ACCUM_EPSILON
· ACCUM_FBIT
· ACCUM_IBIT
· ACCUM_MAX
· ACCUM_MIN
· FRACT_EPSILON
· FRACT_FBIT
· FRACT_MAX
· FRACT_MIN
· LACCUM_EPSILON
· LACCUM_FBIT
· LACCUM_IBIT
· LACCUM_MAX
· LACCUM_MIN
· LFRACT_EPSILON
· LFRACT_FBIT
· LFRACT_MAX
· LFRACT_MIN
· SACCUM_EPSILON
· SACCUM_FBIT
· SACCUM_IBIT
· SACCUM_MAX
· SACCUM_MIN
· SFRACT_EPSILON
· SFRACT_FBIT
· SFRACT_MAX
· SFRACT_MIN
· UACCUM_EPSILON
· UACCUM_FBIT
· UACCUM_IBIT
· UACCUM_MAX
· UFRACT_EPSILON
· UFRACT_FBIT
· UFRACT_MAX
· ULACCUM_EPSILON
· ULACCUM_FBIT
· ULACCUM_IBIT
· ULACCUM_MAX
· ULFRACT_EPSILON
· ULFRACT_FBIT
· ULFRACT_MAX
· USACCUM_EPSILON
· USACCUM_FBIT
· USACCUM_IBIT
· USACCUM_MAX
· USFRACT_EPSILON
· USFRACT_FBIT
· USFRACT_MAX
int_hk_t
· int_hr_t
· int_k_t
· int_lk_t
· int_lr_t
· int_r_t
· uint_uhk_t
· uint_uhr_t
· uint_uk_t
· uint_ulk_t
· uint_ulr_t
· uint_ur_t
abshk
· abshr
· absk
· abslk
· abslr
· absr
· bitshk
· bitshr
· bitsk
· bitslk
· bitslr
· bitsr
· bitsuhk
· bitsuhr
· bitsuk
· bitsulk
· bitsulr
· bitsur
· countlshk
· countlshr
· countlsk
· countlslk
· countlslr
· countlsr
· countlsuhk
· countlsuhr
· countlsuk
· countlsulk
· countlsulr
· countlsur
· divik
· divilk
· divilr
· divir
· diviuk
· diviulk
· diviulr
· diviur
· hkbits
· hrbits
· idivk
· idivlk
· idivlr
· idivr
· idivuk
· idivulk
· idivulr
· idivur
· kbits
· kdivi
· lkbits
· lkdivi
· lrbits
· lrdivi
· mulik
· mulilk
· mulilr
· mulir
· muliuk
· muliulk
· muliulr
· muliur
· rbits
· rdivi
· roundhk
· roundhr
· roundk
· roundlk
· roundlr
· roundr
· rounduhk
· rounduhr
· rounduk
· roundulk
· roundulr
· roundur
· strtofxhk
· strtofxhr
· strtofxk
· strtofxlk
· strtofxlr
· strtofxr
· strtofxuhk
· strtofxuhr
· strtofxuk
· strtofxulk
· strtofxulr
· strtofxur
· uhkbits
· uhrbits
· ukbits
· ukdivi
· ulkbits
· ulkdivi
· ulrbits
· ulrdivi
· urbits
· urdivi
Include the added header <stdfix.h>
to define numerous functions that operate on the fixed-point types.
Note that the use of this header does not require
the additions to the C language mandated by TR18037, which
include twelve additional scalar types and corresponding literals.
For a software implementation of the fixed-point operations,
suitable for supplementing the inline code generated by a compiler,
see the header "fixed.h"
also supplied with this
implementation.
You can use a handy subset of these functions through extra macros and types defined in this header. All use a set of twelve suffixes that denote the twelve fixed-point types:
SUFFIX TYPE hr signed short _Fract r signed _Fract lr signed long _Fract uhr unsigned short _Fract ur unsigned _Fract ulr unsigned long _Fract hk signed short _Accum k signed _Accum lk signed long _Accum uhk unsigned short _Accum uk unsigned _Accum ulk unsigned long _Accum
Thus, the type _Fixed_hk
is one of twelve types
defined in this header (whether or not language support is present).
These are structure types that you can declare, assign, convert to text
with the Formatted Output functions such as
printf
, convert from text
with the Formatted Input functions such as
scanf
, and use with all the
functions declared in this header.
The accompanying macros are:
FIXED_SET(suffix, double_val)
converts the double
value double_val
to
the fixed-point type determined by suffix
.
Thus, you can write the runtime expression
FIXED_SET(ulk, 3.5)
as a substitute for the fixed-point literal
3.5ulk
.FIXED_GET(suffix, fixed_val)
converts the fixed-point value fixed_val
to double
.FIXED_ADD(suffix, fixed_val1, fixed_val2)
yields the fixed-point value fixed_val1 + fixed_val2
.FIXED_SUB(suffix, fixed_val1, fixed_val2)
yields the fixed-point value fixed_val1 - fixed_val2
.FIXED_MUL(suffix, fixed_val1, fixed_val2)
yields the fixed-point value fixed_val1 * fixed_val2
.FIXED_DIV(suffix, fixed_val1, fixed_val2)
yields the fixed-point value fixed_val1 / fixed_val2
.FIXED_LSH(suffix, fixed_val, int_va)
yields the fixed-point value fixed_val << int_val
.FIXED_RSH(suffix, fixed_val, int_va)
yields the fixed-point value fixed_val >> int_val
.FIXED_NEGATE(suffix, fixed_val
yields the fixed-point value -fixed_val
.FIXED_EQ(suffix, fixed_val1, fixed_val2)
yields the integer value fixed_val1 == fixed_val2
.FIXED_LT(suffix, fixed_val1, fixed_val2)
yields the integer value fixed_val1 < fixed_val2
./* MACROS */ #define accum _Accum #define fract _Fract #define sat _Sat /* fractional bits macros */ #define SFRACT_FBIT <#if expression> (7) #define FRACT_FBIT <#if expression> (15) #define LFRACT_FBIT <#if expression> (31) #define USFRACT_FBIT <#if expression> (8) #define UFRACT_FBIT <#if expression> (16) #define ULFRACT_FBIT <#if expression> (32) #define SACCUM_FBIT <#if expression> (7) #define ACCUM_FBIT <#if expression> (15) #define LACCUM_FBIT <#if expression> (31) #define USACCUM_FBIT <#if expression> (8) #define UACCUM_FBIT <#if expression> (16) #define ULACCUM_FBIT <#if expression> (32) /* integer bits macros */ #define SACCUM_IBIT <#if expression> (8) #define ACCUM_IBIT <#if expression> (16) #define LACCUM_IBIT <#if expression> (32) #define USACCUM_IBIT <#if expression> (8) #define UACCUM_IBIT <#if expression> (16) #define ULACCUM_IBIT <#if expression> (32) /* minimum value macros */ #define SFRACT_MIN <signed short _Fract expression> #define FRACT_MIN <signed _Fract expression> #define LFRACT_MIN <signed long _Fract expression> #define SACCUM_MIN <signed short _Accum expression> #define ACCUM_MIN <signed _Accum expression> #define LACCUM_MIN <signed long _Accum expression> /* maximum value macros */ #define SFRACT_MAX <signed short _Fract expression> #define FRACT_MAX <signed _Fract expression> #define LFRACT_MAX <signed long _Fract expression> #define USFRACT_MAX <unsigned short _Fract expression> #define UFRACT_MAX <unsigned _Fract expression> #define ULFRACT_MAX <unsigned long _Fract expression> #define SACCUM_MAX <signed short _Accum expression> #define ACCUM_MAX <signed _Accum expression> #define LACCUM_MAX <signed long _Accum expression> #define USACCUM_MAX <unsigned short _Accum expression> #define UACCUM_MAX <unsigned _Accum expression> #define ULACCUM_MAX <unsigned long _Accum expression> /* epsilon macros */ #define SFRACT_EPSILON <signed short _Fract expression> #define FRACT_EPSILON <signed _Fract expression> #define LFRACT_EPSILON <signed long _Fract expression> #define USFRACT_EPSILON <unsigned short _Fract expression> #define UFRACT_EPSILON <unsigned _Fract expression> #define ULFRACT_EPSILON <unsigned long _Fract expression> #define SACCUM_EPSILON <signed short _Accum expression> #define ACCUM_EPSILON <signed _Accum expression> #define LACCUM_EPSILON <signed long _Accum expression> #define USACCUM_EPSILON <unsigned short _Accum expression> #define UACCUM_EPSILON <unsigned _Accum expression> #define ULACCUM_EPSILON <unsigned long _Accum expression> /* TYPES */ typedef i-type int_hr_t; typedef i-type int_r_t; typedef i-type int_lr_t; typedef ui-type uint_uhr_t; typedef ui-type uint_ur_t; typedef ui-type uint_ulr_t; typedef i-type int_hk_t; typedef i-type int_k_t; typedef i-type int_lk_t; typedef ui-type uint_uhk_t; typedef ui-type uint_uk_t; typedef ui-type uint_ulk_t; /* FUNCTIONS */ signed int mulir(signed int x, signed _Fract y); signed long mulilr(signed long x, signed long _Fract y); signed int mulik(signed int x, signed _Accum y); signed long mulilk(signed long x, signed long _Accum y); unsigned int muliur(unsigned int x, unsigned _Fract y); unsigned long muliulr(unsigned long x, unsigned long _Fract y); unsigned int muliuk(unsigned int x, unsigned _Accum y); unsigned long muliulk(unsigned long x, unsigned long _Accum y); signed int divir(signed int x, signed _Fract y); signed long divilr(signed long x, signed long _Fract y); signed int divik(signed int x, signed _Accum y); signed long divilk(signed long x, signed long _Accum y); unsigned int diviur(unsigned int x, unsigned _Fract y); unsigned long diviulr(unsigned long x, unsigned long _Fract y); unsigned int diviuk(unsigned int x, unsigned _Accum y); unsigned long diviulk(unsigned long x, unsigned long _Accum y); signed int idivr(signed _Fract x, signed _Fract y); signed long idivlr(signed long _Fract x, signed long _Fract y); signed int idivk(signed _Accum x, signed _Accum y); signed long idivlk(signed long _Accum x, signed long _Accum y); unsigned int idivur(unsigned _Fract x, unsigned _Fract y); unsigned long idivulr(unsigned long _Fract x, unsigned long _Fract y); unsigned int idivuk(unsigned _Accum x, unsigned _Accum y); unsigned long idivulk(unsigned long _Accum x, unsigned long _Accum y); signed _Fract rdivi(signed int x, signed int y); signed long _Fract lrdivi(signed long x, signed long y); signed _Accum kdivi(signed int x, signed int y); signed long _Accum lkdivi(signed long x, signed long y); unsigned _Fract urdivi(unsigned int x, unsigned int y); unsigned long _Fract ulrdivi(unsigned long x, unsigned long y); unsigned _Accum ukdivi(unsigned int x, unsigned int y); unsigned long _Accum ulkdivi(unsigned long x, unsigned long y); signed short _Fract abshr(signed short _Fract x); signed _Fract absr(signed _Fract x); signed long _Fract abslr(signed long _Fract x); signed short _Accum abshk(signed short _Accum x); signed _Accum absk(signed _Accum x); signed long _Accum abslk(signed long _Accum x); signed short _Fract roundhr(signed short _Fract x, int y); signed _Fract roundr(signed _Fract x, int y); signed long _Fract roundlr(signed long _Fract x, int y); signed short _Accum roundhk(signed short _Accum x, int y); signed _Accum roundk(signed _Accum x, int y); signed long _Accum roundlk(signed long _Accum x, int y); unsigned short _Fract rounduhr(unsigned short _Fract x, int y); unsigned _Fract roundur(unsigned _Fract x, int y); unsigned long _Fract roundulr(unsigned long _Fract x, int y); unsigned short _Accum rounduhk(unsigned short _Accum x, int y); unsigned _Accum rounduk(unsigned _Accum x, int y); unsigned long _Accum roundulk(unsigned long _Accum x, int y); int countlshr(signed short _Fract x); int countlsr(signed _Fract x); int countlslr(signed long _Fract x); int countlshk(signed short _Accum x); int countlsk(signed _Accum x); int countlslk(signed long _Accum x); int countlsuhr(unsigned short _Fract x); int countlsur(unsigned _Fract x); int countlsulr(unsigned long _Fract x); int countlsuhk(unsigned short _Accum x); int countlsuk(unsigned _Accum x); int countlsulk(unsigned long _Accum x); int_hr_t bitshr(signed short _Fract x); int_r_t bitsr(signed _Fract x); int_lr_t bitslr(signed long _Fract x); int_hk_t bitshk(signed short _Accum x); int_k_t bitsk(signed _Accum x); int_lk_t bitslk(signed long _Accum x); uint_uhr_t bitsuhr(unsigned short _Fract x); uint_ur_t bitsur(unsigned _Fract x); uint_ulr_t bitsulr(unsigned long _Fract x); uint_uhk_t bitsuhk(unsigned short _Accum x); uint_uk_t bitsuk(unsigned _Accum x); uint_ulk_t bitsulk(unsigned long _Accum x); signed short _Fract hrbits(int x); signed _Fract rbits(int x); signed long _Fract lrbits(int x); signed short _Accum hkbits(int x); signed _Accum kbits(int x); signed long _Accum lkbits(int x); unsigned short _Fract uhrbits(unsigned int x); unsigned _Fract urbits(unsigned int x); unsigned long _Fract ulrbits(unsigned int x); unsigned short _Accum uhkbits(unsigned int x); unsigned _Accum ukbits(unsigned int x); unsigned long _Accum ulkbits(unsigned int x); signed short _Fract strtofxhr(const char *restrict s, char **restrict endptr); signed _Fract strtofxr(const char *restrict x, char **restrict endptr); signed long _Fract strtofxlr(const char *restrict s, char **restrict endptr); signed short _Accum strtofxhk(const char *restrict s, char **restrict endptr); signed _Accum strtofxk(const char *restrict s, char **restrict endptr); signed long _Accum strtofxlk(const char *restrict s, char **restrict endptr); unsigned short _Fract strtofxuhr(const char *restrict s, char **restrict endptr); unsigned _Fract strtofxur(const char *restrict s, char **restrict endptr); unsigned long _Fract strtofxulr(const char *restrict s, char **restrict endptr); unsigned short _Accum strtofxuhk(const char *restrict s, char **restrict endptr); unsigned _Accum strtofxuk(const char *restrict s, char **restrict endptr); unsigned long _Accum strtofxulk(const char *restrict s, char **restrict endptr); /* GENERICS */ fx-type absfx(fx-type x); int countlsfx(fx-type x); fx-type roundfx(fx-type x, int y);
All functions in this header manipulate fixed-point values, all of which are integer values scaled to represent a fixed number of fraction bits. The twelve fixed-point types have three attributes:
signed
(two's complement) values,
or unsigned
(nonnegative) values.short
representation (fewer bits)
or a long
representation (more bits)._Fract
(fraction with no integer bits)
or an _Accum
(accumulator with both integer and fraction bits).A macro name reflects its related fixed-point type in its macro prefix, while a type or function name reflects its related fixed-point type in its prefix or suffix type tag. The corresponding data format consists of an optional sign bit, zero or more integer bits, and one or more fraction bits. The following table shows these attributes for the fixed-point types:
Macro Type Prefix Tag Format Type SFRACT hr S0.7 signed short _Fract FRACT r S0.15 signed _Fract LFRACT lr S0.31 signed long _Fract USFRACT uhr 0.8 unsigned short _Fract UFRACT ur 0.16 unsigned _Fract ULFRACT ulr 0.32 unsigned long _Fract SACCUM hk S7.8 signed short _Accum ACCUM k S15.16 signed _Accum LACCUM lk S31.32 signed long _Accum USACCUM uhk 8.8 unsigned short _Accum UACCUM uk 16.16 unsigned _Accum LACCUM ulk 32.32 unsigned long _Accum
The number of integer bits is determined by the six macros with names
*ACCUM_IBIT
, while the number of fraction bits is determined
by the twelve macros with names *_FBIT
. Note that the values
shown here are for this
implementation;
they need not be the same for other implementations.
(Within broad limits, you can change the supported formats simply
by changing the values of these 18 macros and recompiling the library.)
absfx
,
absk
,
abshk
,
abslk
,
absr
,
abshr
,
abslr
signed short _Fract abshr(signed short _Fract x); signed _Fract absr(signed _Fract x); signed long _Fract abslr(signed long _Fract x); signed short _Accum abshk(signed short _Accum x); signed _Accum absk(signed _Accum x); signed long _Accum abslk(signed long _Accum x); fx-type absfx(fx-type x); /* generic version */
The function returns the absolute value of x
.
accum
,
fract
,
sat
#define accum _Accum #define fract _Fract #define sat _Sat
The macros provide more readable forms of the keywords introduced with TR18037.
ACCUM_EPSILON
,
SACCUM_EPSILON
,
LACCUM_EPSILON
,
UACCUM_EPSILON
,
USACCUM_EPSILON
,
ULACCUM_EPSILON
,
FRACT_EPSILON
,
SFRACT_EPSILON
,
LFRACT_EPSILON
,
UFRACT_EPSILON
,
USFRACT_EPSILON
,
ULFRACT_EPSILON
#define SFRACT_EPSILON <signed short _Fract expression> #define FRACT_EPSILON <signed _Fract expression> #define LFRACT_EPSILON <signed long _Fract expression> #define USFRACT_EPSILON <unsigned short _Fract expression> #define UFRACT_EPSILON <unsigned _Fract expression> #define ULFRACT_EPSILON <unsigned long _Fract expression> #define SACCUM_EPSILON <signed short _Accum expression> #define ACCUM_EPSILON <signed _Accum expression> #define LACCUM_EPSILON <signed long _Accum expression> #define USACCUM_EPSILON <unsigned short _Accum expression> #define UACCUM_EPSILON <unsigned _Accum expression> #define ULACCUM_EPSILON <unsigned long _Accum expression>
The macros define the smallest positive nonzero values for each of the fixed-point types.
ACCUM_FBIT
,
SACCUM_FBIT
,
LACCUM_FBIT
,
UACCUM_FBIT
,
USACCUM_FBIT
,
ULACCUM_FBIT
,
FRACT_FBIT
,
SFRACT_FBIT
,
LFRACT_FBIT
,
UFRACT_FBIT
,
USFRACT_FBIT
,
ULFRACT_FBIT
#define SFRACT_FBIT <#if expression> (7) #define FRACT_FBIT <#if expression> (15) #define LFRACT_FBIT <#if expression> (31) #define USFRACT_FBIT <#if expression> (8) #define UFRACT_FBIT <#if expression> (16) #define ULFRACT_FBIT <#if expression> (32) #define SACCUM_FBIT <#if expression> (7) #define FRACT_FBIT <#if expression> (15) #define LACCUM_FBIT <#if expression> (31) #define USACCUM_FBIT <#if expression> (8) #define UACCUM_FBIT <#if expression> (16) #define ULACCUM_FBIT <#if expression> (32)
The macros define the number of fraction bits in each of the fixed-point types. The values in parentheses are those for this implementation.
ACCUM_IBIT
,
SACCUM_IBIT
,
LACCUM_IBIT
,
UACCUM_IBIT
,
USACCUM_IBIT
,
ULACCUM_IBIT
#define SACCUM_IBIT <#if expression> (8) #define FRACT_IBIT <#if expression> (16) #define LACCUM_IBIT <#if expression> (33) #define USACCUM_IBIT <#if expression> (8) #define UACCUM_IBIT <#if expression> (16) #define ULACCUM_IBIT <#if expression> (32)
The macros define the number of integer bits in each of the fixed-point accumulator types. The values in parentheses are those for this implementation.
ACCUM_MAX
,
SACCUM_MAX
,
LACCUM_MAX
,
UACCUM_MAX
,
USACCUM_MAX
,
ULACCUM_MAX
,
FRACT_MAX
,
SFRACT_MAX
,
LFRACT_MAX
,
UFRACT_MAX
,
USFRACT_MAX
,
ULFRACT_MAX
#define SFRACT_MAX <signed short _Fract expression> #define FRACT_MAX <signed _Fract expression> #define LFRACT_MAX <signed long _Fract expression> #define USFRACT_MAX <unsigned short _Fract expression> #define UFRACT_MAX <unsigned _Fract expression> #define ULFRACT_MAX <unsigned long _Fract expression> #define SACCUM_MAX <signed short _Accum expression> #define ACCUM_MAX <signed _Accum expression> #define LACCUM_MAX <signed long _Accum expression> #define USACCUM_MAX <unsigned short _Accum expression> #define UACCUM_MAX <unsigned _Accum expression> #define ULACCUM_MAX <unsigned long _Accum expression>
The macros define the maximum (most-positive) values for each of the fixed-point types.
ACCUM_MIN
,
SACCUM_MIN
,
LACCUM_MIN
,
FRACT_MIN
,
SFRACT_MIN
,
LFRACT_MIN
#define SFRACT_MIN <signed short _Fract expression> #define FRACT_MIN <signed _Fract expression> #define LFRACT_MIN <signed long _Fract expression> #define SACCUM_MIN <signed short _Accum expression> #define ACCUM_MIN <signed _Accum expression> #define LACCUM_MIN <signed long _Accum expression>
The macros define the minimum (most-negative) values for each of the signed fixed-point types.
bitsk
,
bitshk
,
bitslk
,
bitsuk
,
bitsuhk
,
bitsulk
,
bitsr
,
bitshr
,
bitslr
,
bitsur
,
bitsuhr
,
bitsulr
int_hr_t bitshr(signed short _Fract x); int_r_t bitsr(signed _Fract x); int_lr_t bitslr(signed long _Fract x); int_hk_t bitshk(signed short _Accum x); int_k_t bitsk(signed _Accum x); int_lk_t bitslk(signed long _Accum x); uint_uhr_t bitsuhr(unsigned short _Fract x); uint_ur_t bitsur(unsigned _Fract x); uint_ulr_t bitsulr(unsigned long _Fract x); uint_uhk_t bitsuhk(unsigned short _Accum x); uint_uk_t bitsuk(unsigned _Accum x); uint_ulk_t bitsulk(unsigned long _Accum x);
The function returns x << fbits
,
where fbits
is the number of fraction bits in the
related fixed-point type.
(It returns the bit pattern as an integer value.)
countlsfx
,
countlsk
,
countlshk
,
countlslk
,
countlsuk
,
countlsuhk
,
countlsulk
,
countlsr
,
countlshr
,
countlslr
,
countlsur
,
countlsuhr
,
countlsulr
int countlshr(signed short _Fract x); int countlsr(signed _Fract x); int countlslr(signed long _Fract x); int countlshk(signed short _Accum x); int countlsk(signed _Accum x); int countlslk(signed long _Accum x); int countlsuhr(unsigned short _Fract x); int countlsur(unsigned _Fract x); int countlsulr(unsigned long _Fract x); int countlsuhk(unsigned short _Accum x); int countlsuk(unsigned _Accum x); int countlsulk(unsigned long _Accum x); int countlsfx(fx-type x); /* generic version */
The function returns the number of bits in the
related fixed-point type
if x
is zero;
otherwise it returns the largest value k
for
which x << k
does not overflow.
(It counts the leading zero bits.)
divik
,
divilk
,
divir
,
divilr
,
diviuk
,
diviulk
,
diviur
,
diviulr
signed int divir(signed int x, signed _Fract y); signed long divilr(signed long x, signed long _Fract y); signed int divik(signed int x, signed _Accum y); signed long divilk(signed long x, signed long _Accum y); unsigned int diviur(unsigned int x, unsigned _Fract y); unsigned long diviulr(unsigned long x, unsigned long _Fract y); unsigned int diviuk(unsigned int x, unsigned _Accum y); unsigned long diviulk(unsigned long x, unsigned long _Accum y);
The function returns the quotient x / y
rounded to
the nearest integer.
idivk
,
idivlk
,
idivr
,
idivlr
,
idivuk
,
idivulk
,
idivur
,
idivulr
signed int idivr(signed _Fract x, signed _Fract y); signed long idivlr(signed long _Fract x, signed long _Fract y); signed int idivk(signed _Accum x, signed _Accum y); signed long idivlk(signed long _Accum x, signed long _Accum y); unsigned int idivur(unsigned _Fract x, unsigned _Fract y); unsigned long idivulr(unsigned long _Fract x, unsigned long _Fract y); unsigned int idivuk(unsigned _Accum x, unsigned _Accum y); unsigned long idivulk(unsigned long _Accum x, unsigned long _Accum y);
The function returns the quotient x / y
rounded to
the nearest integer.
int_k_t
,
int_hk_t
,
int_lk_t
,
uint_uk_t
,
uint_uhk_t
,
uint_ulk_t
,
int_r_t
,
int_hr_t
,
int_lr_t
,
uint_ur_t
,
uint_uhr_t
,
uint_ulr_t
typedef i-type int_hr_t; typedef i-type int_r_t; typedef i-type int_lr_t; typedef ui-type uint_uhr_t; typedef ui-type uint_ur_t; typedef ui-type uint_ulr_t; typedef i-type int_hk_t; typedef i-type int_k_t; typedef i-type int_lk_t; typedef ui-type uint_uhk_t; typedef ui-type uint_uk_t; typedef ui-type uint_ulk_t;
The type is a signed (i-type
)
or unsigned (ui-type
) integer type
with the same number of bits as the
related fixed-point type.
kbits
,
hkbits
,
lkbits
,
ukbits
,
uhkbits
,
ulkbits
,
rbits
,
hrbits
,
lrbits
,
urbits
,
uhrbits
,
ulrbits
signed short _Fract hrbits(int x); signed _Fract rbits(int x); signed long _Fract lrbits(int x); signed short _Accum hkbits(int x); signed _Accum kbits(int x); signed long _Accum lkbits(int x); unsigned short _Fract uhrbits(unsigned int x); unsigned _Fract urbits(unsigned int x); unsigned long _Fract ulrbits(unsigned int x); unsigned short _Accum uhkbits(unsigned int x); unsigned _Accum ukbits(unsigned int x); unsigned long _Accum ulkbits(unsigned int x);
The function returns x >> fbits
,
where fbits
is the number of fraction bits in the
related fixed-point type.
(It returns the bit pattern as a fixed-point value.)
kdivi
,
lkdivi
,
rdivi
,
lrdivi
,
ukdivi
,
ulkdivi
,
urdivi
,
ulrdivi
signed _Fract rdivi(signed int x, signed int y); signed long _Fract lrdivi(signed long x, signed long y); signed _Accum kdivi(signed int x, signed int y); signed long _Accum lkdivi(signed long x, signed long y); unsigned _Fract urdivi(unsigned int x, unsigned int y); unsigned long _Fract ulrdivi(unsigned long x, unsigned long y); unsigned _Accum ukdivi(unsigned int x, unsigned int y); unsigned long _Accum ulkdivi(unsigned long x, unsigned long y);
The function returns the quotient x / y
rounded to the
related fixed-point type.
mulik
,
mulilk
,
mulir
,
mulilr
,
muliuk
,
muliulk
,
muliur
,
muliulr
signed int mulir(signed int x, signed _Fract y); signed long mulilr(signed long x, signed long _Fract y); signed int mulik(signed int x, signed _Accum y); signed long mulilk(signed long x, signed long _Accum y); unsigned int muliur(unsigned int x, unsigned _Fract y); unsigned long muliulr(unsigned long x, unsigned long _Fract y); unsigned int muliuk(unsigned int x, unsigned _Accum y); unsigned long muliulk(unsigned long x, unsigned long _Accum y);
The function returns the product x * y
rounded to
the nearest integer.
roundfx
,
roundk
,
roundhk
,
roundlk
,
rounduk
,
rounduhk
,
roundulk
,
roundr
,
roundhr
,
roundlr
,
roundur
,
rounduhr
,
roundulr
signed short _Fract roundhr(signed short _Fract x, int y); signed _Fract roundr(signed _Fract x, int y); signed long _Fract roundlr(signed long _Fract x, int y); signed short _Accum roundhk(signed short _Accum x, int y); signed _Accum roundk(signed _Accum x, int y); signed long _Accum roundlk(signed long _Accum x, int y); unsigned short _Fract rounduhr(unsigned short _Fract x, int y); unsigned _Fract roundur(unsigned _Fract x, int y); unsigned long _Fract roundulr(unsigned long _Fract x, int y); unsigned short _Accum rounduhk(unsigned short _Accum x, int y); unsigned _Accum rounduk(unsigned _Accum x, int y); unsigned long _Accum roundulk(unsigned long _Accum x, int y); fx-type roundfx(fx-type x, int y); /* generic version */
The function returns the representable value nearest to x
with all fraction bits zero after the y
most significant
bits. (It rounds to y
bits.)
strtofxk
,
strtofxhk
,
strtofxlk
,
strtofxuk
,
strtofxuhk
,
strtofxulk
,
strtofxr
,
strtofxhr
,
strtofxlr
,
strtofxur
,
strtofxuhr
,
strtofxulr
signed short _Fract strtofxhr(const char *restrict s, char **restrict endptr); signed _Fract strtofxr(const char *restrict x, char **restrict endptr); signed long _Fract strtofxlr(const char *restrict s, char **restrict endptr); signed short _Accum strtofxhk(const char *restrict s, char **restrict endptr); signed _Accum strtofxk(const char *restrict s, char **restrict endptr); signed long _Accum strtofxlk(const char *restrict s, char **restrict endptr); unsigned short _Fract strtofxuhr(const char *restrict s, char **restrict endptr); unsigned _Fract strtofxur(const char *restrict s, char **restrict endptr); unsigned long _Fract strtofxulr(const char *restrict s, char **restrict endptr); unsigned short _Accum strtofxuhk(const char *restrict s, char **restrict endptr); unsigned _Accum strtofxuk(const char *restrict s, char **restrict endptr); unsigned long _Accum strtofxulk(const char *restrict s, char **restrict endptr);
The function effectively returns
strtod(s, endptr)
.
(It converts the string at s
to a fixed-point value,
storing in *endptr
a pointer to the first unconverted character.)
See also the Table of Contents and the Index.
Copyright © 1992-2013 by P.J. Plauger. All rights reserved.