Double isInfinite() method in Java with examples
The java.lang.Double.isInfinite() method of Java Double class is a built in method in Java returns true if this Double value or the specified double value is infinitely large in magnitude, false otherwise.
Syntax:
public boolean isInfinite()
or
public static boolean isInfinite(double val)
Parameters: The function accepts a single parameter val which specifies the value to be checked when called directly with the Double class as static method. The parameter is not required when the method is used as instance method.
Return Value: It return true if the val is infinite else it return false.
Below programs illustrate isInfinite() method in Java:
Program 1:
Java
class GFG {
public static void main(String[] args)
{
Double f1 = new Double( 1.0 / 0.0 );
boolean res = f1.isInfinite();
if (res)
System.out.println(f1 + " is infinity" );
else
System.out.println(f1 + " is not infinity" );
f1 = new Double( 0.0 / 0.0 );
res = f1.isInfinite();
if (res)
System.out.println(f1 + " is infinity" );
else
System.out.println(f1 + " is not infinity" );
}
}
|
Output:
Infinity is infinity
NaN is not infinity
Program 2:
Java
class GFG {
public static void main(String[] args)
{
Double f1 = new Double( 1.0 / 0.0 );
boolean res = f1.isInfinite(f1);
if (res)
System.out.println(f1 + " is infinity" );
else
System.out.println(f1 + " is not infinity" );
f1 = new Double( 0.0 / 0.0 );
res = f1.isInfinite(f1);
if (res)
System.out.println(f1 + " is infinity" );
else
System.out.println(f1 + " is not infinity" );
}
}
|
Output:
Infinity is infinity
NaN is not infinity
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#isInfinite(double)
Last Updated :
13 Sep, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...