Pietro Cerutti wrote:

>

> Hi group,

> I always thought that applying a binary operator such as ==, !=, <= or

> >= to two double or float values was an operation which results were

> well defined.

>

> Now, I'm passing a program through splint[1] and it says:

>

> Dangerous equality comparison involving double types:

> l_lnk1->lnk_freq == l_lnk2->lnk_freq

> Two real (float, double, or long double) values are compared directly

> using == or != primitive. This may produce unexpected results since

> floating point representations are inexact. Instead, compare the

> difference to FLT_EPSILON or DBL_EPSILON.

>

> l_lnk1->lnk_freq and l_lnk2->lnk_freq being defined as double values.

>

> Is it really better to write the comparison as

> (l_lnk1->lnk_freq - l_lnk2->lnk_freq < DBL_EPSILON)

> or is splint being over-pedantic in this situation?
I agree with christian.bau's statement: "It is more complicated.";

and also with Flash Gordon's

"It is best to understand the real issues

and then make an appropriate decision

based on your particular situation."

If you take a look at the math functions at

http://www.mindspring.com/~pfilandr/C/fs_math/fs_math.c
the !=, ==, >=, and > operators

are all used to compare double values,

but as far as I can tell, the usage is appropriate.

In the same file,

there are also examples where DBL_EPSILON needs to be, and is, used.

--

pete