swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Q] on the precision of double variables


From: Norberto Eiji Nawa
Subject: [Q] on the precision of double variables
Date: Wed, 07 Jul 1999 17:22:41 +0900

Hello:

Actually, my question this time is not directly related to swarm, but
the response from the swarm community is always so friendly that I
couldn't resist the temptation to post it here.

I have a very trivial loop that looks more or less like this:

        while (currentPrice != [tempBidOffer getPrice]) {
          // processsing...
          currentPrice -= PRICE_STEP;
          // !!! TEST
          printf("currentPrice: %f\n", currentPrice);
        }

where (double) currentPrice, (double) getPrice, #define PRICE_STEP 0.1

In the problematic situation, currentPrice starts with 3.5 and [tempBidOffer
getPrice] is 3.0. The problem is that the stop condition is never satisfied!

Though after some iterations the value displayed by the printf reaches
3.0 (stop condition), sneaking the currentPrice with gdb (actually
ddd, a nice interface for gdb) it reads:

currentPrice: 3.3999999999999999

then    

currentPrice: 3.2999999999999998

then    

currentPrice: 3.1999999999999997

then    

currentPrice: 3.0999999999999996

then

currentPrice: 2.9999999999999996

skipping the stop condition. The printf counterpart always displays the
"expected" value: 3.4, 3.3, 3.2, 3.1, 3.0.

It is actually the symmetric situation reported in
http://www.santafe.edu/projects/swarm/archive/list-archive.9704/0181.html

I am running linux 2.2.9, in a Pentium II machine, using swarm-1.4.1. 

Is this (1) a weird but well known behavior, (2) an expected behavior with a 
trivial
solution or (3) really weird?

Thanks a lot and again, sorry for posting it here.

Eiji

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]