swarm-support
[Top][All Lists]
Advanced

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

Re: [Q] on the precision of double variables


From: William S. Shu
Subject: Re: [Q] on the precision of double variables
Date: Wed, 07 Jul 1999 11:04:06 +0100

Norberto Eiji Nawa wrote:

> 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]) {
>

The internal representation of real numbers (floats, doubles, etc.)  in 
machines is not
exact, and so you do not test for their equality.  Instead, you test if their
difference is within a given tolerance.  e.g.,
    while (abs(currentPrice - [tempBidOffer getPrice]) > EPS) {.
                ....

Where EPS is the tolerance (e.g., #define  EPS 0.01).  abs(x) obtains the 
absolute
value, just in case the differnce is negative.

William.



                  ==================================
   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]