Changing NaN values not working

 

Hello all

I looked on past posts here and elsewhere, tried, tried and tried but still I am stuck. Can anyone lend a hand?  I want to change NaN values with zero. This is simply my code:

        double a=5;
        double b=0;
        double c=a/b;
   
        if(MathIsValidNumber(c)) c=c;
         else c=0; 
        Comment(c);

When I Compile no error appears. But EA does not work.

Any hint would be appreciated... Thanks!
 
        double a=5;
        double b=0;
        double c=a/b;

A division by zero aborts your EA immediately. Any instruction following that will not be executed.

 
lippmaje:

A division by zero aborts your EA immediately. Any instruction following that will not be executed.

Thanks a lot.

Is there any way to change NaN by zero?
 
mohammad gerami:
Thanks a lot.

Is there any way to change NaN by zero?

I don't understand this?

 
mohammad gerami:
Thanks a lot.

Is there any way to change NaN by zero?
Avoid the division by zero. Instead of trying to catch your mistake after your ea has already crashed, verify that b isn't zero before doing the unthinkable. Then you can assign 0 to your return value instead of trying to rediscover mathematics.
 
lippmaje:

I don't understand this?

I mean is there pre-defined code for changing NaN to zero
 
La_patates:
Avoid the division by zero. Instead of trying to catch your mistake after your ea has already crashed, verify that b isn't zero before doing the unthinkable. Then you can assign 0 to your return value instead of trying to rediscover mathematics.

Thanks a lot

I was helpful

 
mohammad gerami:
I mean is there pre-defined code for changing NaN to zero
Zero is a number.
Reason: