The IEEE-754 (+/- infinity) have two values, defined as infinity. Since double is a floating point, it follows these rules. However, if you were to use an arbitrary type of precision (e.g. BigDecimal ), you could implement such a test - for example,
public static void main(String[] args) {
BigDecimal ONE = BigDecimal.ONE;
BigDecimal THREE = new BigDecimal("3");
BigDecimal THIRD = ONE.divide(THREE);
System.out.println(THIRD);
}
Throws an exception
An exception in the stream "main" java.lang.ArithmeticException: Non-limiting decimal extension; no exact representable decimal result.
source
share