Shortest way of checking if Double is “NaN”

As MSDN says, NaN means that result is undefined. With infinities result is defined:

A method or operator returns NaN when the result of an operation is
undefined. For example, the result of dividing zero by zero is NaN, as
the following example shows. (But note that dividing a non-zero number
by zero returns either PositiveInfinity or NegativeInfinity, depending
on the sign of the divisor.)

So, it’s not good idea to tread infinities as NaN. You can write extension method to check if value is not NaN or infinity:

// Or IsNanOrInfinity
public static bool HasValue(this double value)
{
    return !Double.IsNaN(value) && !Double.IsInfinity(value);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)