|
From: | Albert Graef |
Subject: | Re: [q-lang-users] [Chicken-users] Re: IEEE float arithmetic |
Date: | Wed, 21 Jun 2006 07:54:09 +0200 |
User-agent: | Mozilla Thunderbird 1.0.7 (X11/20050923) |
John Cowan wrote:
The expression "f != 0.0 && f == f + f" will work, I think. 0.0 and NaN are rejected by the left side of "&&", and all other finite values by the right side.
Thinking about it some more I think that "!isnan(f) && isnan(f-f)" (given John's definition of isnan()) might be an even better way to do this. f-f can never be nan on an IEEE float system unless f is either nan or inf. And with non-IEEE floats this test should always fail because (presumably) f==f will always be true and hence isnan will always be false. Right?
This test only relies on the algebraic properties of inf and nan and should be about the most efficient way to do it, too, as it just needs a single subtraction and two comparisons.
-- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: address@hidden, address@hidden WWW: http://www.musikinformatik.uni-mainz.de/ag
[Prev in Thread] | Current Thread | [Next in Thread] |