fixed-凯发k8网页登录

main content

fixed-point concepts and terminology

fixed-point data types

in digital hardware, numbers are stored in binary words. a binary word is a fixed-length sequence of bits (1's and 0's). the way hardware components or software functions interpret this sequence of 1's and 0's is defined by the data type.

binary numbers are represented as either floating-point or fixed-point data types. in this section, we discuss many terms and concepts relating to fixed-point numbers, data types, and mathematics.

a fixed-point data type is characterized by the word length in bits, the position of the binary point, and the signedness of a number which can be signed or unsigned. signed numbers and data types can represent both positive and negative values, whereas unsigned numbers and data types can only represent values that are greater than or equal to zero.

the position of the binary point is the means by which fixed-point values are scaled and interpreted.

for example, a binary representation of a generalized fixed-point number (either signed or unsigned) is shown below:

where

  • bi is the ith binary digit.

  • wl is the number of bits in a binary word, also known as word length.

  • bwl–1 is the location of the most significant, or highest, bit (msb). in signed binary numbers, this bit is the sign bit which indicates whether the number is positive or negative.

  • b0 is the location of the least significant, or lowest, bit (lsb). this bit in the binary word can represent the smallest value. the weight of the lsb is given by:

    weightlsb=2fractionlength

    where, fractionlength is the number of bits to the right of the binary point.

  • bits to the left of the binary point are integer bits and/or sign bits, and bits to the right of the binary point are fractional bits. number of bits to the left of the binary point is known as the integer length. the binary point in this example is shown four places to the left of the lsb. therefore, the number is said to have four fractional bits, or a fraction length of four.

fixed-point data types can be either signed or unsigned.

signed binary fixed-point numbers are typically represented in one of three ways:

  • sign/magnitude –– representation of signed fixed-point or floating-point numbers. in the sign/magnitude representation, one bit of a binary word is always the dedicated sign bit, while the remaining bits of the word encode the magnitude of the number. negation using sign/magnitude representation consists of flipping the sign bit from 0 (positive) to 1 (negative), or from 1 to 0.

  • one's complement

  • two's complement –– two's complement is the most common representation of signed fixed-point numbers. see for more information.

unsigned fixed-point numbers can only represent numbers greater than or equal to zero.

scaling

in [slope bias] representation, fixed-point numbers can be encoded according to the scheme

real-world value=(slope×integer) bias

where the slope can be expressed as

slope=slope adjustment×2exponent

the term slope adjustment is sometimes used as a synonym for fractional slope.

in the trivial case, slope = 1 and bias = 0. scaling is always trivial for pure integers, such as int8, and also for the true floating-point types single and double.

the integer is sometimes called the stored integer. this is the raw binary number, in which the binary point assumed to be at the far right of the word. in system toolboxes, the negative of the exponent is often referred to as the fraction length.

the slope and bias together represent the scaling of the fixed-point number. in a number with zero bias, only the slope affects the scaling. a fixed-point number that is only scaled by binary point position is equivalent to a number in the fixed-point designer™ [slope bias] representation that has a bias equal to zero and a slope adjustment equal to one. this is referred to as binary point-only scaling or power-of-two scaling:

real-world value=2exponent×integer

or

real-world value=2fraction length×integer

in system toolbox software, you can define a fixed-point data type and scaling for the output or the parameters of many blocks by specifying the word length and fraction length of the quantity. the word length and fraction length define the whole of the data type and scaling information for binary-point only signals.

all system toolbox blocks that support fixed-point data types support signals with binary-point only scaling. many fixed-point blocks that do not perform arithmetic operations but merely rearrange data, such as delay and matrix transpose, also support signals with [slope bias] scaling.

precision and range

you must pay attention to the precision and range of the fixed-point data types and scalings you choose for the blocks in your simulations, in order to know whether rounding methods will be invoked or if overflows will occur.

range

the range is the span of numbers that a fixed-point data type and scaling can represent. the range of representable numbers for a two's complement fixed-point number of word length wl, scaling s, and bias b is illustrated below:

for both signed and unsigned fixed-point numbers of any data type, the number of different bit patterns is 2wl.

for example, in two's complement, negative numbers must be represented as well as zero, so the maximum value is 2wl–1. because there is only one representation for zero, there are an unequal number of positive and negative numbers. this means there is a representation for -2wl–1 but not for 2wl–1:

the full range is the broadest range for a data type. for floating-point types, the full range is –∞ to ∞. for integer types, the full range is the range from the smallest to largest integer value (finite) the type can represent. for example, from -128 to 127 for a signed 8-bit integer.

overflow handling.  because a fixed-point data type represents numbers within a finite range, overflows can occur if the result of an operation is larger or smaller than the numbers in that range.

system toolbox software does not allow you to add guard bits to a data type on-the-fly in order to avoid overflows. guard bits are extra bits in either a hardware register or software simulation that are added to the high end of a binary word to ensure that no information is lost in case of overflow. any guard bits must be allocated upon model initialization. however, the software does allow you to either saturate or wrap overflows. saturation represents positive overflows as the largest positive number in the range being used, and negative overflows as the largest negative number in the range being used. wrapping uses modulo arithmetic to cast an overflow back into the representable range of the data type. see for more information.

precision

the precision of a fixed-point number is the difference between successive values representable by its data type and scaling, which is equal to the value of its least significant bit. the value of the least significant bit, and therefore the precision of the number, is determined by the number of fractional bits. a fixed-point value can be represented to within half of the precision of its data type and scaling. the term resolution is sometimes used as a synonym for this definition.

for example, a fixed-point representation with four bits to the right of the binary point has a precision of 2-4 or 0.0625, which is the value of its least significant bit. any number within the range of this data type and scaling can be represented to within (2-4)/2 or 0.03125, which is half the precision. this is an example of representing a number with finite precision.

rounding modes.  when you represent numbers with finite precision, not every number in the available range can be represented exactly. if a number cannot be represented exactly by the specified data type and scaling, it is rounded to a representable number. although precision is always lost in the rounding operation, the cost of the operation and the amount of bias that is introduced depends on the rounding mode itself. to provide you with greater flexibility in the trade-off between cost and bias, dsp system toolbox™ software currently supports the following rounding modes:

  • ceiling rounds the result of a calculation to the closest representable number in the direction of positive infinity.

  • convergent rounds the result of a calculation to the closest representable number. in the case of a tie, convergent rounds to the nearest even number. this is the least biased rounding mode provided by the toolbox.

  • floor, which is equivalent to truncation, rounds the result of a calculation to the closest representable number in the direction of negative infinity. the truncation operation results in dropping of one or more least significant bits from a number.

  • nearest rounds the result of a calculation to the closest representable number. in the case of a tie, nearest rounds to the closest representable number in the direction of positive infinity.

  • round rounds the result of a calculation to the closest representable number. in the case of a tie, round rounds positive numbers to the closest representable number in the direction of positive infinity, and rounds negative numbers to the closest representable number in the direction of negative infinity.

  • simplest rounds the result of a calculation using the rounding mode (floor or zero) that adds the least amount of extra rounding code to your generated code. for more information, see (fixed-point designer).

  • zero rounds the result of a calculation to the closest representable number in the direction of zero.

to learn more about each of these rounding modes, see (fixed-point designer).

for a direct comparison of the rounding modes, see (fixed-point designer).

网站地图