Why 1.0d / 0.0 give NaN but 1 / 0 give me java.lang.ArithmeticException: / by zero, why for the 1st case also I did not got ArithmeticException
            Asked
            
        
        
            Active
            
        
            Viewed 58 times
        
    1
            
            
         
    
    
        Vishrant
        
- 15,456
- 11
- 71
- 120
- 
                    1Because the rules for floating-point and integer arithmetic are different. – Oliver Charlesworth Mar 23 '14 at 12:38
- 
                    That should give you `Infinity` instead of `NaN`. – Rohit Jain Mar 23 '14 at 12:38
- 
                    @RohitJain perhaps in JavaScript, but strictly speaking it is nonsense. The result is not defined. Then, what would 0/0 should be in your opinion. – Jiri Kremser Mar 23 '14 at 12:40
- 
                    @JiriKremser `0/0` would give the same `/ by zero` exception. However, `0.0 / 0.0` will give `NaN`. – Rohit Jain Mar 23 '14 at 12:42
- 
                    @JiriKremser The result is as per IEEE 754 standard, and not per language. – Rohit Jain Mar 23 '14 at 12:46
- 
                    I see, I was speaking "math" and you were speaking "IEEE 754". I haven't noticed the tag. – Jiri Kremser Mar 24 '14 at 10:42