-1

How can I multiply by a *10^(-20). I couldn't find any logarithmic functions so I hope there will be some others

Laurynas G
  • 573
  • 9
  • 30

3 Answers3

3

Java doubles cover the range 4.9*10^-324 to 1.7*10^308, positive or negative. If your numbers fit within that range, and you are happy to use floating point precision, you can use the normal * operator.

The documentation for the Math.log method is here.

Douglas
  • 36,802
  • 9
  • 76
  • 89
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
  • 1
    Why 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