from Hacker News

Your programming language does not know about elementary mathematics

by malloc47 on 9/3/12, 5:53 PM with 2 comments

  • by lutusp on 9/3/12, 6:16 PM

    It's somewhat predictable that the claim is based on floating-point examples. Computer floating-point numerical processing reliably fails many kinds of common-sense logical test.

    Those interested in serious computer mathematics have remedies -- instead of floating-point values, use integers or ratios where possible, as Sage (http://www.sagemath.org/) does. In Sage, one discovers that 3456/7263 times 21/996 equals 224/22327, rather than 0.010032695839118555, as one might expect from less specialized programming environments.

    Or one can increase the size of floating-point mantissas, something not possible in a non-specialized programming environment, but always available in environments designed for serious mathematics. This is less satisfactory than avoiding floating-point altogether, of course.

    To the student programmer, this simple advice -- always prefer integers over floating-point values, and never use a floating-point value as a loop index.

  • by pwg on 9/3/12, 10:08 PM

    The author of the blog seems to be unaware of this information regarding floating point binary values:

    What Every Computer Scientist Should Know About Floating-Point Arithmetic

    http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.ht...