[CS61C FA20] Lecture 06.2 - Floating Point: Floating Point — Transcript
Full transcript
- 0:00and welcome back when last we left our
- 0:03hero we saw that
- 0:04maybe there's an idea of not just
- 0:07locking in these six bits and saying
- 0:09that the binary point is
- 0:10two in from the right but maybe there's
- 0:12another input on the side that can
- 0:14actually
- 0:15change where that binary point is and
- 0:18that second input
- 0:20is the aha with floating point
- 0:23so again before we've locked in fixed
- 0:26point we fix it there
- 0:28but what if i were able to also pass in
- 0:31another input which tells you where the
- 0:34binary point might be
- 0:35and that allows the binary point two
- 0:37drum roll please
- 0:40float float it's not fixed
- 0:43it can float and that beautiful idea of
- 0:46it floating back and forth
- 0:47is the power of this representation it's
- 0:50like another level of abstraction rather
- 0:51than locking it here
- 0:52i'm now abstracting away and saying what
- 0:54if it's more general now i can now move
- 0:56it where it is
- 0:57so that's just really amazing so that's
- 0:59a good example
- 1:01here's 0.1640625 it's in binary
- 1:05if i represent this in five bits and i
- 1:07choose where to put the binary point
- 1:08okay
- 1:09so here is this i've got point zero it
- 1:11says here point zero
- 1:13zero 10101 at 101.01 and then all the
- 1:17zeros
- 1:19so all i kind of need to know see the
- 1:22guys in blue
- 1:23all the need to know is i need to
- 1:25somehow send
- 1:26these five bits if i could somehow send
- 1:28those five bits i need to send the zeros
- 1:30before it or zero's after it
- 1:31or over here i don't need to send those
- 1:33it's just default it's always zero
- 1:35i need to i need i almost need to send
- 1:37you where the energy is where are the
- 1:38ones and zeros that are interesting
- 1:40but i kind of need to freeze it on the
- 1:41left side and the right side with ones
- 1:42and the zeros outside of it
- 1:44so if i could just send that set and
- 1:47with my
- 1:47other input that's the key idea i tell
- 1:50you oh
- 1:50the binary point should be two to the
- 1:52left of the leftmost
- 1:54one so i would say like you know somehow
- 1:56minus two
- 1:57sitting at minus two that tells you it's
- 1:59over there
- 2:00and on this guy i'm sending 10101.
- 2:04so that's kind of cool so you can
- 2:05imagine taking two inputs this
- 2:07is the energy i say what the energy is
- 2:09and this is
- 2:10where the the floating point would be
- 2:13and that's amazing that's amazing
- 2:17so that is the idea we're gonna have
- 2:20some fields to our representation one
- 2:22field tells you kind of where the energy
- 2:24is
- 2:24and one field tells you in a way the
- 2:26exponent tells you where it is it's
- 2:28it's multiplied times two to the what
- 2:30right it's times two to the
- 2:31minus two here's two to the minus two
- 2:33because it's two over okay it's the
- 2:35quarter this is a times a quarter
- 2:36so what it's saying is it's saying
- 2:40i want to be able to have this exponent
- 2:42for where that moves every time i move
- 2:43it to the left it's multiplying by a
- 2:44factor of two so it's really what two to
- 2:46the what
- 2:47two to the zero it says it's exactly
- 2:48where you think it is to the one says
- 2:50move it you know move it one to the
- 2:51to the left and now i have a zero to the
- 2:53right etcetera
- 2:54is that cool or one to the right move
- 2:56one to the right i guess what is but one
- 2:57to the right okay
- 2:59so because the binary point
- 3:02where it is it's different from the
- 3:03actual stored bits what i call the
- 3:05energy
- 3:06now i can do large and small numbers now
- 3:08i've got the first thing i can do really
- 3:09small numbers or really big numbers
- 3:11or big and small and i got it so let's
- 3:13now review scientific notation
- 3:15in decimal back in the old days now
- 3:18we're in i think we're probably in
- 3:20physics class maybe ap maybe chemistry
- 3:22back in high school 9th or 10th grade
- 3:24if you remember here are some words just
- 3:26to remind you what these words mean
- 3:28i had a decimal point that's the obvious
- 3:30thing i've got the radix which we call
- 3:32the base
- 3:33i've got the exponent and i've got the
- 3:35mantissa on the left
- 3:36okay so if i live in normal form
- 3:41normal form says that i always have a
- 3:44single
- 3:45digit to the left of the decimal point
- 3:48so i don't have
- 3:49if i want to store 1 times 10 to the
- 3:50minus ninth okay so
- 3:52or a nano something i wouldn't store it
- 3:55as
- 3:550.1 times 10 to the 8th and i would not
- 3:58store it as 10 or 10 to the minus 10
- 4:00even though they're equivalent
- 4:00mathematically i would not do that
- 4:02because they're not in normalized form
- 4:04so we're going to go with a normalized
- 4:06form there
- 4:07so that's pretty cool so let's see what
- 4:11that looks like when we go to
- 4:13binary same idea
- 4:16three out of those four words are
- 4:17exactly the same mentis is there the
- 4:20exponents up there the base is base two
- 4:22not base ten
- 4:22and now it's the binary point we call
- 4:26this
- 4:27floating point numbers officially
- 4:28floating point numbers and if you've
- 4:30ever seen the phrase
- 4:32in c float that's it
- 4:35this is what happens we're storing this
- 4:37this story in this way we're storing in
- 4:39this way
- 4:40in normalized form where on the left is
- 4:42always going to be a one
- 4:44that's the important thing always going
- 4:45to be one to the left of the binary
- 4:47point
- 4:48in normalized form this is it i feel
- 4:50like i
- 4:51always it's such a delight to teach
- 4:53somebody something new for the first
- 4:54time and this is it this is
- 4:55the this is the beginning of what we
- 4:57call the ieee floating point
- 4:59designation so here's normalized form
- 5:02you're gonna say but dan
- 5:04if every number starts at one point
- 5:06something you might say to me
- 5:07why do you have to transmit it why would
- 5:09you store the one on the left if it's
- 5:11one on the left
- 5:12always there's always going to be one on
- 5:13the left unless it's all zeros there's
- 5:15gonna be a leading one
- 5:16why store it where it's always gonna be
- 5:18one and you're like
- 5:20i'm you're right so we actually don't
- 5:22store it we only store
- 5:23the number to the right which is the
- 5:25significant
- 5:26so we're one point the one point is
- 5:29always kind of default there
- 5:32yyyy is our exponent so this exponent
- 5:37goes here
- 5:38here's a significant there and you're
- 5:40going to say well dan we probably should
- 5:41have some negative numbers too
- 5:43and you know to make this easy what
- 5:45we're going to do is
- 5:46let's actually use a sine magnitude
- 5:48model so that left is a sine bit
- 5:51so there we go s is your sign bit bloop
- 5:55exponent are these eight bits there that
- 5:57returns two to the y
- 5:58and the significant are the x's
- 6:00represented there with 23 bit that's a
- 6:02lot
- 6:02one point 23 more bits that's quite a
- 6:04bit actually
- 6:06it's pretty cool and by the way what's
- 6:08this last bit controlling
- 6:10what's that last bit if it's always one
- 6:12point something that last bit is two to
- 6:14the minus 23.
- 6:15so it's one plus two to the minus if i
- 6:18only have a one here and have zeros all
- 6:20in here
- 6:20that last guy is two to the minus 23 if
- 6:22you think about that 23 bits there on
- 6:24the right it's that it's one point this
- 6:25to the minus 23. remember there was
- 6:27there was four bits to the right it was
- 6:28once one sixteenth it was two minus four
- 6:30well 23 bits across
- 6:32two to the minus 23 is the guy all the
- 6:33way on the right what can we do
- 6:36well this just this nothing special
- 6:39nothing more than that no
- 6:40special cases which we're going to see
- 6:41in later lectures
- 6:43we can get to 1.2 times 10 to the minus
- 6:4638
- 6:46really small numbers and up to 3.4
- 6:50times 10 to the 38. that's amazing this
- 6:53is
- 6:53really cool now you're going to say well
- 6:55dan
- 6:56what if they're too large what if i mean
- 6:58that's pretty good
- 6:59that's pretty good and we're going to
- 7:01see the ain't no free lunch coming up
- 7:03back again but we'll talk about that in
- 7:05a second so what if they're bigger than
- 7:06that what if they're either bigger than
- 7:08the high side or
- 7:09smaller than the low side well that's
- 7:11overflow
- 7:12you know i want to restore a number
- 7:14bigger than that i what if i double it
- 7:15and double that
- 7:16and i can't always in forever do that
- 7:18double that double that i got a fixed
- 7:19bit
- 7:20bit width at some point it's going to be
- 7:22bigger than i can store
- 7:23we call that overflow what if it's even
- 7:25smaller than it what if it's half of
- 7:26that half of that on the negative side
- 7:28half
- 7:29it should be double a negative number
- 7:31i'm sorry if you double the negative
- 7:32number and keep
- 7:33pushing the left the left side it's also
- 7:35overflow
- 7:36some people call it negative overflow
- 7:37but it's also overflow on the big sides
- 7:40on the ends towards infinity always
- 7:42overflow sometimes the left they call it
- 7:43negative overflow
- 7:45what if they're too small aha
- 7:49underflow you thought that the negative
- 7:51infinity was
- 7:52under flow it's not if that's overflow
- 7:54that's not a flow underflow is towards
- 7:55zero what if i take a number and have it
- 7:57and have it and have it
- 7:59and it keeps getting smaller and smaller
- 8:00at some point i reach the limit
- 8:02of what i can do and one past
- 8:05that is underflow i would probably would
- 8:07say it's zero even though there is some
- 8:09number nope
- 8:10the closest number that i can store to
- 8:12what you're asking me for is zero
- 8:13so i kind of underflowed to zero and
- 8:15that's that's a problem because it means
- 8:17that
- 8:17oh i made some fractional amount but
- 8:19then it says zero but it's not really
- 8:20zero it's close to zero that's an issue
- 8:22so again underflow is close to zero
- 8:25overflow
- 8:26is on the sides we'll just call it
- 8:27overflow in 621c rather than negative
- 8:29overflow but that's right what would
- 8:31help think about what would help reduce
- 8:33the chances of overflow and underflow
- 8:36throw more bits at it right throw more
- 8:38bits at the problem
- 8:40so here is the ieee 754 floating point
- 8:44standard used in every computer you have
- 8:46access to
- 8:47that's it sign bit
- 8:50eight exponent bits 23 significant bits
- 8:54that's great by the way just a refresher
- 8:56one is going to mean
- 8:57a negative number and 0 is going to be a
- 8:59positive number
- 9:01so that's pretty cool now we mentioned
- 9:04this before to pack more bits the
- 9:06leading one is going to be implicit
- 9:07remember that's normalized form and why
- 9:09store that one if it's always going to
- 9:10be a one so
- 9:11that's pretty cool if i actually want
- 9:13more
- 9:14if i want i want to have more resolution
- 9:16i want to reduce the chance of
- 9:18overflow or underflow throw more bits of
- 9:20the problem call it a double
- 9:22so we'll have actually a double for our
- 9:24significant for that i have 52 bits for
- 9:26that
- 9:28so what's always true is the significand
- 9:30is between
- 9:31zero and one for normalized numbers
- 9:33because if you remember it's one point
- 9:36all those bits 23 or 52. think about
- 9:38that one point this
- 9:40so this the this the significant is
- 9:42point
- 9:43something goes from zero if it's all
- 9:45zeros to all ones but it's still a
- 9:46fractional number
- 9:48it's probably with 23 it is one
- 9:51over two to the 23 away from one so it
- 9:53is
- 9:54um i don't know how to say that it's a
- 9:57it's a
- 9:57number very close to one how close is it
- 9:59to one one
- 10:01over two to the 23 away from 1. that's
- 10:04how it is
- 10:05and uh here's the interesting thing 0
- 10:09has no leading one we said this is weird
- 10:10case that 0 has no leading 1
- 10:12so we're going to reserve the exponent
- 10:14value of all zeros
- 10:16just for zero which is great so now i
- 10:19have
- 10:19exponent of zero so i wanna store zero
- 10:22there's a zero
- 10:23there's a zero and ah wait wait sine bit
- 10:26do you remember our issue with sine bits
- 10:28with sine magnitude i got two zeros
- 10:33what do you think we got two zeros here
- 10:35too
- 10:37so here's the other part that's
- 10:39interesting
- 10:40if zero is the smallest exponent
- 10:44in terms of the bid pattern and we go up
- 10:47wouldn't it be nice if all zeros
- 10:51here's the thing all zeroes were the
- 10:54smallest one and we kept going up
- 10:55continually not having to wrap like
- 10:57remember signed
- 10:57it starts in the middle goes up and then
- 10:59it snaps over here and does this thing
- 11:01i want it to be zero all zeros is the
- 11:02smallest one and go up
- 11:04but if i want the small here's the part
- 11:06that's a little weird i want that
- 11:07smallest one
- 11:08to be in the negative because i want to
- 11:11do fractional numbers right i want that
- 11:13to be two to the
- 11:14negative number so if i want all zero
- 11:16bit pattern just might be a negative
- 11:17how does this going to work okay
- 11:22so here's the designer the designers
- 11:24went back to the drawing board they said
- 11:26we want to use if i have no floating
- 11:28port hardware by the way back in the day
- 11:29they used to have
- 11:30explicit floating point hardware and we
- 11:33still have that
- 11:34but if i didn't in the early days of
- 11:36machines they didn't have special
- 11:37purpose floating power they just had a
- 11:38normal cpu
- 11:39but they want to be able to use the cpu
- 11:41to compare and do things to do some
- 11:43manipulations with
- 11:44floating point numbers so they came up
- 11:46with the idea that
- 11:48bigger integer exponents are bigger
- 11:49numbers the smaller ones are fractional
- 11:51numbers
- 11:52and they thought to themselves they said
- 11:54think about the odometer the only way to
- 11:55do that is that bias notation
- 11:58so therefore kind of a really small bit
- 12:00patterns very few numbers and low low
- 12:02bid patterns like you're driving the
- 12:04binary odometer a little bit
- 12:05that should be a negative number and a
- 12:07high thing should be a really big
- 12:08positive number well that's a bias model
- 12:11if you think about that that takes this
- 12:12you know zero and this and here's
- 12:14all ones and if you shift them down by
- 12:16some offset
- 12:17then this is going to be overall a
- 12:19negative number and this will be a
- 12:20positive number
- 12:21if this is from 0 to 55 then roughly
- 12:23this would be kind of
- 12:24128 to minus 128 ish somewhere on there
- 12:27and that's pretty good so we'll shift it
- 12:29down by some bias and we'll get what we
- 12:31want
- 12:32love this so bias notation
- 12:35and the bias is subtracted and we've got
- 12:37eight bits you remember how we did eight
- 12:38bits before
- 12:39eight bits is two to the n minus one
- 12:42minus one
- 12:43so two to the n minus one so eight bits
- 12:44two to the n minus one eight
- 12:46n is eight that's 128 minus one is 127.
- 12:50so we call the bias 127. what that
- 12:52really means is you subtract 127 from
- 12:55the value of that so you look at the
- 12:57unsigned value
- 12:58subtract 127 and you've got your actual
- 13:01number
- 13:02so that's it so there's our equation
- 13:03let's take a look at our equation now
- 13:06this is actually a kind of interesting
- 13:07thing minus 1 to the s when s is 0 minus
- 13:101 to the 0
- 13:10is 1. so that's just a normal positive
- 13:12number if s is 1 it's minus 1 to the 1
- 13:14which is minus number so actually that's
- 13:16kind of a cool way to think about the
- 13:17sign bit it's minus 1 to the sign bit
- 13:20times 1 plus significant remember this
- 13:23there's
- 13:23there's the implicit one times
- 13:262 to the exponent whatever the raw value
- 13:29is
- 13:29minus your 127 bias that's it
- 13:33folks that is the ieee 754
- 13:37floating point there's still some more
- 13:38details there but that's pretty cool and
- 13:40double is exactly the same
- 13:41it's just you have more bits for the
- 13:43significant and more bits for the
- 13:44exponent but exactly the same equation
- 13:47that's pretty cool and quad
- 13:50quad is bigger than that same idea just
- 13:52more again bits for the exponent
- 13:54more bits for the significance let me
- 13:55introduce you to my colleague professor
- 13:57velvel
- 13:59kahan he's the father of the floating
- 14:02point standard uc berkeley
- 14:05ieee standard 754 for binary floor
- 14:07arithmetic
- 14:08earn him the turing award the nobel
- 14:12prize in computer science
- 14:14for being the leader of this boy
- 14:17floating point
- 14:18space the ecosystem was chaotic before
- 14:22his team of folks said let's kind of
- 14:24normalize this so that
- 14:26if i calculate something on one computer
- 14:28and bring it to the other computer i've
- 14:28got the different number
- 14:29this was happening all around them and
- 14:31so i would try to compare oh right to
- 14:32the trajectory and it landed here and
- 14:34yours that
- 14:34why because the way the algorithms were
- 14:37the same but the way the floating point
- 14:38was done below the line
- 14:40in the hardware was different on every
- 14:41machine he said that's crazy let's have
- 14:43a standard
- 14:44let's have a way that my calculation can
- 14:46move to your computer remember porting
- 14:47was an issue
- 14:48well it's big indian small indian all
- 14:50these weird things that are different
- 14:52about this answer different sizes
- 14:53it's even worse back in the day in the
- 14:56floating point space your machine was
- 14:58completely different from our machine we
- 14:59couldn't trust our numbers
- 15:01so the scientific community said we got
- 15:02to centralize this he led the team to
- 15:05centralize it came up with ieee standard
- 15:07754
- 15:08and won the turing award back in 1994.
- 15:10amazing right
- 15:11amazing work so we're going to see now
- 15:14more details about this we're going to
- 15:15see
- 15:16does that cover everything well that's
- 15:18almost 90
- 15:19of it in terms of intellectually 90 of
- 15:20this but there's a lot of interesting
- 15:22ideas now that you know the basics of
- 15:24floating point where can we go with that
- 15:26we're gonna see that in the next set of
- 15:27videos see you there
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 06.2 - Floating Point: Floating Point by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 3,100 words across 500 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.