I want to protect my variable from storing overflow values .
I am Calculating Loss at every level in a tree and at some stages.
- it gives values like 4.94567e+302 ;Is this value Correct .If i compare it(Like Minimum ,Maximum etc) with any other values .Will it give the right answer?
- Some Times it gives negative answer but Formula can not give negative values so surely this kind of value is wrong
I want to do Following thing in my c++ code .
ForExample:
long double loss; //8 Bytes Floating Number
loss=calculate_loss();
if(loss value is greater than Capacity)
do
store 8 bytes in loss abd neglect remaining;
end if
There is a
limits.hin C++, but thiscannot work by definition. The value in
losscan not be greater than its own data type maximum.Your example value of 5 times 10^302 indeed is suspiciously large. Coupled with your statement that you sometimes get unexpected negative values, I suggest you take a good long look at your calculations.
A reasonable guess: you are tinkering with pointers and mix up pointers to integers and floating point numbers. But noone can tell without seeing the code.