Java BigDecimal trigonometric methods

Marco picture Marco · Jan 31, 2010 · Viewed 11.1k times · Source

I am developing a mathematical parser which is able to evaluate String like '5+b*sqrt(c^2)'. I am using ANTLR for the parsing and make good progress. Now I fell over the Java class BigDecimal and thought: hey, why not thinking about precision here.

My problem is that the Java API does not provide trigonometric methods for BigDecimals like java.lang.Math. Do you know if there are any good math libraries like Apache Commons out there that deal with this problem?

The other questions is how to realize the power method so that I can calculate 4.9 ^ 1.4 with BigDecimals. Is this possible?

A book request about numerical computing is also appreciated.

Answer

Scott Fines picture Scott Fines · Jan 31, 2010

ApFloat is a library which contains arbitrary-precision approximations of trigometric functions and non-integer powers both; however, it uses its own internal representations, rather than BigDecimal and BigInteger. I haven't used it before, so I can't vouch for its correctness or performance characteristics, but the api seems fairly complete.