How to replace the keyword "nan" to check the contract assert?
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Mar 20 22:35:01 PDT 2015
On Saturday, 21 March 2015 at 04:53:20 UTC, Ali Çehreli wrote:
> nan cannot be used in comparisons. It is neither greater than
> nor less than any value. You cannot even compare it against
> itself. nan==nan would always be false.
>
> The solution is to call std.math.isNaN. In this case, you have
> to split the assert into two. You can achieve the same thing in
> may ways but the following works:
>
> assert(arr[0 .. $ - 2] == [3.25, 3.25, 3.25, 3.25]);
>
> import std.algorithm;
> import std.math;
> assert(arr[$ - 2 .. $].all!isNaN);
Thanks.
More information about the Digitalmars-d-learn
mailing list