Many computer programmers do not get taught about floating-point properly in college and they assume that it behaves just like real numbers would as the first few programs they write make it seem so. Integer and FP are like horse and donkey. While FP offers a wide range and good precision, it does not offer exact precision similar to integers and mathematical real numbers as one might naively expect from it. Many times these errors add up and become troublesome, so it’s good to have an understanding of the subject. The FP standard which is popularly used in CPUs, virtual machines and languages standards is IEEE 754. Apart from representation, this standard also defines various other bits such as rounding modes and exception handling. Old-skool programmers will probably expect floating-point x/0 to cause a divide-by-zero trap as it does with integers, but this’s not so in IEEE 754 by default.. it lets the process run on and uses special floating point values called -inf and +inf (although languages like Delphi enable traps by default by not following the standard and then we have fun in the Windoze world where a Delphi compiled DLL used in some arcane place like a file selection dialog enables traps and unrelated apps start crashing in various places when they cause traps). There are things a good programmer should know about FP’s accuracy and how to write good floating-point code, and this aptly titled paper is great for it: What Every Computer Scientist Should Know About Floating Point Arithmetic. If you haven’t read this one yet, take some time and read it (all ye C, Java, etcetera etcetera programmers). C99 has a bunch of functions to get/set trap handling behaviour, etc. and glibc includes some more extra convenience functions.
Links
Projects
Smart people
Categories
Archives
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- October 2004
- February 2004
- January 2004
- December 2003
- November 2003
- August 2003
- June 2003
- May 2003
- August 2002
- July 2002
- April 2002
- February 2002
- December 2001
- November 2001
- October 2001
- September 2001
- August 2001
- July 2001
- June 2001
- May 2001
- April 2001
- March 2001
- February 2001
- January 2001
- December 2000
- November 2000
- October 2000
- September 2000
0 Responses to “Know your floating-point”