Re: floating point calculation bug?
- From: "K. Sung" <sungk@xxxxxxxxxx>
- Date: Thu, 16 Feb 2006 10:17:39 -0500
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
- References:
- floating point calculation bug?
- From: Kyongje Sung
- floating point calculation bug?
- Prev by Date: Problem of Java, Help!
- Next by Date: Re: Searching a Sorted Matrix Without Using a Loop
- Previous by thread: Re: floating point calculation bug?
- Next by thread: Bounding Circle / Ellipse Function
- Index(es):
Relevant Pages
|
Loading