How can I multiply by a *10^(-20). I couldn't find any logarithmic functions so I hope there will be some others
Asked
Active
Viewed 824 times
-1
-
3Java `doubles` cover the range 4.9*10^-324 to 1.7*10^308, positive or negative. Is that enough? If so, you can just use the normal `*` operator. – Douglas Sep 18 '11 at 15:33
-
2And the Math utility class has plenty of logarithmic methods, but I support Douglas' comment, which if it were an answer, I'd up-vote it. – Hovercraft Full Of Eels Sep 18 '11 at 15:34
-
2You mean multiply a by 1e-20 ? – Hari Menon Sep 18 '11 at 15:34
-
Is this what you're looking for: http://stackoverflow.com/questions/277309/java-floating-point-high-precision-library ? – Kashyap Sep 18 '11 at 15:35
3 Answers
1
You can use BigDecimal class which can store large values for your calculations.

Jim Lewis
- 43,505
- 7
- 82
- 96

Inon Stelman
- 955
- 7
- 12
-
1Why was this answer given a minus 1? Where in the OP does he mention floating point values? Has the question been modified recently? Even if he was using floating point numbers, doing calculations on very small numbers and using floating point causes a lot of problems you can avoid by using a class like BigDecimal. That's the point, to keep the accuracy and avoid the issues that arise with floating point arithmetic. – Asaf Sep 18 '11 at 18:56
-
@JimLewis - There is no prevention using BigDecimal when doing calculations with floats/doubles - on the contrary, it is much safer and reduces pitfalls of using float and double types. Take a look in [here](http://www.ibm.com/developerworks/java/library/j-jtp0114/) or [here](http://stackoverflow.com/questions/6320209/javawhy-should-we-use-bigdecimal-instead-of-double-in-the-real-world) – Inon Stelman Sep 19 '11 at 21:30
-
@inistel: I was misled by the first sentence in the link in your original answer, which states "This class represents immutable integer numbers of arbitrary length." But I see now that it is capable of representing non-integers as well. I still think it's not the solution the OP should be looking into, but I'll happily rescind the downvote. – Jim Lewis Sep 19 '11 at 22:19
0
I wouldn't use a log function, I would use Math.pow
double d = a * Math.pow(10, -20);

Peter Lawrey
- 525,659
- 79
- 751
- 1,130
-
1Java supports floating point literals, so you could write: `a * 1.0e-20` – Douglas Oct 02 '11 at 15:38