[Ns-developers] Bug in shadowing.cc

Mathieu Lacage mathieu.lacage at sophia.inria.fr
Mon Jan 28 23:02:26 PST 2008


On Mon, 2008-01-28 at 11:58 +0100, Marcello Caleffi wrote:
> In the function Shadowing::Pr() the avg_db is calculated as
> -10.0 * pathLossExp_ * log10(dist/dis0)
> without checking if dist is equal to 0, as happens if the send and  
> the recv node have the same position. If so, an arithmetic exception  
> happens.
> 
> What about adding a check as the following:
> if (dist == 0)
>     dist = 1e-23;
> before the avg_db computation?

A more useful test would be:

if (dist <= 1e-23)
    dist = 1e-23;

or:

dist = std::max (dist, 1e-23);


i.e., you can't rely on equality testing of double/float entities except
in a few very rare cases.

Mathieu


More information about the Ns-developers mailing list