www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - problem with isnan

reply Charles Hixson via Digitalmars-d-learn writes:
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?
Nov 10 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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.
Nov 10 2016
next sibling parent reply Charles Hixson via Digitalmars-d-learn writes:
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.
Nov 10 2016
parent Edwin van Leeuwen <edder tkwsping.nl> writes:
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)
Nov 11 2016
prev sibling parent reply pineapple <meapineapple gmail.com> writes:
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.
Nov 11 2016
parent reply Charles Hixson via Digitalmars-d-learn writes:
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.
Nov 11 2016
parent reply John C <johnch_atms hotmail.com> writes:
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.
Nov 11 2016
parent Charles Hixson via Digitalmars-d-learn writes:
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.
Nov 11 2016