how to check higher than 'allowed'

 

Hi

How do I check if a sum or an other calculation exceeds the highest possible double (see https://www.mql5.com/en/forum/140395/page2)

I'd like to do

...
double MaxDoub = 1.7976931348623158*MathPow(10,308);
...
int chckMax( double x,double y){
        if (x*y > MaxDoub) return(0)
        else return(1);
}

I guess that it'll cause an Error. But how do I catch that without risking the run of the program?

Thanks in advance,

Gooy

 
gooly: How do I check if a sum or an other calculation exceeds the highest possible double

A sum can NOT exceed highest possible value BY DEFINITION. Since you can't compute first and then check you must reverse the test:

double MaxDoub = 1.79*MathPow(10,308); // Truncate to prevent rounding problem.
bool chckMax( double x,double y){
  return(MaxDoub/x < y);               // if 10/3 < 4 then 10 < 3 * 4
}

I don't know why you even have the question.

 
WHRoeder:

A sum can NOT exceed highest possible value BY DEFINITION. Since you can't compute first and then check you must reverse the test:

I don't know why you even have the question.


Ouch, could have thought of that myself: reverse the test.


I need that to be safe for a simplified calc. of the standard deviation, where I have to sum up the square of the new value.
Anyway, thanks a lot,
Gooly