in reply to Getting stranger values in subtraction

Computers cannot be trusted with arithmetics...

Have a look at this thread or look for "floating point arithmetic" in Super Search.

  • Comment on Re: Getting stranger values in subtraction

Replies are listed 'Best First'.
Re^2: Getting stranger values in subtraction
by MidLifeXis (Monsignor) on Feb 08, 2016 at 13:55 UTC

    This might be a bit strong. Perhaps "Naive Programmers cannot be trusted to use computers to do arithmetic." :-)

    If you are aware of the limitations based on how the hardware, libraries, and language does arithmetic (iow - know your tools), computers can be used to do the job just fine. I had two courses in this in college that dealt with this topic - one in the math department and one in the CS department. It is a similar concept to students writing down a highly precise, but terribly inaccurate answer on a test because they didn't understand significant digits and error accumulation.

    --MidLifeXis

      Fully agree. In this context -3.5527136788005e-015 seems to be close enough to zero for any practical purpose.

      But this "naive" behavior can be seen so often not only with students but also in real applications for commercial purposes (which costs real money).