Search code examples
c#mathinfinite-value

Express mathematical infinity in C#


Is it possible to express (mathematical) infinity, positive or negative, in C#? If so, how?


Solution

  • double.PositiveInfinity

    double.NegativeInfinity

    float zero = 0;
    
    float positive = 1 / zero;
    Console.WriteLine(positive);    // Outputs "Infinity"
    
    float negative = -1 / zero;
    Console.WriteLine(negative);    // Outputs "-Infinity"