Java BigDecimal trigonometric methods

前端 未结 5 1454
一个人的身影
一个人的身影 2020-11-27 08:42

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 fe

5条回答
  •  攒了一身酷
    2020-11-27 08:49

    Using an existing feature of Java BigDecimals, namely to allow limited precision arithmetic as described here, I recently implemented sqrt/1, exp/1, tan/1, etc.. for these number objects.

    The numeric algorithms themselve use Maclaurin and Taylor series, plus appropriate range reductions to assure enough speed and breadth of the series.

    Here is an example calculation, Ramanujan's Constant:

    Jekejeke Prolog 2, Runtime Library 1.1.8
    (c) 1985-2017, XLOG Technologies GmbH, Switzerland
    
    ?- use_module(library(stream/console)).
    % 0 consults and 0 unloads in 0 ms.
    Yes
    
    ?- X is mp(exp(pi*sqrt(163)), 60).
    X = 0d262537412640768743.999999999999250072597198185688879353856320
    

    The thingy was written in mixture of Prolog and Java. The speed and accuracy of it is still work in progress. The code is currently open source on GitHub.

提交回复
热议问题