Java.lang.Double.isInfinite() Method


Advertisements


Description

The java.lang.Double.isInfinite() method returns true if this Double value is infinitely large in magnitude, false otherwise.

Declaration

Following is the declaration for java.lang.Double.isInfinite() method

public boolean isInfinite()

Parameters

NA

Return Value

This method returns true if the value represented by this object is positive infinity or negative infinity, else false.

Exception

NA

Example

The following example shows the usage of java.lang.Double.isInfinite() method.

package com.tutorialspoint;

import java.lang.*;

public class DoubleDemo {

   public static void main(String[] args) {

      Double d1 = new Double(1.0/0.0);
      Double d2 = new Double(0.0/0.0);
  
      // returns true if positive or negative infinity
      System.out.println(d1 + " = " + d1.isInfinite());
  
      // returns false for other cases
      System.out.println(d2 + " = " + d2.isInfinite());
   }
}  

Let us compile and run the above program, this will produce the following result −

Infinity = true
NaN = false

java_lang_double.htm

Advertisements