Zero division java integer vs double -


this question has answer here:

    double doubleresult = 1d/0d;     system.out.println(doubleresult);      int intresult = 1/0;     system.out.println(intresult); 

the output is:

infinity exception in thread "main" java.lang.arithmeticexception: / 0 

why double 0 division returns infinity , int 0 division throws exception?

this principally due fact double type (which in java ieee754 64 bit double precision type) has representation infinity, whereas int type not.

note double doubleresult = 1 / 0; still cause exception thrown: type of variable result assigned not relevant.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -