[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in example code for isnan in autoconf info
From: |
David Cournapeau |
Subject: |
Bug in example code for isnan in autoconf info |
Date: |
Sun, 21 Sep 2008 00:53:22 +0900 |
User-agent: |
Thunderbird 2.0.0.16 (X11/20080724) |
Hi,
In section 5.5.1 (portability of C functions), there is a mention of
isnan and isinf. A portable replacement for isinf is suggested when not
available. Unfortunately, the function is wrong on two important aspects:
- isnan(x-x) returns true for x being inf and Nan. But isinf(NaN) is
false
- also, some compilers optimize the x-x to 0, this making it fail too.
To solve 1, I would suggest to define isnan and isfinite as basis, and
isinf as a compound of those two. The following definition for isfinite:
#define isfinite(x) \
!isnan((x)-(x))
Should be ok.
For 2, I would suggest using ((x) + (-x)) instead of ((x)-(x)). I am not
really familiar with what IEEE-754 permits, but ((x) + (-x)) seems to
work much more often than ((x)-(x)) for compilers which optimize
aggressively.
regards,
Davud
- Bug in example code for isnan in autoconf info,
David Cournapeau <=