|On this page…|
Fixed-point numbers and their data types are characterized by their word size in bits, binary point, and whether they are signed or unsigned. The Fixed-Point Designer™ software supports integers and fixed-point numbers. The main difference among these data types is their binary point.
A common representation of a binary fixed-point number , either signed or unsigned, is shown in the following figure.
Computer hardware typically represents the negation of a binary fixed-point number in three different ways: sign/magnitude, one's complement, and two's complement. Two's complement is the preferred representation of signed fixed-point numbers and supported by the Fixed-Point Designer software.
Negation using two's complement consists of a bit inversion (translation into one's complement) followed by the addition of a one. For example, the two's complement of 000101 is 111011.
Whether a fixed-point value is signed or unsigned is usually not encoded explicitly within the binary word; that is, there is no sign bit. Instead, the sign information is implicitly defined within the computer architecture.
The binary point is the means by which fixed-point numbers are scaled. It is usually the software that determines the binary point. When performing basic math functions such as addition or subtraction, the hardware uses the same logic circuits regardless of the value of the scale factor. In essence, the logic circuits have no knowledge of a scale factor. They are performing signed or unsigned fixed-point binary algebra as if the binary point is to the right of b0.
Fixed-Point Designer supports the general binary point scaling . V is the real-world value, Q is the stored integer value, and E is equal to -FractionLength. In other words, RealWorldValue = StoredInteger * 2 ^ -FractionLength.
FractionLength defines the scaling of the stored integer value. The word length limits the values that the stored integer can take, but it does not limit the values FractionLength can take. The software does not restrict the value of exponent E based on the word length of the stored integer Q. Because E is equal to -FractionLength, restricting the binary point to being contiguous with the fraction is unnecessary; the fraction length can be negative or greater than the word length.
For example, a word consisting of three unsigned bits is usually represented in scientific notation in one of the following ways.
If the exponent were greater than 0 or less than -3, then the representation would involve lots of zeros.
These extra zeros never change to ones, however, so they don't show up in the hardware. Furthermore, unlike floating-point exponents, a fixed-point exponent never shows up in the hardware, so fixed-point exponents are not limited by a finite number of bits.
Consider a signed value with a word length of 8, a fraction
length of 10, and a stored integer value of 5 (binary value 00000101).
The real-word value is calculated using the formula
RealWorldValue = StoredInteger * 2 ^ -FractionLength. In this case, RealWorldValue = 5 * 2 ^ -10 = 0.0048828125. Because the fraction length is 2 bits longer than the word length, the binary value of the stored integer is x.xx00000101 , where x is a placeholder for implicit zeros. 0.0000000101 (binary) is equivalent to 0.0048828125 (decimal). For an example using a fi object, see Create a fi Object With Fraction Length Greater Than Word Length.
The dynamic range of fixed-point numbers is much less than floating-point numbers with equivalent word sizes. To avoid overflow conditions and minimize quantization errors, fixed-point numbers must be scaled.
With the Fixed-Point Designer software, you can select a fixed-point data type whose scaling is defined by its binary point, or you can select an arbitrary linear scaling that suits your needs. This section presents the scaling choices available for fixed-point data types.
V is an arbitrarily precise real-world value.
is the approximate real-world value.
Q, the stored value, is an integer that encodes V.
is the slope.
B is the bias.
The slope is partitioned into two components:
specifies the binary point. E is the fixed power-of-two exponent.
F is the slope adjustment factor. It is normalized such that .
The scaling modes available to you within this encoding scheme are described in the sections that follow. For detailed information about how the supported scaling modes effect fixed-point operations, refer to Recommendations for Arithmetic and Scaling.
Binary-point-only or power-of-two scaling involves moving the binary point within the fixed-point word. The advantage of this scaling mode is to minimize the number of processor arithmetic operations.
With binary-point-only scaling, the components of the general slope and bias formula have the following values:
F = 1
The scaling of a quantized real-world number is defined by the slope S, which is restricted to a power of two. The negative of the power-of-two exponent is called the fraction length. The fraction length is the number of bits to the right of the binary point. For Binary-Point-Only scaling, specify fixed-point data types as
signed types — fixdt(1, WordLength, FractionLength)
unsigned types — fixdt(0, WordLength, FractionLength)
Integers are a special case of fixed-point data types. Integers have a trivial scaling with slope 1 and bias 0, or equivalently with fraction length 0. Specify integers as
signed integer — fixdt(1, WordLength, 0)
unsigned integer — fixdt(0, WordLength, 0)
When you scale by slope and bias, the slope S and bias B of the quantized real-world number can take on any value. The slope must be a positive number. Using slope and bias, specify fixed-point data types as
fixdt(Signed, WordLength, Slope, Bias)
Specify fixed-point data types with an unspecified scaling as
Simulink® signals, parameters, and states must never have unspecified scaling. When scaling is unspecified, you must use some other mechanism such as automatic best precision scaling to determine the scaling that the Simulink software uses.
The quantization Q of a real-world value V is represented by a weighted sum of bits. Within the context of the general slope and bias encoding scheme, the value of an unsigned fixed-point quantity is given by
while the value of a signed fixed-point quantity is given by
are binary digits, with , for
The word size in bits is given by ws, with ws = 1, 2, 3,..., 128.
S is given by , where the scaling is unrestricted because the binary point does not have to be contiguous with the word.
Formats for 8-bit signed and unsigned fixed-point values are shown in the following figure.
Note that you cannot discern whether these numbers are signed or unsigned data types merely by inspection since this information is not explicitly encoded within the word.
The binary number 0011.0101 yields the same value for the unsigned and two's complement representation because the MSB = 0. Setting B = 0 and using the appropriate weights, bit multipliers, and scaling, the value is
Conversely, the binary number 1011.0101 yields different values for the unsigned and two's complement representation since the MSB = 1.
Setting B = 0 and using the appropriate weights, bit multipliers, and scaling, the unsigned value is
while the two's complement value is
The range of a number gives the limits of the representation, while the precision gives the distance between successive numbers in the representation. The range and precision of a fixed-point number depend on the length of the word and the scaling.
The following figure illustrates the range of representable numbers for an unsigned fixed-point number of size ws, scaling S, and bias B.
The following figure illustrates the range of representable numbers for a two's complement fixed-point number of size ws, scaling S, and bias B where the values of ws, scaling S, and bias B allow for both negative and positive numbers.
For both the signed and unsigned fixed-point numbers of any data type, the number of different bit patterns is 2ws.
For example, if the fixed-point data type is an integer with scaling defined as and B = 0, then the maximum unsigned value is , because zero must be represented. In two's complement, negative numbers must be represented as well as zero, so the maximum value is . Additionally, since there is only one representation for zero, there must be an unequal number of positive and negative numbers. This means there is a representation for but not for .
The precision of a data type is given by the slope. In this usage, precision means the difference between neighboring representable values.
The low limit, high limit, and default binary-point-only scaling for the supported fixed-point data types discussed in Binary Point Interpretation are given in the following table. See Precision and Range for more information.
Fixed-Point Data Type Range and Default Scaling
Default Scaling (~Precision)
Unsigned Binary Point
|Signed Binary Point|
Unsigned Slope Bias
|Signed Slope Bias|
s = Slope, b = Bias, ws = WordLength, fl = FractionLength
The precisions, range of signed values, and range of unsigned values for an 8-bit generalized fixed-point data type with binary-point-only scaling are listed in the follow table. Note that the first scaling value (21) represents a binary point that is not contiguous with the word.
Range of Signed Values (Low, High)
Range of Unsigned Values (Low, High)
The precision and ranges of signed and unsigned values for an 8-bit fixed-point data type using slope and bias scaling are listed in the following table. The slope starts at a value of 1.25 with a bias of 1.0 for all slopes. Note that the slope is the same as the precision.
Range of Signed Values (low, high)
Range of Unsigned Values (low, high)