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.

jwa
  • 3,239
  • 2
  • 23
  • 54
  • 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. – Durandal Nov 12 '13 at 18:28
  • @Durandal - 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. – jwa Nov 13 '13 at 07:39
  • You say "level of precision which is well known and understood" and "truncation" in the same statement? – Durandal Nov 13 '13 at 13:57
  • @Durandal 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. – jwa Nov 13 '13 at 14:50
  • 1
    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. – Luke Cartner Nov 19 '13 at 23:19
  • 1
    @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 :-( – jwa Nov 20 '13 at 09:42
  • Did you ever find a library for this? Thank you! – Jonathan S. Fisher Mar 15 '23 at 02:34

0 Answers0