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

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -