Lec 5 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008
http://www.youtube.com/watch?v=Pfo7r6bjSqI&feature=BFa&list=PL7BC1DAED2189CFA6&lf=BFa
Python has two different kinds of numbers. Aside from integers (int) it has arbitrary precision. When going over 2 billion there is a L appended to the answer, which means it's a Long answer, and it's not as precise. Python also has float numbers, which are floating point numbers, used for real numbers. Python represents numbers using IEEE floating point standard, IEEE 754. x=0.1 results in 0.100000000001, as scientific notation. We represent floating point numbers as mantissa and exponent. 1<=mantissa<2. exponent is in the range of -1022 to +1023. Computers have words, which are 64 bits. We use 1 bit for the sign, 11 for the exponent, and 52 for the mantissa. This gives us 17 decimal digits of precision. Let's look at 1/8. That's 0.125. In Base 10 = 1.25 x 10^-1. In Base 2 = 1.0 x 2^-3. How about 1/10? In base 10 it's 1 x 10^1. In Base 2 it's a problem. On most computers if printing decimals, because of repeating, it would have to display a long list of numbers. Python uses the repr function. If value of s is 0.9999999999989 and we use print s, we get 1.0, that's because of rounding.
Worry about == on floats. If we get a square root of 2 into variable a and then do a*a==2 we will get false, because of accuracy errors. A*A would be 2.000000000004. We can't enumerate all guesses of reals as opposed to integers, that's because reals are uncountable. We can use the method: guess, check and improve. Successive approximation is an important concept. Every time we start with a guess, initial guess, then iterate over some range, then if f(guess) is close enough then return the guess. If not close enough, better guess. The function assert tests the variables.
Comments
So I was surprised not to see the next IT notes.
So then, I logged on and saw it, meaning it was set to private as I'm your friend on livejournal and only friends can see private posts... Does that make sense?