Digital Signal Processing Reference
In-Depth Information
Fig. 3
Constraints on the
various sizes of the fixed
point types
f
(
short
-
Fract
)
≤
f
(
-
Fract
)
≤
f
(
long
-
Fract
)
i
(
short
-
Fract
)=
i
(
-
Fract
)=
i
(
long
-
Fract
) =
0
f
(
short
-
Accum
)=
f
(
short
-
Fract
)
(recommended)
f
(
-
Accum
) =
f
(
-
Fract
)
(recommended)
(recommended)
i
(
short
-
Accum
)
≤
i
(
Accum
)
≤
i
(
longAccum
)
f
f
(
long
-
Accum
) =
f
(
long
-
Fract
)
(
short
-
Fract
)
≥
7
15
f
(
long
-
Fract
)
≥
23 (31 recommended)
i
f
(
-
Fract
)
≥
(
short
-
Accum
)
≥
4 (8 recommended)
(
-
Accum
)
≥
i
4 (8 recommended)
i
(
long
-
Accum
)
≥
4 (8 recommended)
f
is the number of fractional bits,
i
(
type
)
the number integral bits of a type.
(
type
)
The recommended values and constraints do not have to be supported by a
compiler, however if supported it would improve portability of applications across
different architectures.
The actual sizes of the implementation will be highly dependent on the architec-
ture targeted by the compiler. It can be expected that different architectures for the
same application domain will have converging sizes of their fixed point hardware,
because the application domain will dictate a certain precision.
3.2
Fixed Point Constants
Fixed point constants look just like floating point constants, except for a suffix that
specifies the exact type of the constant. The
r
is used to specify a
Fract
and
the
k
for the
Accum
.The
h
is used for
short
and the
l
is used for
long
.The
u
is used for
unsigned
.So
0.5uhr
specifies an
unsigned short Fract
constant, whereas
0.5lk
specifies a
signed long Accum
. All constants must
be within the range of their types, with the exception of 1
.
0 that can be used to
2
f
(
Fract
)
,where
specify the largest possible value of a
Fract
type, that is 1
.
0
−
1
/
f
(
Fract
)
Figure
4
lists all the suffices for fixed point constants and their implied type.
3.3
Fixed Point Conversions and Arithmetical Operations
Conversions involving fixed point follow similar rules in C as apply to integer. This
means that the types of the operands determine the type of the operation through a
ranking order and the rounding and overflow are dictated by this destination type.
Conversion from a fixed point type to an integral type uses rounding towards zero.