Slashdot Mirror


What Every Programmer Should Know About Floating-Point Arithmetic

-brazil- writes "Every programmer forum gets a steady stream of novice questions about numbers not 'adding up.' Apart from repetitive explanations, SOP is to link to a paper by David Goldberg which, while very thorough, is not very accessible for novices. To alleviate this, I wrote The Floating-Point Guide, as a floating-point equivalent to Joel Spolsky's excellent introduction to Unicode. In doing so, I learned quite a few things about the intricacies of the IEEE 754 standard, and just how difficult it is to compare floating-point numbers using an epsilon. If you find any errors or omissions, you can suggest corrections."

10 of 359 comments (clear)

  1. .9999999984 Post by tonywestonuk · · Score: 5, Funny

    Damn...Missed it! lol

    1. Re:.9999999984 Post by Yvan256 · · Score: 4, Funny

      I see you're still using that Pentium CPU.

    2. Re:.9999999984 Post by Anonymous Coward · · Score: 0, Funny

      This is what happens when you use intel cpus, if you want a ifsrt spto use an athlon and nothing can go rwnog.

  2. Stop with the educational articles by sunderland56 · · Score: 4, Funny

    Look, times are tough for programmers already. Knowing how to do things correctly - like proper floating point math - is one of the ways to separate the true CS professional from the wannabe new graduates. Articles like this just make everyone smarter, and make finding a job that much harder.

    1. Re:Stop with the educational articles by jellomizer · · Score: 2, Funny

      Except for the fact that companies don't care about floating point they are looking for 3+ years on windows 7. 20 years of Linux. and 15 years of .NET.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
  3. Re:float are over by sco08y · · Score: 4, Funny

    Really, the best answer is to store all numbers on the cloud, and just use a 256-bit GUID to look them up when needed.

  4. Not equivalent to Spolsky's article. by John+Hasler · · Score: 2, Funny

    It's missing the irritating cutesy "humor".

    --
    Warning: this article may contain humor, sarcasm, parody, and perhaps even irony. Read at your own risk.
  5. Re:Analog Computers by adonoman · · Score: 2, Funny

    Nobody would expect someone to write down 1/3

    I use base 3, so 0.1 is a perfectly easy number to express in floating point.

  6. Re:Simple, effective and useful by safetyinnumbers · · Score: 2, Funny

    The code on the site for

    function nearlyEqual(a,b)

    contains the line

    if (a==0.0){

    Clearly, this should be

    if (nearlyEqual(a, 0.0)){

    There. What could possibly go wrong now? :)

  7. Re:Simple, effective and useful by Dog-Cow · · Score: 5, Funny

    That would be because 0.1 + 02 is 2.1. :-)