Floating Point/Fixed-Point Numbers
From Wikibooks, the open-content textbooks collection
Contents |
[edit] Fixed-Point
Fixed point numbers are a simple and easy way to express fractional numbers, using a fixed amount of bits. Systems without floating-point hardware support frequently use fixed-point numbers to represent fractional numbers.
[edit] The Decimal Point
The term "Fixed-Point" refers to the decimal point of a number. In binary, bits can be either 0 or 1, and therefore we don't have a separate symbol to designate where the decimal point lies. However, we imagine, or assume, that the decimal point always sits at a certain location in the number. For instance, in a 32-bit number, we can assume that the decimal point exists directly between bits 15 (15 because the first bit is numbered 0, not 1) and 16, giving 16 bits of whole numbers, and 16 bits for the fractional part.
[edit] Width and Precision
The width of a fixed-point number is the total number of bits assigned for storage for the fixed-point number. If we are storing the whole part and the fractional part in different storage locations, the width would be the total amount of storage for the number. The range of a fixed-point number is the difference between the minumum number possible, and the maximum number possible. The precision of a fixed-point number is the total number of bits for the fractional part of the number. Because we can define where we want the fixed decimal point to be located at, the precision can be any number up to and including the width of the number. Note however, that the more precision we have, the less total range we have.
There are a number of standards, but in this book we will use n for the width of a fixed-point number, p for the precision, and R for the total range.