floating point calculation bug?



I'm having a problem in doing simple addition and subtraction with
floating numbers.

Following is the problem.

a = 17.9
b = 16.1
then,
(a - 1.8) == b
gives 0, which means that (a - 1.8) is not equal to 16.1.

If I try following, it is ok.
a = 12.9
b = 11.1
(a - 1.8) == b gives '1'.

It looks like MATLAB has a problem in dealing with decimal places.
Is this known to everyone already?
I thought this kind of problem only happens in MS product...

FYI, I tried following to solve the problem temporarily.

a = 17.9
b = 16.1
then,
round((a - 1.8)*10)/10 == b
gives correct answer, which is '1'.

I'm using Mac OS X (tiger) and MATLAB 7.1. I also tried the above
problems on PC with MATLAB7.0, it has the same problem.

K. Sung
.



Relevant Pages

  • Re: floating point calculation bug?
    ... Kyongje Sung wrote: ... I'm having a problem in doing simple addition and subtraction with ... floating numbers. ... It looks like MATLAB has a problem in dealing with decimal places. ...
    (comp.soft-sys.matlab)
  • Re: quick question
    ... > Any suggestion how I can output the subtraction as zero?!! ... Floating point arithmetic is approximate. ... but the relevant reason in the present case is that floating point numbers ...
    (comp.lang.cpp)
  • Re: tiny values in matrix from rounding error?
    ... I'm doing row operations on a matrix and I've used ... output from matlab of it happening. ... As you can see they should all be zero, but maple displays them as *. ... one works with floating points vs exact rationals, ...
    (comp.soft-sys.matlab)
  • Re: background subtraction in x-rays
    ... i am working on MATLAB and am restricted to MATLAB as ... though background subtraction seems a very common topic ... image as my operating image which is a digital x-ray. ...
    (sci.image.processing)
  • Re: Floating point subtraction rounding error (NOT display error)
    ... arcsin, and apparently it's because floating point subtraction is having ... point subtraction routines has escaped detection. ... for that last digit would prevent subtraction errors from compounding. ...
    (comp.lang.python)

Loading