Classes Fix16
, Fix24
, Fix32
, and Fix48
support operations on 16, 24, 32, or 48 bit quantities that are
considered as real numbers in the range [-1, +1). Such numbers are
often encountered in digital signal processing applications. The classes
may be be used in isolation or together. Class Fix32
operations are entirely self-contained. Class Fix16
operations
are self-contained except that the multiplication operation Fix16
* Fix16
returns a Fix32
. Fix24
and Fix48
are
similarly related.
The standard arithmetic and relational operations are supported
(=
, +
, -
, *
, /
, <<
, >>
,
+=
, -=
, *=
, /=
, <<=
, >>=
,
==
, !=
, <
, <=
, >
, >=
).
All operations include provisions for special handling in cases where
the result exceeds +/- 1.0. There are two cases that may be handled
separately: "overflow" where the results of addition and subtraction
operations go out of range, and all other "range errors" in which
resulting values go off-scale (as with division operations, and
assignment or initialization with off-scale values). In signal
processing applications, it is often useful to handle these two cases
differently. Handlers take one argument, a reference to the integer
mantissa of the offending value, which may then be manipulated. In
cases of overflow, this value is the result of the (integer) arithmetic
computation on the mantissa; in others it is a fully saturated (i.e.,
most positive or most negative) value. Handling may be reset to any of
several provided functions or any other user-defined function via
set_overflow_handler
and set_range_error_handler
. The
provided functions for Fix16
are as follows (corresponding
functions are also supported for the others).
Fix16_overflow_saturate
Fix16_ignore
Fix16_overflow_warning_saturate
Fix16_warning
Fix16_abort
In addition to arithmetic operations, the following are provided:
Fix16 a = 0.5;
short& mantissa(a); long& mantissa(b);
double value(a); double value(b);