"commons-math"-like Implementation for BigDecimal / BigInteger
Asked Answered
A

0

10

I'm looking for suggestions regarding a third-party library to use for statistical analysis on numbers encoded in BigDecimal / BigInteger.

Apache commons-math contains all the ideal functionality (it's DescriptiveStatistics and SummaryStatistics)... but it's using doubles instead of the BigXXX implementations.

I am required to use the BigXXX implementations due to regulatory requirements on my software's precision. But I'm very keen not to roll-my-own implementation of the fundamental statistics that I will require.

For example, it’d be easy enough to write my own median algorithm – but it seems counterintuitive to pick-up high-precision data types, and then use my own immature (therefore, probably bug-ridden) methods to perform statistics on them.

Arzola answered 12/11, 2013 at 12:37 Comment(7)
You do realize that even if you use BigDecimal, you will need to round at some point, as BigDecimal will not help you to represent certain numbers with infinite precision? There won't be an exact duplication of the commons functionality, because you will need to deal with rounding, like it or not.Rhee
@Rhee - I'm not sure I follow, "rounding" seems to have little to do with my requirement. I require a level of precision which is well known and understood up-front. As I understand, if I overflow the precision of a BigDecimal it will not "round" the number - it will just be stored to the level of precision that is supported.Arzola
You say "level of precision which is well known and understood" and "truncation" in the same statement?Rhee
@Rhee For example, if I used a data type where I know anything beyond 10 decimal places will be truncated, I would say I understand the precision. I can store 1.0000000001 accurately, but I can't store 1.00000000001 accurately.Arzola
I've got a stupid question for you. If it is just a case of strict control of precision why no not multiply the number by your precision by your precision. Store it in a long, do your math then load you BigDecimal and divide it down keeping the precision you want? commons math tends not to use BigDecimal/BigInteger as they have performance over-heads the primitives do not.Weaks
@LukeCartner A very sensible suggestion, and something I've considered. BUT commons-math will require me to convert these to double for the Median / percentile stats :-(Arzola
Did you ever find a library for this? Thank you!Baseline

© 2022 - 2024 — McMap. All rights reserved.