Ali
Ali

Reputation: 1869

negative infinity when using JAVA Math library

I know that when a variable is positive zero or negative zero then the result of Math.log() would be negative infinity. Now my question is why this code returns negative infinity?!

System.out.println((0.5 / Math.log(3600)* Math.log(9 / 60)+ 0.5);

but when I using

System.out.println((0.5 / Math.log(3600)* Math.log(0.15)+ 0.5);

The answer is correct. What caused this problem and how can I fix that?!

Upvotes: 1

Views: 627

Answers (1)

Mohammed Alokshiya
Mohammed Alokshiya

Reputation: 643

Math.log(9 / 60) equals Math.log(0), which is -Infinity.

You can try Math.log(9.0/60) instead.

Upvotes: 2

Related Questions