Natalie Ap

Ranch Hand

Posts: 49

posted 8 years ago

Hi,

Can someone please explain me that following results:

int i = 5;

i % 0 //ArithmeticException

i % 0.0 //NaN....why is this not Arithmetic exception?

i % -0.0 //NaN..why is this not Arithmetic exception?

i / 0 //ArithmeticException

i / 0.0 //Infinity..why is this not Arithmetic exception?

i / -0.0 //-Infinity..why is this not Arithmetic exception?

Thanks

Can someone please explain me that following results:

int i = 5;

i % 0 //ArithmeticException

i % 0.0 //NaN....why is this not Arithmetic exception?

i % -0.0 //NaN..why is this not Arithmetic exception?

i / 0 //ArithmeticException

i / 0.0 //Infinity..why is this not Arithmetic exception?

i / -0.0 //-Infinity..why is this not Arithmetic exception?

Thanks

Fiona

Uli Hofstoetter

Ranch Hand

Posts: 57

posted 8 years ago

Check out the Java Language Specification, especially

Regards,

Uli

*15.17.2 Division Operator*and*15.17.3 Remainder Operator %*.Regards,

Uli

SCEA5, Certified ScrumMaster

posted 8 years ago

Java follows the IEEE floating point standard. This is also the same standard used by practically every modern processor and programming language today.

The result is defined by IEEE. As for integers, there is no define value of NaN or Infinity for ints, so they have to throw an exception.

Henry

i % 0.0 //NaN....why is this not Arithmetic exception?

i % -0.0 //NaN..why is this not Arithmetic exception?

i / 0.0 //Infinity..why is this not Arithmetic exception?

i / -0.0 //-Infinity..why is this not Arithmetic exception?

Java follows the IEEE floating point standard. This is also the same standard used by practically every modern processor and programming language today.

The result is defined by IEEE. As for integers, there is no define value of NaN or Infinity for ints, so they have to throw an exception.

Henry

It is sorta covered in the JavaRanch Style Guide. |