Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we compare whether the result of an arithmetic operation is NaN or infinity..?

double SampleInterval = (PopulationValue - valueOfSignItems) / (SampleSize - noOfSignItems);

if my divisor = 0, sampleInterval wil bcom infinity and it will be = NaN if both dividend and divisor are = 0

i need to do my code when SampleInterval = infinity and in another context when SampleInterval = NaN. How it is possible..?? can any one tel me how can i compare a decinmal value to infinity or to NaN.?

like image 270
Bijoy K Jose Avatar asked Dec 05 '25 12:12

Bijoy K Jose


1 Answers

You must use the Double.IsInfinity() and Double.IsNaN() methods.

if (Double.IsInfinity(SampleInterval))
{
  //TODO
}
if (Double.IsNaN(SampleInterval))
{
  //TODO
}

Don't compare directly to Double.NaN, it will always return false.

like image 125
Benjamin Baumann Avatar answered Dec 08 '25 01:12

Benjamin Baumann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!