1

I was dividing two doubles in Kotlin and when I tried to divide by Zero, kotlin returns NaN instead of an Arithmetic Exception. Is that correct? Image dividing double returning NaN

facuhump
  • 13
  • 1
  • 3
  • Yes, that’s what it does. ArithmaticExceptions are for integer types. – Tenfour04 Oct 18 '21 at 01:39
  • It's correct. There is a convention that dividing an integer by 0 throws an error and dividing a float by 0 (or an integer by 0.0) returns NaN. – enzo Oct 18 '21 at 01:40
  • 2
    Like most languages, Kotlin uses IEEE754 specification for floating-point arithmetic https://en.wikipedia.org/wiki/Floating-point_arithmetic#NaNs, also check https://stackoverflow.com/questions/588004/is-floating-point-math-broken – IR42 Oct 18 '21 at 01:40

0 Answers0