digitalmars.D.learn - How to replace the keyword "nan" to check the contract assert?
- Dennis Ritchie (11/11) Mar 20 2015 Hi,
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (12/22) Mar 20 2015 nan cannot be used in comparisons. It is neither greater than nor less
- Dennis Ritchie (2/12) Mar 20 2015 Thanks.
Hi, How do I replace double.init? import std.stdio : writeln; import std.algorithm : uninitializedFill; void main() { double[] arr = new double[6]; uninitializedFill(arr[0 .. $ - 2], 3.25); writeln(arr); assert(arr == [3.25, 3.25, 3.25, 3.25, double.init, double.init]); /* not work */ }
Mar 20 2015
On 03/20/2015 09:24 PM, Dennis Ritchie wrote:> Hi,How do I replace double.init? import std.stdio : writeln; import std.algorithm : uninitializedFill; void main() { double[] arr = new double[6]; uninitializedFill(arr[0 .. $ - 2], 3.25); writeln(arr); assert(arr == [3.25, 3.25, 3.25, 3.25, double.init, double.init]); /* not work */ }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); Ali
Mar 20 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.
Mar 20 2015