# Floating-point Numbers Aren't Real

(Difference between revisions)
 Revision as of 16:14, 14 December 2008 (edit)← Previous diff Revision as of 16:18, 14 December 2008 (edit) (undo)Next diff → Line 1: Line 1: - Floating-point numbers are not real numbers in the mathematical sense. Real numbers have infinite precision; floating-point numbers have fixed precision, and resemble "badly-behaved" integers. If you have access to a 32-bit platform with single-precision IEEE floating-point, like '''float''' in C++ on Windows, assign 2147483647 (the largest signed integer) to a float variable ('''x''', say), and print it. You'll see 2147483648. Now print x - 64. Still 2147483648. Now print x-65 and you'll get 2147483520! Why? Because the spacing between adjacent floats in there is 128. IEEE floating-point numbers are fixed-precision numbers based on base-two scientific notation: $1.d_1d_2d_3...d_(p-1)\times 2^e$. + Floating-point numbers are not real numbers in the mathematical sense. Real numbers have infinite precision; floating-point numbers have fixed precision, and resemble "badly-behaved" integers. If you have access to a 32-bit platform with single-precision IEEE floating-point, like '''float''' in C++ on Windows, assign 2147483647 (the largest signed integer) to a float variable ('''x''', say), and print it. You'll see 2147483648. Now print x - 64. Still 2147483648. Now print x-65 and you'll get 2147483520! Why? Because the spacing between adjacent floats in there is 128. IEEE floating-point numbers are fixed-precision numbers based on base-two scientific notation: $1.d_1d_2d_3...d_(p-1)\times 2^e$. The spacing between two consecutive numbers is $2^(1-p+e)$, which can be approximated by $\varepsilon$
Floating-point numbers are not real numbers in the mathematical sense. Real numbers have infinite precision; floating-point numbers have fixed precision, and resemble "badly-behaved" integers. If you have access to a 32-bit platform with single-precision IEEE floating-point, like float in C++ on Windows, assign 2147483647 (the largest signed integer) to a float variable (x, say), and print it. You'll see 2147483648. Now print x - 64. Still 2147483648. Now print x-65 and you'll get 2147483520! Why? Because the spacing between adjacent floats in there is 128. IEEE floating-point numbers are fixed-precision numbers based on base-two scientific notation: $1.d_1d_2d_3...d_(p-1)\times 2^e$. The spacing between two consecutive numbers is $2^(1-p+e)$, which can be approximated by $\varepsilon$