views:

32

answers:

1
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.?

+4  A: 

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.

Benjamin Baumann
@Benjamin, Thanks..... Thanks a lot... :-)
bjoy
@Benjamin.. Double.IsInfinity() doesnt handle -ve infinity, what we have to do for that..???
bjoy
Weird. Double.IsInfinity should match +oo and -oo like said in http://msdn.microsoft.com/en-us/library/system.double.isinfinity%28v=VS.90%29.aspx I tried and it works both with positive and negative infinity.
Benjamin Baumann