I would like to announce the release of BigFixedArithmetic Version 1.0 - It is s an arbitrary-precision Java fixed-point library that prevents integer overflow and floating-point rounding errors by executing math solely via bit shifts, addition, and subtraction using BigInteger. It offers deterministic arithmetic for financial systems and simulations where CPU floating-point drift must be avoided.
It is not a replacement for BigDecimal. It is a better fit for certain kinds of scientific, engineering and financial applications than that class.
For example, BigDecimal is enough for most money handling: prices, invoices, interest at a fixed scale, tax with a defined rounding rule. BigFixedArithmetic is a better fit when:
- Division must be exact. BigDecimal.divide throws for 1/3 unless you pick a rounding. Here 1/3 is kept as the fraction 1/3 and prints as 0.(3), so splitting a payment three ways and recombining gives exactly the original amount, with no cent lost.
- Rates and ratios must stay exact through a chain of calculations. Currency conversion, pro-rata allocation, day-count fractions (such as 31/365) and compound factors can be carried as Rational values and rounded once, at the end, with the rounding mode you choose.
- You need an audit trail. Exact fractions and exact decimal output let you show that a result is not an accumulation of rounding errors, and Context lets you state the rounding point explicitly.
-You must reconcile in several bases or formats, or need the repeating pattern of a quotient (periodLength(), toRepeatingString()).
Keep using BigDecimal for storage and interchange (database columns, APIs, reports), and convert at the edges: Rational.parse(bigDecimal.toPlainString()) in, toDecimalString(places, mode) out.
GitHub: https://github.com/RDMachinery/BigFixedArithmetic
GitHubGitHub - RDMachinery/BigFixedArithmetic: BigFixedArithmetic is an arbitrary-precision Java fixed-point library that prevents integer overflow and floating-point rounding errors by executing math solely via bit shifts, addition, and subtraction using BigInteger. It offers deterministic arithmetic fo…BigFixedArithmetic is an arbitrary-precision Java fixed-point library that prevents integer overflow and floating-point rounding errors by executing math solely via bit shifts, addition, and subtra...
commit 3f470e1