250 likes | 345 Views
Factional Values. What is 0.75 in binary?. How could we represent fractions?. In decimal: As fractions : 1/5 . How could we represent fractions?. In decimal: As fractions : 1/5 As decimals : 0.2. Column Pattern. What goes to the right of 1’s column?. Column Pattern.
E N D
Factional Values What is 0.75 in binary?
How could we represent fractions? • In decimal: • As fractions : 1/5
How could we represent fractions? • In decimal: • As fractions : 1/5 • As decimals : 0.2
Column Pattern • What goes to the right of 1’s column?
Column Pattern • Negative powers of two: 2-3 = = = 0.125
Number • Binary decimal: 10.112 = 2 + 0.5 + 0.25 = 2.7510
Number • Binary decimal: 0.10012 = 0.5 + 0.0625 = 0.562510
Number • Binary decimal: 0.10102 = 0.5 + 0.125 = 0.62510
Missing Numbers • Where is 0.6? 0.10012 = 0.5 + 0.0625 = 0.562510 0.10102 = 0.5 + 0.125 = 0.62510
More Digits • An attempt with 11 decimal digits:
More Digits • With fixed decimal, adding digits… • To left of decimal: Bigger values • To right of decimal:More accurate values
Decimals are an Approximation • Regardless, some values will be hard • Decimal has same issue: • What is 1/3 ?? What is 2/7 ??
Fixed Decimal Problems • Fixed decimal points waste space: 100,000,000,000,000,000 vs 1017 0.000000000000025 vs 2.5 x 10-14
Fixed Decimal Problems • Fixed decimal points waste space: 100,000,000,000,000,000 vs 1017 0.000000000000025 vs 2.5 x 10-14 • In computers, space is precious • Computers use a floating decimal point(Like scientific notation)
Floating Point • Bits used to represent 3 parts: • Sign • Exponent • Fraction (or Mantissa)
Sign • 0 = positive, 1 = negative
Exponent • Binary integer in excess notation • Gives power of 2 to multiply by 100 = 0 So 20
Mantissa • Fractional Value • Always a decimal 1000 = 0.5
Examples + 20 x 0.5 = + 1 x 0.5 =+ 0.5
Examples - 23 x 0.5625 = - 8 x 0.5625 = -4.5
Examples + 2-4 x 0.25 = + 0.0625 x 0.25 = +0.015625
Floating Point Math is HARD • XOR the signs • Calculate new exponent • Excess Notation – different math rules! • Calculate new mantissa • Normal binary multiplication
Choices, choices • Choices • More bits to exponent • More bits to mantissa • How we represent each • What is our excess start point? • Do mantissas have to start with 1?
32 Bit Floating Point • PC processors are 32 or 64 bit • Size of data they can work on at one time • IEEE specifies conventions for floating points:
Remember… • Decimals are approximate • 32 bit float gives 6-7 significant decimal digits • 64 bit float gives 15-16 significant decimal digits