Reputation: 31
i am using java jdk1.8 version. when i devide any number by zero(0) it shows message "Infinity".While it should shows at runtime ArithmeticException :/zero.What can be the reason.
class division
{
public static void main(String args[])
{
float a=10,b=0;
System.out.println(a/b);
}
}
Upvotes: 2
Views: 60
Reputation: 77063
Mathematically,
x / 0 can be:
As @Bathsheba pointed out in his answer:
Java insists on the IEEE754 standard for floating point.
So, if we take a look at Wikipedia, for example, then we can see that:
Division by zero (an operation on finite operands gives an exact infinite result, e.g., 1/0 or log(0)) (returns ±infinity by default).
Upvotes: 0
Reputation: 234875
No it shouldn't issue an exception.
Java insists on the IEEE754 standard for floating point. This states that a division by a floating point zero yields NaN if the numerator is also zero, +Infinity if the numerator is positive, and -Infinity if the numerator is negative.
Upvotes: 6