IEEE Standard 754 floating point is the most common representation today for real numbers on computers, including Intel-based PC's, Macintoshes, and most Unix platforms. This article gives a brief overview of IEEE floating point and its representation. Discussion of arithmetic implementation may be Found in The Book Mentioned At The Bottom of this Article.
What Are Floating Point NumBers?
There are several ways to represent real numbers on computers. Fixed point places a radix point somewhere in the middle of the digits, and is equivalent to using integers that represent portions of some unit. For example, one might represent 1 / 100ths of a unit If You Have Four Decimal Digits, You Could Represent 10.82, OR 00.01. Another approach is to use judice, and represent every number as the ratio of two integers.
Floating-point representation - the most common solution -. Basically represents reals in scientific notation Scientific notation represents numbers as a base number and an exponent For example, 123.456 could be represented as 1.23456 x 102. In hexadecimal, the number 123.abc might. BE REPRESENTED AS 1.23ABC x 162.
Floating-point solves a number of representation problems. Fixed-point has a fixed window of representation, which limits it from representing very large or very small numbers. Also, fixed-point is prone to a loss of precision when two large numbers are divided .
Floating-point, on the other hand, employs a sort of "sliding window" of precision appropriate to the scale of the number. This allows it to represent numbers from 1,000,000,000,000 to 0.0000000000000001 with ease.
Storage Layout
IEEE floating point numbers have three basic components: the sign, the exponent, and the mantissa The mantissa is composed of the fraction and an implicit leading digit (explained below) The exponent base (2) is implicit and need not be stored... The Following Figure Shows The Layout for Single (32-Bit) And Double (64-bit) Precision floating-point values. The number of bits for Each Field Are Shown (Bit Ranges Are In Square Bracket):
SignExponentfractionbiassingle precision1 [31] 8 [30-23] 23 [22-00] 127double precision1 [63] 11 [62-52] 52 [51-00] 1023
The Sign Bit
..............................
The Exponent
The exponent field needs to represent both positive and negative exponents. To do this, a bias is added to the actual exponent in order to get the stored exponent. For IEEE single-precision floats, this value is 127. Thus, an exponent of zero Means That 127 Is Stored in The Exponent Field. A Stored Value of 200 INDICATES An Exponent of 200 Indicates An Exponent of (200-127), OR 73. For Reasons Discussed Later, Exponents Of -127 (ALL 0S) And 128 (all 1s) Are Reserved For Special Numbers.
For Double Precision, The Exponent Field IS 11 BITS, AND HAS A BIAS OF 1023.
The mantissa
........................
To Find Out The Value of The Implicit Leading Bit, Consider That Any Number CAN Be Expressed In Scientific Notance In Many Different Ways. For Example, The Number Five Can Be Repented As Any of these:
5.00 x 100
0.05 x 102
5000x10-3
In order to maximize the quantity of representable numbers, floating-point numbers are typically stored in normalized form. This basically puts the radix point after the first non-zero digit. In normalized form, five is represented as 5.0 x 100.A nice little optimization is available to us in base two, since the only possible non-zero digit is 1. Thus, we can just assume a leading digit of 1, and do not need to represent it explicitly. As a result, the mantissa has effectively 24 Bits of Resolution, by Way of 23 Fraction Bits.
Putting it all together
So, to sum up:
The sign bit is 0 for positive, 1 for negative. The exponent's base is two. The exponent field contains 127 plus the true exponent for single-precision, or 1023 plus the true exponent for double precision. The first bit of the mantissa is typically Assumed to be 1.f, WHERE f is the field of fraction bits.
Ranges of floating-point number
Let's consider single-precision floats for a second. Note that we're taking essentially a 32-bit number and re-jiggering the fields to cover a much broader range. Something has to give, and it's precision. For example, regular 32- bit integers, with all precision centered around zero, can precisely store integers with 32-bits of resolution. Single-precision floating-point, on the other hand, is unable to match this resolution with its 24 bits. It does, however, approximate THIS value by Effectively Truncating from the Lower End. for example:
11110000 11001100 10101010 00001111 // 32-bit integer
= 1.11110000 11001100 10101010 x 231 // Single-Precision Float
= 11110000 11001100 10101010 00000000 // Corresponding Value
This approximates the 32-bit value, but does not yield an exact representation. On the other hand, besides the ability to represent fractional components (which integers lack completely), the floating-point value can represent numbers around 2127, compared to 32 -bit integers maximum value around 232.The range of positive floating point numbers can be split into normalized numbers (which preserve the full precision of the mantissa), and denormalized numbers (discussed later) which use only a portion of the fractions's precision.
DENORMALIZEDNORMALIZEDAPPROXIMATE DECIMALSINGLE PRECISION
± 2
-149 to (1-2
-23) x2
-126
± 2
-126 TO (2-2
-23) x2
127
± ~ 10
-44.85 to ~ 10
38.53
Double Precision
± 2
-1074 TO (1-2
-52) x2
-1022
± 2
-1022 TO (2-2
-52) x2
1023
± ~ 10
-323.3 to ~ 10
308.3
Since the sign of floating point number is given by the future for negative number.
There Are Five Distinct Numeric Ranges That Single-Precision Floating-Point Numbers Are Not Able To Reperse:
Negative numbers less than - (2-2-23) x 2127 (negative overflow) Negative numbers greater than -2-149 (negative underflow) Zero Positive numbers less than 2-149 (positive underflow) Positive numbers greater than (2-2 -23) x 2127 (POSITIVE overflow)
Overflow means that values have grown too large for the representation, much in the same way that you can overflow integers. Underflow is a less serious problem because is just denotes a loss of precision, which is guaranteed to be closedly approximated by zero.
Here's a Table of The Effective Range (Excluding Infinite Values) of IEEE FLOATING-POINT NUMBERS:
BinaryDecimalSingle ± (2-2-23) 127 ~ ± 1038.53Double ± (2-2-52) 1023 ~ ± 10308.25Note that the extreme values occur (regardless of sign) when the exponent is at the maximum value for finite numbers (2127 FOR SINGLE-Precision, 21023 for Double, And The Mantissa IS Filled with 1s (Including the Normalizing 1 Bit).
Special Values
.
ZERO
As mentioned above, zero is not directly representable in the straight format, due to the assumption of a leading 1 (we'd need to specify a true zero mantissa to yield a value of zero). Zero is a special value denoted with an exponent Field of Zero and a Fraction Field of Zero. Note That -0 and 0 Are Distinct Values, Though They Both Compare As Equal.
DENORMALIZED
If the exponent is all 0s, but the fraction is non-zero (else it would be interpreted as zero), then the value is a denormalized number, which does not have an assumed leading 1 before the binary point. Thus, this represents a Number
(-1)
s x 0.
f x 2
-126
, WHERE S is The Sign Bit and f is The Fraction. for Double Precision, DenorMalized Numbers Aref
(-1)
s x 0.
f x 2
-1022
. From this you can interpret ZERO As a Special Type of Denortribed Number.
Infinity
The values infinity and -infinity are denoted with an exponent of all 1s and a fraction of all 0s. The sign bit distinguishes between negative infinity and positive infinity. Being able to denote infinity as a specific value is useful because it allows operations to continue Past overflow Situations. Operations with infinite values are well defined in IEEE Floating Point.
NOT A Number
The value NaN (Not a Number) is used to represent a value that does not represent a real number NaN's are represented by a bit pattern with an exponent of all 1s and a non-zero fraction There are two categories of NaN:.. QNaN (Quiet NaN) and SNaN (Signalling NaN) .A QNaN is a NaN with the most significant fraction bit set. QNaN's propagate freely through most arithmetic operations. These values pop out of an operation when the result is not mathematically defined.
.
Semantically, Qnan's Denote Indeterminate Operations, While Snan's Denote Invalid Operations.
Special Operations
Operations On Special Numbers Are Well-Defined by IEEE. In The Simplest Case, Any Operation with a nan yields a nan result. Other Operations Are As Follows:
Operation result n / ± infinity 0 ± infinity x ± infinity ± infinity ± 0 ± infinity ± 0 ± 0 ± 0 nan infinity - infinity nan ± infinity / ± infinity nan ± infinity x 0 nan
Summary
To Sum up, the FOLLOWING ARE The Corresponding Values for a Given Repesentation:
Float Values
B = BIAS)
Sign Exponent (e) Fraction (f) Value 0 00..00..00 0 0 00..00 00..01: 11..11 Positive Denormalized Real0.fx 2 (-b 1) 0 00. .01: 11..10 xx..x Positive Normalized Real1.FX 2 (EB) 0 11..11 00..00 Infinity 0 11..11 00..01: 01..11 snan 0 11 .. 11 10..00: 11..11 Qnan 1 00..00 00..00-0 1 000..00..01: 11..11 Negative Denormalized Real-0.FX 2 (-b 1) 1 ..01: 11..10 xx..x negative normalized real-1.fx 2 (EB) 1 11..11 00..00-infinity 1 11..11 @..01: 01..11 Snan 1 11..11 10..00: 11.11 QnanReferences
A lot of this stuff was observed from small programs I wrote to go back and forth between hex and floating point (printf-style), and to examine the results of various operations. The bulk of this material, however, was lifted from Stallings' Book.
Computer Organization and Architecture, William Stallings, pp. 222-234 Macmillan Publishing Company, ISBN 0-02-415480-6 IEEE Computer Society (1985), IEEE Standard for Binary Floating-Point Arithmetic, IEEE Std 754-1985. Intel Architecture Software Developer's Manual, Volume 1: Basic Architecture, Comparing floating point numbers, Bruce Dawson, http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm This is (a PDF document downloaded from intel.com.). An Excellent Article on The Traps, Pitfalls and Solutions for Comparing Floating Point Numbers. Hint - Epsilon Comparison IS Usually The Wrong Solution.