0

I'm writing a program in Java, and I noticed that I had an expression in my code x / y > 0 that was evaluating to false when y == 0. I have since corrected this line in my code, but I'm curious, does anyone know why x / y > 0 evaluates to false rather than causing the program to terminate?

Zereges
  • 5,139
  • 1
  • 25
  • 49
Rootbeer
  • 13
  • 1
  • 3

1 Answers1

1

x / y will throw ArithmeticException if they are both integers and y is 0.

x / y equals Infinity if they are floating point numbers. And Infinity is greater than 0!

Ewan Mellor
  • 6,747
  • 1
  • 24
  • 39
  • 2
    `Infinity` is greater than `0`, but that does not explain why `Infinity > 0 == false`. I suppose that not only `x,y` were floats and `y == 0`, but also `x < 0`. – Zereges May 23 '15 at 23:08