Digital Signal Processing Reference
In-Depth Information
types. In this case the result of the operation is calculated using the values of the
two operands, with their full precision . The result is rounded back to the required
fixed point type dictated by the ranking of the fixed point types. The same holds for
relational operators ( < , <= etc.). See Fig. 7 for a visualization.
The reason for this exception is that the normal conversion rules in C would
result in pointless expressions. For example 3 * 0.1r would either result in 0.1r ,
if 3 was converted to a Fract , or it would result in 0 ,if 0.1r was first converted
to an integral type. With this exception the result is 0.3r , which was deemed to
make more sense.
If an unsigned fixed point type is combined with signed fixed point type,
then the unsigned value is first converted to its corresponding signed value
and the result will also have this type. See Fig. 8 for a visualization. If any of the
operands was of a saturated type, then the result of the operation is also saturated.
If one of the operands in an expression is a saturating fixed point type, then the
result is also a saturating fixed point type. See Fig. 9 for a visualization.
The efficiency of the machine code generated for such combinations highly
depends on the support in the architecture. Most processors with fixed point
hardware support do not support such mixed operations, and the generated code
will emulate the calculation using regular integral arithmetic.
With the exception of bitwise and & ,or | and exclusive or ˆ all operations on
fixed point types are supported.
3.4
Fixed Point Support Functions
As described in the previous section, all operations on combinations of integral
and fixed point types will yield a fixed point type. Other combinations are supported
through special support functions. The value returned by these functions are defined
similarly as for the regular operators: the result value is first calculated using the
exact value of the operands and then rounded according the result type. If the result
type is an integral type, then overflow results in undefined behavior.
Embedded C also specifies some useful support functions for which there is no
operator.
Figure 10 describes the various support functions, where the replacement for fx
refers to a qualified fixed point type using the suffices as also used for fixed point
constants. The integral types involved in these functions use the same qualifiers as
the involved fixed point type, unless stated otherwise.
Figure 11 shows the four new conversion specifiers used for the new fixed point
types and the standard length modifiers that also apply to the conversions specifiers
for fixed point types. The specification of precision and length is similar to that of
floating point formatter f .
Search WWH ::




Custom Search