I am in a situation that I need to calculate something like log(1/1400). I have tried Math.log method in java but no luck. actually how can we calculate something like this in java? Math.log1p also I have tried since it give the log value of 1+x which x is the small number no luck at all. But when we use scientific calculator we can calculate log(1/1400) or ln(1/1400) easily.?
Asked
Active
Viewed 388 times
2 Answers
1
You get 0 when divide 1/1400, because java use integer division when arguments are ints.
Math.log(((double) 1)/1400);

Bogdan Lukiyanchuk
- 767
- 4
- 19
0
You can use Math.log(double d)
to compute the value for all real numbers greater than 0. Your problem is that you perform integer division when you divide an integer by an integer directly.
double val = 1/1400;
will evaluate to 0.
double val = ((double)1)/2;
will evaluate to the true value of 0.5.

Zachary
- 1,693
- 1
- 9
- 13