infinity constatn in java

www.‮.iruttual‬com
infinity constatn in java

In Java, there is no built-in constant for infinity. However, you can use the Double.POSITIVE_INFINITY constant from the java.lang.Double class to represent positive infinity in a double-precision floating-point value.

Here is an example of how to use the Double.POSITIVE_INFINITY constant:

public class InfinityConstantExample {
    public static void main(String[] args) {
        double x = Double.POSITIVE_INFINITY;
        System.out.println(x);

        // Check if a value is positive infinity
        if (x == Double.POSITIVE_INFINITY) {
            System.out.println("x is positive infinity");
        }
    }
}

Output:

Infinity
x is positive infinity

Note that the Double.POSITIVE_INFINITY constant is a special value that represents positive infinity in a double-precision floating-point value. It is not the same as a regular double value, and it does not behave like a regular double value in all cases. For example, Double.POSITIVE_INFINITY + 1 is still equal to Double.POSITIVE_INFINITY, and Double.POSITIVE_INFINITY * 2 is also equal to Double.POSITIVE_INFINITY.

To represent negative infinity, you can use the Double.NEGATIVE_INFINITY constant.

Created Time:2017-11-01 22:29:51  Author:lautturi