Open In App

Double.IsInfinity() Method in C#

Last Updated : 10 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In C#, Double.IsInfinity() is a Double struct method. This method is used to check whether a specified value evaluates to either positive infinity or negative infinity or not. While performing some mathematical operations, it is possible to obtain a result that is either positive infinity or negative infinity. For Example: If any positive value is divided by zero, it results in positive infinity.
 

Syntax: public static bool IsInfinity (double d);
Parameter: 
d: It is a double-precision floating-point number of type System.Double 
 

Return Type: This function return a Boolean value True, if specified value evaluates to either positive infinity or negative infinity, otherwise return False.
Example: 
 

Input  : d = 10 / 0.0 
Output : True

Input  : d = 7.997e307 + 9.985e307
Output : True

Note: 

  • If the result of any floating point operation exceeds Double.MaxValue (i.e 1.79769313486232E+308) is considered as Positive Infinity and if the result is less than Double.MinValue (i.e -1.79769313486232E+308) is considered as Negative Infinity.
  • Floating-point operation return Infinity (Positive Infinity) or -Infinity (Negative Infinity) to indicate an overflow condition.

Code: To demonstrate the Double.IsInfinity(Double) Method
 

CSHARP




// C# program to illustrate the
// Double.IsInfinity() Method
using System;
 
class GFG {
 
    // Main method
    static public void Main()
    {
 
        // Dividing a Positive number by zero
        // results in positive infinity.
 
        double zero = 0.0;
        double value = 10.0;
        double result = value / zero;
 
        // Printing result
        Console.WriteLine(result);
 
        // Check result using IsInfinity() Method
        Console.WriteLine(Double.IsInfinity(result));
 
        // Result of any operation that
        // exceeds Double.MaxValue
        // (i.e 1.79769313486232E+308)
        // is Positive infinity
        result = Double.MaxValue + 9.985e307;
 
        // Printing result
        Console.WriteLine(result);
 
        // Check result using IsInfinity() Method
        Console.WriteLine(Double.IsInfinity(result));
 
        // Result of any operation that
        // is less than Double.MinValue
        // (i.e -1.79769313486232E+308)
        // is Negative infinity
        result = Double.MinValue - 9.985e307;
 
        // Printing result
        Console.WriteLine(result);
 
        // Check result using IsInfinity() Method
        Console.WriteLine(Double.IsInfinity(result));
    }
}


Output: 

Infinity
True
Infinity
True
-Infinity
True

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads