Thread overview
problem with isnan
Nov 10, 2016
Charles Hixson
Nov 10, 2016
Adam D. Ruppe
Nov 10, 2016
Charles Hixson
Nov 11, 2016
Edwin van Leeuwen
Nov 11, 2016
pineapple
Nov 11, 2016
Charles Hixson
Nov 11, 2016
John C
Nov 11, 2016
Charles Hixson
November 10, 2016
The line:

assert    (isnan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation));

throws the exception:

core.exception.AssertError@cell.d(285): cell has unexpected curActivation: nan

and I've looked at it backwards and forwards and don't understand why.  It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion.  What am I doing wrong?

November 10, 2016
On Thursday, 10 November 2016 at 16:41:56 UTC, Charles Hixson wrote:
> It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion.  What am I doing wrong?

How did you set it? There are like billions of different NaNs. I'm not sure if isnan checks for all of them. (I'm also not sure that it doesn't, the docs don't specify.)

you might try using std.math.isNaN instead and see what it does.
November 10, 2016
On 11/10/2016 08:47 AM, Adam D. Ruppe via Digitalmars-d-learn wrote:
> On Thursday, 10 November 2016 at 16:41:56 UTC, Charles Hixson wrote:
>> It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion.  What am I doing wrong?
>
> How did you set it? There are like billions of different NaNs. I'm not sure if isnan checks for all of them. (I'm also not sure that it doesn't, the docs don't specify.)
>
> you might try using std.math.isNaN instead and see what it does.
>
It was default initialized by the class instance:

class    Cell
...
float    curActivation;
...

The this method doesn't have any mention of a few variables that are supposed to be default initialized, or which curActivation is one.

I suppose I could set it to be -2.0 or something, but that doesn't really tell me what's going on.
November 11, 2016
On Thursday, 10 November 2016 at 23:45:01 UTC, Charles Hixson wrote:
>> you might try using std.math.isNaN instead and see what it does.
>>
> It was default initialized by the class instance:
>
> class    Cell
> ...
> float    curActivation;
> ...
>
> The this method doesn't have any mention of a few variables that are supposed to be default initialized, or which curActivation is one.


std.math.isNaN should work for the default initialization (at least it does for doubles)

November 11, 2016
On Thursday, 10 November 2016 at 16:47:30 UTC, Adam D. Ruppe wrote:
> On Thursday, 10 November 2016 at 16:41:56 UTC, Charles Hixson wrote:
>> It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion.  What am I doing wrong?
>
> How did you set it? There are like billions of different NaNs. I'm not sure if isnan checks for all of them. (I'm also not sure that it doesn't, the docs don't specify.)
>
> you might try using std.math.isNaN instead and see what it does.

Incidentally, I just recently submitted a PR to fix this.

What probably happened is that you're referring to a limited `isnan` method defined as a unittest utility method in object.d that should have been private but wasn't.

You want to use `isNan` instead.

November 11, 2016
On 11/11/2016 10:31 AM, pineapple via Digitalmars-d-learn wrote:

> On Thursday, 10 November 2016 at 16:47:30 UTC, Adam D. Ruppe wrote:
>> On Thursday, 10 November 2016 at 16:41:56 UTC, Charles Hixson wrote:
>>> It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion.  What am I doing wrong?
>>
>> How did you set it? There are like billions of different NaNs. I'm not sure if isnan checks for all of them. (I'm also not sure that it doesn't, the docs don't specify.)
>>
>> you might try using std.math.isNaN instead and see what it does.
>
> Incidentally, I just recently submitted a PR to fix this.
>
> What probably happened is that you're referring to a limited `isnan` method defined as a unittest utility method in object.d that should have been private but wasn't.
>
> You want to use `isNan` instead.
>
>
Thank you.  Unfortunately:
import    std.math;
        ...
    assert    (isNan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation));

yields:
cell.d(292): Error: undefined identifier 'isNan', did you mean overloadset 'isnan'?

while:
import    std.math;
        ...
    assert    (std.math.isnan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation));

yields:
core.exception.AssertError@cell.d(310): cell has unexpected idno: 636144943519357244

That is, indeed, an unexpected value, unless it's some representation of Nan, in which case it should have passed the assert.  I notice that it doesn't appear to be a float, which puzzles me.
November 11, 2016
On Friday, 11 November 2016 at 20:55:52 UTC, Charles Hixson wrote:
> Thank you.  Unfortunately:
> import    std.math;
>         ...
>     assert    (isNan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation));
>
> yields:
> cell.d(292): Error: undefined identifier 'isNan', did you mean overloadset 'isnan'?

It should be isNaN.
November 11, 2016

On 11/11/2016 01:34 PM, John C via Digitalmars-d-learn wrote:
> On Friday, 11 November 2016 at 20:55:52 UTC, Charles Hixson wrote:
>> Thank you.  Unfortunately:
>> import    std.math;
>>         ...
>>     assert    (isNan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation));
>>
>> yields:
>> cell.d(292): Error: undefined identifier 'isNan', did you mean overloadset 'isnan'?
>
> It should be isNaN.
>
Ok, now it seems the same as std.math.isnan, (i.e., it works properly).  On looking over the error messages more closely (just now) I noticed that the line number had now changed.  Whoops!  It just *LOOKED* like the error hadn't been fixed, where it had actually moved onto the next one.  The hint should have been that it was printing an integer value...I mean besides the changed line number.