A more functionrich number (than Bigdecimal) holding java library
The operation should try and keep the answer of the same type as the original inputs, thus if the holder started of with a Double then the result should also be a double.
If inputs contain holders of different number types then it should auto widden etc.
There should be a single type of Holder with getters to return the result as an integer, double, bigdecimal, big integer etc with exceptions thrown if conversion fails.
Code should look like Bigdecimal.
Ideally immutable
Code shouldnt know or care whats inside the holder, operations just work until conversion is needed at a later stage.
Unfortunately BigDecimal is not really complete for my needs its missing many key functions eg: sine, log and most of the static helpers on Math.
ApacheCommonsMath
Axelcb made a suggestion to use the apache commons math library. The main class of use in my case seem to be DFP.
Examining DFP there is no simple way to pass a BigDecimal/BigInteger and build a DFP. It would be nice if precision would also be a parameter and used during the suck in process.
none of the functions (like multiply) accept a context w/ a precision and rounding just like BigDecimal. I really dont understand the reasoning for the clunky way precisions and rounding are handled.
What is a DfpField, what exactly does it do and why are there fields in a DFP ??? Please dont tell me this Calendar again.
there are no methods to export to a BigDecimal or BigInteger
dfp
is this the original inspiration for apache commons math DFP class ?
the first concern about import from a BigDecimal or BigInteger is lacking.
开发者_Python百科there are no methods to export to a BigDecimal or BigInteger
You might try the package gnu.math from the kawa language framework which is used to implement the full Scheme "numeric tower". The package should be pretty self-contained and independent from the rest of kawa.
BigDecimal
is not final
. You can extend it and add the methods (sine, log, etc) to the subclass.
I know these libraries which may be usable for you:
- High Performance Arbitrary Precision Arithmetic Package
- Decimal Floating Point Java class library which is now part of the Commons-Math 2.2 API
- JScience Real Implementation
I think the best way is to write wrapper for BigDecimal and implement all your additional options.
精彩评论