10.2 Data Types
All 12 of the primary fixed-point types and their aliases, described in section 4.1 “Overview and principles of the fixed-point data types” of N1169, are supported via three fixed point formats corresponding to the intrinsic hardware capabilities of Microchip DSC devices.
Format | Description |
---|---|
1.15 | 1 bit sign, 15 bits fraction |
1.31 | 1 bit sign, 31 bits fraction |
9.31 | 9 bit signed integer, 31 bits fraction |
These formats represent the fixed-point C data types, shown below.
Type | Format |
---|---|
_Fract |
1.15 |
short _Fract |
1.15 |
signed _Fract |
1.15 |
signed short _Fract |
1.15 |
unsigned _Fract |
1.15 (sign bit 0) |
unsigned short
_Fract |
1.15 (sign bit 0) |
long _Fract |
1.31 |
signed long _Fract |
1.31 |
unsigned long _Fract |
1.31 (sign bit 0) |
_Accum |
9.31 |
short _Accum |
9.31 |
long _Accum |
9.31 |
signed _Accum |
9.31 |
signed short _Accum |
9.31 |
signed long _Accum |
9.31 |
unsigned _Accum |
9.31 (sign bit 0) |
unsigned short
_Accum |
9.31 (sign bit 0) |
unsigned long _Accum |
9.31 (sign bit 0) |
The _Sat
type specifier, indicating that the values are
saturated, may be used with any type as described in N1169.
Unsigned types are represented identically to signed types, but negative numbers (sign bit 1) are not valid values in the unsigned types. Signed types saturate at the most negative and positive numbers representable in the underlying format. Unsigned types saturate at 0 and the most positive number representable in the format.
The default behavior of overflow on signed or unsigned types is not
saturation (as defined by the pragmas described in section 4.1.3 “Rounding and Overflow” of
N1169). Therefore variables in signed or unsigned types that are not declared as saturating
with the _Sat
specifier may receive invalid values when assigned the
result of an expression in which an overflow may occur (the results of non-saturating
overflows are not defined.)