Download presentation
Presentation is loading. Please wait.
1
Floating Point. Binary Fractions.
Fixed point representation Scientific Notation. Floating point Single precision, Double precision. Textbook Ch.3.5 Central Connecticut State University, MIPS Tutorial. Chapters
2
Fixed Point representation
This is base 10 positional notation. The decimal point is put between the 100 position and the 10-1 position 3 5 7 . 2 8 4 3×102+ 5×101+ 7×100+ 2×10-1+ 8×10-2+ 4×10-3 If the base is two, the point '.' is called a binary point. 1 . 1×22+ 0×21+ 0×20+ 1×2-1+ 0×2-2+ 1×2-3
3
Integer and Fractional parts
1 . 1×22 + 0×21 + 0×20 + 1×2-1 + 0×2-2 + 1×2-3 1×4 + 0×2 + 0×1+ 1×0.5 + 0×0.25 + 1×0.125 4 + 0 + 0.5 + 0.125 4 625
4
How to calculate 0110 . 1001 = 4 + 2 + 0.5 +0.0625 = 6.5625 Power of 2
3 2 1 . -1 -2 -3 -4 Decimal 8 4 0.5 0.25 0.125 0.0625 Include? = =
5
Adding fixed point Expressions
as decimal 6.5625 1.2500 7.8125 Power of 2 3 2 1 . -1 -2 -3 -4 Decimal 8 4 0.5 0.25 0.125 0.0625 Include? = = Binary Addition Algorithm Works!
6
Different Ranges Sometimes one program needs to deal with several different ranges of numbers. Consider a program that must deal with both the measurements that describe the dimensions on a silicon chip (say to meters) and also the speed of electrical signals, to meters/second. It is hard to find a place to fix the decimal point so that all these values can be represented.
7
Point Floats Notice that in writing those numbers ( , , , ) I was able to put the decimal point where it was needed in each number. When the decimal point moves to where it is needed in an expression, the decimal point is said to Float.
8
Scientific Notation 1.38502 × 1003 ---+--- | | +-- exponent |
| | exponent | +--- mantissa × 1000 = The idea of floating point comes from scientific notation for numbers. The mantissa always has a decimal point after the first digit. The decimal point "floats" to where it belongs. The mantissa gives the digits and the exponent says where the decimal point should go.
9
Negative Exponents The exponent shows by what power of 10 to multiply the mantissa by, or (the same thing) how far to float the decimal point. × 101 = 10 (move the point 1 place right) 10-1 .1 (move the point 1 place left) 102 100 (move the point 2 places right) 10-2 .01 (move the point 2 places left) The reverse process is called mantissa normalization
10
Negative Values The notation for a negative number has a negative sign in front of the first digit: × 1003 = -( × 1003) = The notation for a small negative number has two negative signs: one to negate the entire number and one (in the exponent) to shift the decimal point left: × 10-3 = -( × 10-3) =
11
e - close to idea of floating point
Writing the cross (×) and the superscript exponent is tedious, and not suitable for programs. A slightly altered notation is used in computer programs and in input and output text: The number of digits in the mantissa is called the precision of the floating point number. × = e+03 × = e-03 × = e+03 × = e-03 This is getting close to the idea of floating point. Each expression has eight digits. Two of the digits are used to "float" the decimal point. The remaining six show the digits of the number.
12
Single Precision Floating Point
Single-precision floating point value is 32 bits long. The bits are divided into fixed-sized fields as follows: The mantissa and exponent fields work like the similar parts in scientific notation. The sign bit gives the sign of the entire expression: a 0 bit means positive and a 1 bit means negative.
13
Mantissa 1.xxx xxxx xxxx xxxx xxxx xxxx 1.11110000101101101010001
The mantissa represents a number in 24-bit base two positional notation that looks like this: 1.xxx xxxx xxxx xxxx xxxx xxxx (x = 0 or 1; there are 23 x's) The mantissa represents the 23-bit binary fraction part of a 24-bit number that starts with a "1". The 20 place (the one's place) is presumed to contain a 1 and is not present in the mantissa. This trick gives us 24 bits of precision with only 23 bits. For example, this binary number is represented as
14
Mantissa Explained Represent 00011.00101101 as a float
Drop the leading zeros: Now there is a leading one. Normalize the mantissa - Move the binary point so that the leading one is in the one's place (the exponent shows the move): × 21 Drop the leading one: × 21 Add zero bits on the right so that there are 23 bits in total: × 21 The mantissa is:
15
The Exponent The exponent is expressed using a biased integer.
Biased 127 Exponent actual exponent biased exponent eight bit exponent Notes -127 Not repre sented -126 1 -10 117 127 128 10 137 254 255 Special Usage The exponent is expressed using a biased integer. This is an unsigned binary integer that has +127 added to it. The sign bit is zero when the number is zero. A floating point zero consists of 32 zero bits.
16
Formula and Example 1.0 s is the sign bit (0 or 1), 0 x 3F 80 00 00
M is the mantissa ( to ) E is the exponent (-126 to +127). value = (-1)s × 1.M × 2E-127 1.0 What is the sign bit of 1.0? (for positive) What is the mantissa of 1.0? What is the actual exponent of 1.0? 0 What is the biased exponent of 1.0? = 0 x 3F
17
Example on SPIM ## Program to represent 1.0 .text .globl main main: .data val: .float 1.0 ## End of file
18
- 0.110 imprecise representation
The sign bit of -0.1 is 1 (for negative). The binary fraction for 0.1 (from the chapter 29 MIPS tutorial) The mantissa of 0.1 is: Shift the leading bit into the one's place: The shift was 4 places left, for an exponent of -4 Drop bit in the one's place: Retain 23 bits: The actual exponent is -4 The biased exponent is = 123 =
19
Decimal Binary so far Start 0.1 0. ×2 0.2 0.0 0.4 0.00 0.8 0.000 1.6 0.0001 .6 1.2 Result
20
- 0.110 imprecise representation
+- exponent Mantissa 1 B D C C D On SPIM, a constant of -0.1 is represented as 0xBDCCCCCD because the value is rounded up one bit to form the "D" at the end. The sign bit of -0.1 is 1 (for negative). Retain 23 bits: The biased exponent is = 123 =
21
Floating Point Double and more Precisions
31 S Exponent bits Mantissa – 20 bits 31 Mantissa continued – 32 bits Single precision floats have only 24 bits of precision. This is the equivalent of 7 to 8 decimal digits. The 7 or 8 decimal digits of precision is much worse than most electronic calculators. Double precision has 53 bits and 15 or 16 decimal places of precision. Name Common name Base Digits E min E max Decimal digits Decimal E max binary16 Half precision 2 10+1 −14 +15 3.31 4.51 binary32 Single precision 23+1 −126 +127 7.22 38.23 binary64 Double precision 52+1 −1022 +1023 15.95 307.95 binary128 Quadruple precision 112+1 −16382 +16383 34.02
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.