Re: floating point calculation bug?



Thanks for all your comments.
These help me a lot.

Thanks again.

Kyongje Sung wrote:


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

  • floating point calculation bug?
    ... 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. ... I'm using Mac OS X (tiger) and MATLAB 7.1. ...
    (comp.soft-sys.matlab)
  • 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: Dumbfounding Loop Result
    ... I stated that matlab could get different results from +c than from ... Since the true sum of a and b, 13000000000000003, is odd, this sum must ... This demonstrates how the associative law of addition can fail with floating ... very different from a+b and therefore possibly possess a different rounding ...
    (comp.soft-sys.matlab)
  • Re: Fixed point simulation speed: any clever ideas on why my fi objects are running so slow?
    ... I'm transitioning my communications receiver floating point model ... My fixed point model using the matlab fixed point ... and more than 95% of the sim time is in one ... embedded.fi.fi which is the fi object constructor. ...
    (comp.dsp)

Loading