CSE-3109 Computer Architecture Lecture 14 Floating Point Representation 1 Basic Format of Floating-Point Number • Three numbers are associate with a floating-point number: a mantissa M, an exponent E and a base B. The mantissa M is also referred to as the significant or fraction in the literature. • A real number is represented as M × BE. • Example: 1.0 × 1018 where 1.0 = mantissa, 10 = base and 18 = exponent. 2 Representation of Floating-Point Number • A floating point number is represented as a word (M,E) consisting of a pair of signed fixed-point numbers: M, which is usually a fraction or integer and E, which is an integer. • Since, B is constant, it is not stored but is simply built into the circuit that process the number. • The number of digits in M determines the precision (accuracy) of (M,E); B and E determines the range. 3 Representation of Floating-Point Number 4 Scientific Notation • Scientific notation (also referred to as standard form or standard index form) is a way of expressing numbers that are too big or too small to be conveniently written in decimal form. • In scientific notation all numbers are written in the form: m × 10n (m times ten raised to the power of n), where the exponent n is an integer, and the coefficient m is any real or integer number called the mantissa.) 5 Example of Scientific Notation 6 Normalized Notation • Any given integer can be written in the form m×10n in many ways: for example, 350 can be written as 3.5×102 or 35×101 or 350×100. • In normalized scientific notation (called "standard form" in the UK), the exponent n is chosen so that the absolute value of m remains at least one but less than ten (1 ≤ |m| < 10). • Thus 350 is written as 3.5×102. • The 10 and exponent are often omitted when the exponent is 0. 7 Normalized Notation • Scientific notation, as many people may remember, is a method of writing out large or small numbers, as a normalized fraction, and a multiplier. • The term normalized, in this case, means that the magnitude (absolute value) of the number is between 1 and 10. • If the number we have lies outside this range, we multiply or divide by successive powers of 10, as necessary, until the fractional part of the number is within that range. 8 Normalized Notation • Let's say that we have a large number: 123,456,789 in scientific notation, we want to divide this by a power of 10, To do this, we divide by 100,000,000 (hundred million), and we get the final result: • Now, to express our original number, we have to multiply this fractional number times the amount we divided by originally: • And for ease, we frequently write the last term as an exponent of 10: 9 Binary Numbers in Scientific Notation • Just as we can show decimal numbers in scientific notation, we can also show binary numbers in scientific notation: 1.xxxxxxxxxtwo × 2yyyy • Since the point is called a "decimal point" in a decimal (base 10) number system, it is common to refer to the same exact point as a "binary point" when in a binary system. • Numbers are represented as a single nonzero digit to the left of the binary point. 10 Binary Numbers in Scientific Notation 11 Normalizing the Mantissa • Before a floating-point binary number can be stored correctly, its mantissa must be normalized. The process is basically the same as when normalizing a floating-point decimal number. For example, decimal 1234.567 is normalized as 1.234567 × 103 by moving the decimal point so that only one digit appears before the decimal. • Similarly, the floating-point binary value 1101.101 is normalized as 1.101101 × 23 by moving the decimal point 3 positions to the left, and multiplying by 23. 12 Normalizing the Mantissa • Normalized form: no leading 0s (exactly one digit to left of decimal point. +1.xxxxxxxxxtwo × 2yyyy two 13 IEEE 754 Floating Point Number • IEEE 754 was first published in 1985 to unify how floatingpoint numbers are represented and computed across computers. • A floating-point number is stored in three parts: – Sign bit (S): Determines whether the number is positive (0) or negative (1). – Exponent (E): Determines where the “binary point” (similar to decimal point) is placed. – Mantissa (Fraction or Significand): Represents the significant digits of the number. 14 IEEE 754 Floating Point Number Bit Allocation: Sign: 1 bit Exponent: 8 bits Mantissa: 23 bits Total: 32 bits • s is the sign of the floating-point number (1 meaning negative). • exponent is the value of the 8-bit exponent field • mantissa is the 23-bit number • This representation is called sign and magnitude, since the sign is a separate bit from the rest of the number. 15 IEEE 754 Floating Point Number Biased Exponent • In IEEE 754 floating-point representation, the exponent field is stored using a bias rather than a separate sign bit. • The exponent is always stored as an unsigned integer. • Instead of a sign bit, biasing shifts the range so that both positive and negative exponents can be represented with just unsigned numbers. 16 IEEE 754 Floating Point Number 8-bit Binary -3 0 +3 Stored (Biased) Value -3 + 127 = 124 0 + 127 = 127 +3 + 127 = 130 Binary (Biased) 01111100 01111111 10000010 17 IEEE 754 Floating Point Number Biased Exponent For single precision (32-bit): Exponent field is 8 bits. Bias = 127. Stored exponent = (actual exponent) + 127. So: ❑ An actual exponent of 0 is stored as 127 (01111111₂). ❑ An actual exponent of -1 is stored as 126 (01111110₂). ❑ An actual exponent of +1 is stored as 128 (10000000₂). This approach avoids having to handle two’s complement or a separate sign bit — the hardware just subtracts the bias during decoding. 18 IEEE 754 Floating Point Number Biased Exponent No separate sign bit for the exponent — the "sign" of the exponent is encoded implicitly in the biased value. •If the stored exponent < 127 → negative actual exponent. •If stored exponent > 127 → positive actual exponent. 19 IEEE 754 Floating Point Number Example: Let’s represent -6.75 in IEEE 754 (Single Precision): •Sign: Since number is negative → S = 1. •Convert 6.75 to binary: 6 → 110 .75 → .11 → Combined: 110.11 •Normalize: 1.1011 × 2² Mantissa (F) = 1011 + 19 trailing zeros (to make 23 bits) • Exponent: Unbiased exponent = 2 Biased exponent = 2 + 127 = 129 → 10000001 1 10000001 10110000000000000000000 20 IEEE 754 Floating Point Number • A normalized IEEE 754 floating-point number is represented as: Where: •S: Sign bit •F: Fraction (mantissa bits after the binary point) •Bias: A fixed number used to represent negative exponents without using signed bits (e.g., Bias = 127 for single precision). •The number you decoded from IEEE 754 is expressed in decimal (base-10). 21 IEEE 754 Floating Point Number 22 IEEE 754 Floating subnormal) number Point Number-denormal (or A denormal (or subnormal) number is a floating-point number in IEEE 754 where: • Exponent field = 00000000 (all zeros) • Fraction (mantissa) ≠ 000…000 (at least one bit set) • No implicit leading 1 is used in the significand This makes them special because they are not normalized like most floating-point numbers. Value Formula (Single Precision) For 32-bit floats: • The exponent is fixed at −126 (not −127). • The significand uses 0.fraction instead of 1.fraction, which makes the number much smaller. 23 IEEE 754 Floating subnormal) number Point Number-denormal (or What if we Used −127 for Denormals? Denormals are designed to provide gradual underflow . If stored exponent = 0 were interpreted as exponent −127, we would have: •Smallest normal number: •Largest denormal number (all fraction bits = 1): • There would still be a gap between: • This means the smallest normal would be twice as large as the largest denormal. • No gradual transition → an abrupt jump. 24 IEEE 754 Floating subnormal) number Point Number-denormal (or What IEEE 754 Actually Does (−126) ? • • • • • • • For denormals: No hidden 1 → significand = 0.fraction Effective exponent is set to −126, not −127 So 00000000 does not literally represent −126 in the usual bias formula — instead, the standard says: If exponent field = 0 and fraction ≠ 0, Use exponent = 1 − bias and hidden bit = 0. • And since: 1−bias=1−127=−126 • we end up using −126. Largest denormal number = Smallest normal number = Now there’s no gap — they are right next to each other. This gives us gradual underflow (smooth transition from normal to denormal to 0). 25 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) The IEEE floating-point standard has special cases to represent numbers such as zero, infinity, and illegal results. For example, representing the number zero is problematic in floating-point notation because of the implicit leading one. Special codes with exponents of all 0’s or all l’s are reserved for these special cases. 26 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) 1. Zero (+0 and –0) Representation: • Sign bit: 0 for +0, 1 for –0 • Exponent: All bits are 0 (zero does not “represent” −127 at all — it just represents 0.) • Fraction (Mantissa): All bits are 0 • The implicit leading 1 is not used Meaning: Both +0 and –0 are considered equal for arithmetic, b u t the sign can affect certain computations like division: • 1 / +0 = +∞ • 1 / –0 = –∞ Why needed: To distinguish results of operations that approach zero from positive or negative directions (important in scientific computation). 27 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) 28 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) Example: Smallest positive denormal number: • Exponent: 00000000 • Fraction: 00000000000000000000001 • Value: 29 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) 3. Infinity (±∞) Representation: • Sign bit: 0 for +∞, 1 for –∞ • Exponent: All bits are 1 (this bit pattern is interpreted specially, bias is not used) • Fraction: All bits are 0 • The implicit leading 1 is not used Meaning: Represents overflow or results of operations like: • 1 / 0 → +∞ • –1 / 0 → –∞ Usage: Allows programs to handle overflows gracefully rather than crashing. 30 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) 4. NaN (Not a Number) Representation: • Sign bit: Can be 0 or 1 (not meaningful for NaN) • Exponent: All 1s (bias is not used) • Mantissa: Non-zero • The implicit leading 1 is not used Interpretation: Represents invalid or undefined results. Examples:0/0, √(-1) 31 IEEE 754 Floating Point Number-Special Cases (Special Cases: 0, denormal, ±∞, and NaN) 32 The Trade-off: Fraction (Mantissa) vs Exponent • Mantissa / Fraction bits: Control precision (how many significant digits you can store). • Exponent bits: Control range (how large or small the number can be). • Since we have a fixed word size (e.g., 32-bit single precision or 64-bit double precision), adding more bits to the mantissa reduces exponent bits and thus reduces range, and vice versa. 33 The Trade-off: Fraction (Mantissa) vs Exponent Let’s take a 10-bit floating-point format (just for illustration): •1 bit for sign •3 bits for exponent •6 bits for mantissa Case 1: Increase Mantissa (Precision ↑, Range ↓) Suppose we take 4 bits for exponent, 5 bits for mantissa: •Mantissa can store more precision: Example: 1.10101₂ × 2³ (more accurate representation of fractional numbers). •But fewer exponent bits mean smaller range: If exponent is 4 bits (biased), range might only cover 2−7 to 28. This is useful when you need very precise results but don’t expect extremely large or small numbers (e.g., graphics shading, audio processing). 34 The Trade-off: Fraction (Mantissa) vs Exponent If exponent is 4 bits (biased), range might only cover 2−7 to 28. (Explanation) • With 4 bits, you can represent 2⁴ = 16 possible values (0000 to 1111). • If this were a signed exponent (two’s complement), you could represent: • Minimum exponent: 1000₂ = -8 • Maximum exponent: 0111₂ = +7 • So, the range would be −8 to +7. • But IEEE 754 does not store the exponent as signed — it uses bias notation. 35 The Trade-off: Fraction (Mantissa) vs Exponent If exponent is 4 bits (biased), range might only cover 28. (Explanation) 2−7 to • Bias means we store the exponent as an unsigned number, but interpret it as: e= E(Stored Exponent)−Bias • For 4-bit exponent, bias is: Bias=2k−1−1=23−1=7 So: • Stored 0000₂ (010) → Actual exponent =0 −7=-7 • Stored 0111₂ (710) → Actual exponent = 7-7=0 • Stored 1110₂ (140) → Actual exponent =14-7=+7 • Stored 1111₂ (1510) → Actual exponent =15-7=+8 This way, exponents cover:−7 … 0 … +8 36 The Trade-off: Fraction (Mantissa) vs Exponent Case 2: Increase Exponent (Range ↑, Precision ↓) Suppose we take 5 bits for exponent, 4 bits for mantissa: •Mantissa is now shorter: Example: 1.1010₂ × 2³ (less precision — fewer fractional bits stored). •But range is bigger: 5-bit exponent allows covering 2−15 to 216 (much larger dynamic range). This is useful when you need to represent very large or very small values, such as scientific simulations (astronomy, particle physics). 37 How the value of Bias is chosen? • For k bits, stored exponent values go from: Min stored value=0, So the full range is 0→2k−1. Max stored value=2k−1 • We want both positive and negative exponents Example: If k=3, we have numbers 0 to 7. But we need to represent exponents like -3, -2, -1, 0, 1, 2, 3, 4. • Shift (bias) the range To allow negative exponents, we “center” the range so that roughly half the numbers are below 0 and half are above 0. This is done by subtracting a bias value from the stored exponent. • Choose the bias The bias should be the midpoint of the range of values, so that: ❑ Stored value 0 maps to the lowest exponent ❑ Stored value 2k - 1 maps to the highest exponent ❑ Stored value equal to bias represents exponent = 0 38 How the value of Bias is chosen? • Midpoint of 0→2k−1 is: But since bias must be an integer, we take the floor (round down): Biased Exponent Actual Exponent 0 1 2 3 4 5 6 7 -3 -2 -1 0 1 2 3 4 39 How the value of Bias is chosen? (k=8) • Stored exponent range: • Bias: 0 → 255 (because 8 bits can represent 28=256 values) • Biased Exponent : 0 to 255 • Actual Exponent: -127 to +128 • The mathematical span −127…+128 comes from blindly subtracting the bias from all 256 codes. • IEEE-754 reserves the endpoints: 0 → zero/subnormals (use −126, no hidden 1) 255 → infinities/NaNs (no hidden 1) • Therefore, finite normalized numbers use −126…+127. 40 How the value of Bias is chosen? Why Favor Positives? This is intentional — positive exponents are slightly more common because: •Many real-world numbers are larger than 1.0 •Giving one extra code to positive exponents increases the range for big numbers If we picked 128 as the bias: (8-bit exponent) •Stored 128 → exponent 0 •Range would be –128 to +127 (more negatives than positives) •We'd favor tiny numbers (less common in typical computations) 41 Underflow and Overflow in floating point number What the labels mean (single precision, 32-bit) •Exponent field is 8 bits: Normalized exponents span −126 … +127. •Significand (mantissa) is 23 fraction bits with an implicit leading 1 for normalized numbers. •The shaded band : The hatched strip across the center is the finite representable numbers. Outside it, results overflow to ±∞. 42 Underflow and Overflow in floating point number Right edge (largest finite +ve) •Label “ + 1.11…11 × 2127” means the significand is all 1s ⇒ Any larger positive result overflows → +∞ (and sets the overflow flag). Left edge (largest finite −ve) •Symmetric: “− 1.11…11 × 2127” is the most negative finite number. •More negative → −∞. 43 Underflow and Overflow in floating point number The center “underflow” region •Underflow happens when the result of a computation is closer to zero than the smallest representable denormalized number. •Near zero, the smallest normalized magnitude is ±1.0 × 2−126. •Between ±1.0×2−126 and 0 you have subnormal (denormal) numbers. •Denormalized numbers (if supported), use a leading 0 in the mantissa. •The smallest positive subnormal number in IEEE 754 single precision (binary32) is:+(0.0000000000000001)2 ×2−126 •The largest subnormal negative number in IEEE 754 single precision (binary32) is:−(0.11111111111111111)2×2−126 44 Underflow and Overflow in floating point number The center “underflow” region •If the number is too small even for denormalized representation, that is smaller than smallest subnormal number and larger than largest subnormal negative number , it is flushed to 0 (called flushto-zero underflow). •An underflow flag can also be set. 45 Double precision • One way to reduce chances of underflow or overflow is to offer another format that has a larger exponent. • Double-precision floating-point format, on the other hand, occupies 64 bits of computer memory and is far more accurate than the single-precision format. • Although double precision allows for more accuracy, it also requires more computational resources, memory storage, and data transfer. The cost of using this format doesn’t always make sense for every calculation. 46 What is the Hidden Bit? • In normalized floating-point numbers (except for special cases), the mantissa (or significand) is always assumed to have a leading 1 before the binary point. • This leading 1 is not stored explicitly — it is hidden — which saves one bit of storage and effectively gives you one extra bit of precision. • When a floating-point number is normalized, it is written in the form: This means: •The first bit to the left of the binary point is always 1 (for any non-zero normalized number). •Since it is always 1, storing it is redundant — so IEEE 754 doesn’t store it. •The hardware simply assumes it to be 1 during calculations. 47 What is the Hidden Bit? Impact of the Hidden Bit This approach: •Increases precision: You effectively get 24 bits of precision using only 23 bits of storage. •Saves memory: No need to store a bit that is always 1. Special Case – Denormalized Numbers For denormalized numbers (used to represent values very close to zero): •The hidden bit is assumed to be 0 (not 1). •This allows representation of numbers smaller than the smallest normalized number (gradual underflow). 48 What is the Hidden Bit? Number Type Stored Mantissa Implied Leading Bit Actual Significant Normalized 0111… 1 1.0111 Denormalized 0111… 0 0.0111 49 Floating Point representation-Example 1 Let’s take the number 5.75 (decimal) and represent it in IEEE 754 single precision: •Convert to binary: 5.7510=101.112 •Normalize: Shift binary point so only one 1 remains on the left: 101.112=1.01112×22 •Mantissa = 1.0111 •Exponent = 2 •Store in IEEE 754: The exponent field stores 2 + 127 = 129 = 10000001₂. The mantissa field stores only the fractional part after the binary point:01110000000000000000000 (23 bits). The leading 1. is implied (hidden bit). 50 Floating Point representation-Example 2 Let's decode a 32-bit floating-point number: 0 10000010 10100000000000000000000 Step 1: Sign Bit (S = 0) ⇒ (−1)0=+1 → Number is positive. Step 2: Exponent Field = 10000010₂ = 130₁₀ Actual exponent: E=130−127=3 Step 3: Mantissa (Fraction Bits) = 101000... This means: 1+0.101=1.1012=1.62510 Step 4: Combine (+1)×(1.625)×23=1.625×8=13 Final Value = 13.0 51 Revision 52 End 53
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )