#1,094 – Positive and Negative Infinity

Because .NET uses the IEEE 754 standard to represent floating point numbers, it allows representing both positive and negative infinity.  The two values of infinity are special values that can be represented by the 32-bit float type or the 64-bit double.  Mathematically, infinity is a concept that represents a value greater than any other real number (positive infinity), or smaller than any other real number (negative infinity).

You can specify a value of infinity using the PositiveInfinity and NegativeInfinity static properties of the float class.

            float posInfinity = float.PositiveInfinity;
            float negInfinity = float.NegativeInfinity;

In Visual Studio, the debugger will list these values as Infinity or -Infinity.


You can also generate a positive or negative infinity value as a result of dividing a positive or negative number by zero.  Doing these calculations does not result in an exception.

            float posInfinity = 1.0f / 0;
            float negInfinity = -1.0f / 0;