float.nan is not itself ?
Ali Çehreli
acehreli at yahoo.com
Tue Feb 14 11:21:54 PST 2012
On 02/14/2012 07:48 AM, Bernard Helyer wrote:
> On Tuesday, 14 February 2012 at 15:39:37 UTC, Joshua Reusch wrote:
>> Hello,
>>
>> why does this assertion fail:
>>
>> > assert(float.nan == float.nan);
>>
>> there is the std.math.isNaN function which works correctly, but why
>> can I not just use the comparison ?
>>
>> Thanks, Joshua
>
> Use `float.nan is float.nan`; all other expressions with NaNs in them
> will be false (or result in NaN).
In the general case, std.math.isNaN works:
import std.math;
void main()
{
float f;
assert(f is float.nan); // fails
assert(isNaN(f)); // passes
}
Ali
More information about the Digitalmars-d-learn
mailing list