Floating Point
Overview
The IEEE binary floating-point standard defines an encoding used to represent numbers of form
where
- Normalized Form
- Here the exponent field is neither all
0s nor all1s. - 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
0s. - 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
1s. - If the fraction field is all
0s, we have anvalue. - If the fraction field is not all
0s, we have.
- Here the exponent field is all
The
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 (also known as round-to-nearest) 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
Floating-point arithmetic operations (e.g.