Double.IsInfinity() Method in C#


The Double.IsInfinity() method in C# is used to return a value indicating whether the specified number evaluates to negative or positive infinity.

Syntax

The syntax is as follows −

public static bool IsInfinity (double d);

Above, the value d is a double-precision floating-point number.

Example

Let us now see an example −

 Live Demo

using System;
public class Demo {
   public static void Main(){
      double d = 5.5;
      Console.WriteLine("Double Value = "+d);
      Console.WriteLine("HashCode of Double Value = "+d.GetHashCode());
      TypeCode type = d.GetTypeCode();
      Console.WriteLine("TypeCode of Double Value = "+type);
      Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d));
   }
}

Output

This will produce the following output −

Double Value = 5.5
HashCode of Double Value = 1075183616
TypeCode of Double Value = Double
Positive Infinity? = False

Example

Let us now see another example −

 Live Demo

using System;
public class Demo {
   public static void Main(){
      double d = 1.0/0.0;
      Console.WriteLine("Double Value = "+d);
      Console.WriteLine("HashCode of Double Value = "+d.GetHashCode());
      TypeCode type = d.GetTypeCode();
      Console.WriteLine("TypeCode of Double Value = "+type);
      Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d));
   }
}

Output

This will produce the following output −

Double Value = ∞
HashCode of Double Value = 2146435072
TypeCode of Double Value = Double
Positive Infinity? = True

Updated on: 03-Dec-2019

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements