CHAPTER 2:
Floating Point
6 to represent real numbers on
computers.
6 reals in scientific notation
which represents numbers as a base number and an exponent. The base for the scaling is
normally 2, 10 or 16.
} Scientific notation
◦ ±___.___ x 10__
◦ –2.34 × 1056 (normalized)
◦ +0.002 × 10–4 (not normalized)
◦ +987.02 × 109 (not normalized)
} Scientific notation in binary
◦ ±1.______2 × 2___
Example:
1.01012 x 24
-1.100112 x 212
1.00012 x 2-3
A. Floating
Point Standard
} Defined by IEEE Std 754
} Developed in response to
divergence of representations
◦ Portability issues for
scientific code
} Two representations
◦ Single precision (32-bit)
◦ Double precision (64-bit)
B. IEEE Floating-Point Format
Bit
|
s
|
Exponent
|
Fraction
|
single(32)
|
1
|
8
|
23
|
double(64)
|
1
|
11
|
52
|
} x = (-1)s x (1 + Fraction ) x 2(Exponent-Bias)
}S: sign bit (0 Þ positive,
1 Þ negative)
}
Normalize significand:
1.0
≤ |significand| < 2.0
}
Exponent: excess
representation: actual exponent + Bias
◦
Ensures exponent is
unsigned
◦
Single: Bias = 127;
Double: Bias = 1203
C. Floating-Point Example
} Represent is –45.75
1st:
change 45.75 to binary form
(a) (b)
45=32+8+4+1 45/2
= 22 r 1
=25+23+22+20 22/2 = 11 r 0
=1011012 11/2 = 5 r 1
5/2
= 2 r 1
2/2 = 1 r 0
1/2 = 0 r 1 ↑
45 = 1011012
(a) (b)
0.75 = 0.5 + 025 0.75 x
2 = 1.5 1 ↓
= 2-1 + 2-2 0.5 x 2 = 1.0 1
= 0.112
0.75 = 0.112
45.75 = 1011012 + 0.112
= 101101.112
2nd: change the –45.75 to formula below
x = (-1)s x (1 + Fraction ) x 2(Exponent-Bias)
–45.75 = –1 x (101101.112)
= –1 x
1.01101112 x 25
= –11 x (1 + 0.01101112) x 25
(the exponent is 5 because the decimal are
move to the left hand side with 5 digit places.)
3rd: list out the information
S = 1 ( negative )
Fraction = 0110111……002
Exponent = 5+ Bias ( Bias of
single = 127)
= 5 + 127
= 132
= 100001002
(the exponent must in the base 2)
s
|
Exponent
|
Fraction
|
1
|
10000100
|
0110111……00
|
※ Single: 1100001000110111……00
D. Floating-Point Example
} What number is represented by the
single-precision float
010000011011100……00
1st: list out the information
S = 0
Fraction = 01110…002
Exponent = 100000112
= 27 + 21 + 20
= 131
2nd: replace the information
into the equation
}x = (-1)s x (1 + Fraction ) x 2(Exponent-Bias)
} x = (–1)0× (1 + 0.01112)
× 2(131 – 127)
= (1) × 1.4375 x 24
※
= 23
the end ^^
if you have any questions or ideas can contact me
Prepared By : TEE SONG WEI
Contact Number : 0173403160
Facebook : Wentson Tee Song Wei
0 comments:
Post a Comment