float and double type defines constant values to represent the positive infinit, negative infinit and NaN(Not a Number).
Special value Double constant Float constant
NaN double.NaN float.NaN
positive infinit double.PositiveInfinity float.PositiveInfinity
negetive infinit double.NegativeInfinity float.NegativeInfinity
-0 -0.0 -0.0f
Dividing a nonzero number by zero results in an infinite value.
For example:
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(1.0 / 0.0); // Infinity
Console.WriteLine(-1.0 / 0.0); // -Infinity
Console.WriteLine(1.0 / -0.0); // -Infinity
Console.WriteLine(-1.0 / -0.0); // Infinity
}
}
The output:
Infinity
-Infinity
-Infinity
Infinity
Dividing zero by zero, or subtracting infinity from infinity, results in a NaN.
For example:
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine ( 0.0 / 0.0); // NaN
Console.WriteLine ((1.0 / 0.0) - (1.0 / 0.0)); // NaN
}
}
The output:
NaN
NaN