Overview
The IEEE floating-point standard defines an encoding used to represent numbers of form where denotes the sign bit, the significand, and the exponent. The binary representation of floating point numbers are segmented into three fields: the sign bit, the exponent field, and the fraction field. Furthermore, there are three classes these fields are interpreted with respect to:
- Normalized Form
- Here the exponent field is neither all
0
s nor all1
s. - The significand is , where denotes the fractional part.
- where is the unsigned interpretation of the exponent field.
- Here the exponent field is neither all
- Denormalized Form
- Here the exponent field is all
0
s. - The significand is , where denotes the fractional part.
- , defined for smooth transition between normalized and denormalized values.
- Here the exponent field is all
- Special Values
- Here the exponent field is all
1
s. - If the fraction field is all
0
s, we have an value. - If the fraction field is not all
0
s, we have .
- Here the exponent field is all
The in the first two forms is set to where denotes the number of bits that make up the exponent field. In C, fields have the following widths:
Declaration | Sign Bit | Exponent Field | Fractional Field |
---|---|---|---|
float | 1 | 8 | 23 |
double | 1 | 11 | 52 |
The precision of a floating-point type refers to the number of bits found in the fractional field.
Rounding
Because floating-point arithmetic can’t represent every real number, it must round results to the “nearest” representable number, however “nearest” is defined. The IEEE floating-point standard defines four rounding modes to influence this behavior:
- Round-to-even rounds numbers to the closest representable value. In the case of values equally between two representations, it rounds to the number with an even least significant digit.
- Round-toward-zero rounds downward for positive values and upward for negative values.
- Round-down always rounds downward.
- Round-up always rounds upward.
Arithmetic
Bibliography
- Bryant, Randal E., and David O’Hallaron. Computer Systems: A Programmer’s Perspective. Third edition, Global edition. Always Learning. Pearson, 2016.
- “Scientific Notation.” In Wikipedia, March 6, 2024. https://en.wikipedia.org/w/index.php?title=Scientific_notation&oldid=1212169750.