120 likes | 153 Views
Explore the intricacies of floating point numbers, including normalized and denormalized values, rounding rules, and bit operations. Learn how to interpret and manipulate floating point data effectively.
E N D
15-213 Recitation 8/28/08 Jackson Davis (Material blatantly stolen from lecture slides)
Floating Points and You (or, Float Points, you, and datalab) • + • 0x7F800000 • NAN • Lots of values (fraction anything but 0) • But the questions require 0x7FC00000 • And they will remind you other this • Fraction mask (how many bits are those?) • 0x007FFFFF • Exponent mask (how many bits are these?) • 0x7F800000
Aside • Book is mostly awesome • But Not Always (see multi-level vm) • Wikipedia is also awesome • Especially Here • Funny Standard Name-IEEE 754 • Double arrow bullets!
Those Denormalized Things(and why they exist) • Smallest Normalized Value • 0x00800000 • 2^-126 1.18*10^-38 • Largest Denormalized Value • 0x007FFFFF • 0.high (1-2^-26) * 2^-126 1.18*10^-38 • But not the same 1.18*10^-38
They Get Smaller! • Smallest Denormalized Value • 0x0000001 • 0.(small, 2^-23) * 2^-126 = 2^-149 = 1.40*10^-45
A Smaller Example (aka why sign bits make conversion to hex ugly and why my 21-355 homework sucks) • 8 Bits – 4 for Exponent, 4 for Fraction • Bias is??? (drumroll) • 7 (2^(4-1)-1) • Everything is positive • Because things are more happy
Yet Another Normalized Slide (YANS) • Smallest Normalized • 0x10 – 1.0*2^-6 =1/64 • Largest Denormalized • 0x0F 0.15/16 *2^-6 =15/1024 (1/64-1/1024) • Smallest Denormalized • 0x01 0.1/16*2^-6 =1/1024 • Don’t leave him out-Largest Normalized? • 0xEF 1.15/16*2^7 =248
Rounding is fun too (Except when its super confusing-see below) • The only one you need to know • Round to Even • What??? • Goes to nearest number, except when in the middle • Then you go to the nearest even, either + or –
More Practice Time • Round to the nearest integer • 1.5 • 2 • 2.5 • 2 • -1.5 • -2 • -2.5 • -2
How it applies to The Thing Due on Monday • You will be dividing by 2 • And rounding correctly • Some binary number is being divided by 2 • But its the fraction part of a normalized floating point! • Bit shifts are fun here
How it works • Right of the |->getting cut off by shift • blabla0|0 (nice and easy to start) • blabla0 • blabla0|1 • blabla0 (go even) • blabla1|0 • blabla1 (what rounding?) • blabla1|1 • Blabla1 + 1 (blablb?) • What Bit Operations might be nice here?
Sometimes, we chop off more than 1 bit (this super-shamelessly stolen from the lecture slides) • Cutting to 2 decimal places • 2 2/32 10.00011-> • 10.00 2 • 2 3/16 10.00110-> • 10.01 2 ¼ • 2 7/8 10.11100 • 11.00 3 • 2 5/8 10.10100 • 10.10 2 1/2