The output for a Java program I wrote is giving me "Infinity" when I should be getting a number. I'm using floats, and I don't think my numbers are going out of the range of what floats can handle.
My question is would I ever get "Infinity" as the output if Java computes a value that is bigger than what the data type in use can handle? Or is "Infinity" only returned if I have accidentally divided by zero somewhere.
The JLS answers this pretty explicitly.
A floating-point operation that overflows produces a signed infinity.
You are probably dividing by zero somewhere but you could check.
double b = 1.1*Double.MAX_VALUE;
System.out.println(b);
That shows up as infinity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With