Java – how do I evaluate this equation?
•
Java
I think it's very self explanatory in the code Obviously, I don't evaluate the same thing over and over again, it's just an example number to explain my problem I guess it's overflow / underflow, but I don't know how to deal with it
@H_ 301_ 8@
@H_ 301_ 8@
double d = (1 / (684985+157781)); System.out.println(d); // returns 0.0 System.out.println(Math.log(d)); // returns -Infinity.
Solution
(1 / (684985 157781)) is an integer expression, so it becomes 0
@H_ 301_ 8@
Try changing 1 to 1.0 to force the expression to be a floating point number, or 1.0d to double@ H_ 301_ 8@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码