0

Why have Apache commons-math3 based it's Fraction on int type???

Are there any reasons to use int instead of long? Do we have some performance gains here? Aren't longs process at the same speed as ints on modern CPUs?

I think we got only unneeded limitations from this decision.

Please correct me if I am mistaking.

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • 2
    I would say a usable `Fraction` class should use `BigInteger`s. Even with `long`, you get overflow for fairly trivial computations. – Daniel Fischer Mar 14 '13 at 19:22

1 Answers1

4

If you want arbitrary precision, use BigFraction. Many platforms -- especially e.g. Android -- have tight memory constraints and may not be as efficient for 64-bit computations. Additionally, any performance improvements to long may not have been available when Fraction was originally written, and for API compatibility, it may not be changeable.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
  • 1
    They made new package `math3` to break compatibility. Actually they have a number of incompatibilities with previous version. They could change `Fraction` to `long` also. Also I don't believe mobile devices were taken into account here... – Suzan Cioc Mar 14 '13 at 22:25