+ 1

Why java math Is not mathing?

If I divide a number in java by zero, it outputs an error. Makes sense! Example (5/0) But if I divide an double by zero, it output "infinite". Why? Example (5.0/0) https://sololearn.com/compiler-playground/cZUb9M516Rke/?ref=app

5th Oct 2025, 8:00 AM
Pou10mine
Pou10mine - avatar
1 ответ
+ 3
Java handles integer and floating point division by zero differently: Integer division by zero (5/0) throws ArithmeticException because integers have no way to represent infinity Floating point division by zero (5.0/0) returns Infinity because the IEEE 754 floating point standard (which Java follows) has special values to represent positive/negative infinity This happens because 5.0 is a double, and floating point types have built in representations for infinity, while integers do not.
5th Oct 2025, 8:02 AM
Ferdous 👾
Ferdous 👾 - avatar