R
Razvan
Hi !
I have noticed that the division by zero is handled differently for
integer and float types.
Let me explain better:
public class CDummy // this class prints "Infinity" (division by zero)
{
public static void main(String args[])
{
System.out.println("CDummy.");
float f1 = 1.41356f;
float f2 = 0f;
System.out.println("f1/f2 = " + (f1/f2));
}
}
public class CDummy // this class throws an exception (division by
zero)
{
public static void main(String args[])
{
System.out.println("CDummy.");
int i1 = 1;
int i2 = 0;
System.out.println("i1/i2 = " + (i1/i2));
}
}
What is the reason for this behavior ? Why integers throw exceptions
when dividing by zero while floats just assumes the number is Infinity
(no exception is thrown) ?
Regards,
Razvan
I have noticed that the division by zero is handled differently for
integer and float types.
Let me explain better:
public class CDummy // this class prints "Infinity" (division by zero)
{
public static void main(String args[])
{
System.out.println("CDummy.");
float f1 = 1.41356f;
float f2 = 0f;
System.out.println("f1/f2 = " + (f1/f2));
}
}
public class CDummy // this class throws an exception (division by
zero)
{
public static void main(String args[])
{
System.out.println("CDummy.");
int i1 = 1;
int i2 = 0;
System.out.println("i1/i2 = " + (i1/i2));
}
}
What is the reason for this behavior ? Why integers throw exceptions
when dividing by zero while floats just assumes the number is Infinity
(no exception is thrown) ?
Regards,
Razvan