|
From: | Abdulaziz Ghuloum |
Subject: | [Chicken-users] Re: IEEE float arithmetic |
Date: | Tue, 20 Jun 2006 19:23:28 -0400 |
User-agent: | Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.12) Gecko/20050915 |
John Cowan wrote:
Here are some handy C routines for detecting infs and nans that I worked out with Albert Gräf (the Q author): int isnan(double f) { return !(f == f); } int isinf(double f) { return f == f + 1.0; } The first one works because any comparison involving a NaN is always false. In the second one, obviously no finite argument can return true, and although NaN + 1.0 gives NaN, it will still not compare equal to itself!
The second test is obviously bogus since f==f+1.0 for large values of f. (try 1e16) Aziz,,,
[Prev in Thread] | Current Thread | [Next in Thread] |