problem with isnan

Charles Hixson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 11 12:55:52 PST 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 at 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.


More information about the Digitalmars-d-learn mailing list