This revision made February 05, 2012 18:04, by vgrazi

Precision

• Support a very large number and a very large number of decimal places
• Candidates are
• BigDecimal
• single long
• two longs (pounds & fraction)
• new Decimal class (probably wrapping two longs)
• double should be ruled out as inaccurate
• Number should be ruled out as being abstract and non-precise

We have decided on using a Decimal class, that will encapsulate 2 longs - one long for the integer part and the other for the fractional part. Arithmetic needs to take this into account.

Issue - 1000/3 = 333.33, but 333.33*3 = 999.99 which is one penny short. Since this would not work in an accounting application, need to consider an api where the penny is accounted for, Several options - return an array where the first element is the quotient, and the second element is the excpetion: [333.33, 333.34] Or represent the result and remainder [333.33, .01] Both of these approaches would require a third long to represent the remainder or exception. In both approaches, the remainder or exception needs to be included in further calculations.

So 100/3 = [33, 34]. Now let's say we want to divide that by 4, so the 33 term produces [8,9] and the 34 term produces [8,10], so how do you capture all of those remainders?

Another issue. To show it clearly, assume 0 decimal precision, so - 34/4 = [8, 10] using exception approach, or [8, 2] using remainder approach. In either case, "multiplying" back yields the correct result: 8+8+8+10 = 34. But shouldn't that be better represented as 8+8+9+9? so how do you represent that.

Another approach - retain the fractional representation and work with the formatter to iterate through the results, adding the missing penny to the last one. Then all arithmetic would be fractional arithmetic.

Difference compared to previous revision
** two longs (pounds & fraction) ** new Decimal class (probably wrapping two longs) * double should be ruled out as inaccurate * Number should be ruled out as being abstract and non-precise We have decided on using a Decimal class, that will encapsulate 2 longs - one long for the integer part and the other for the fractional part. Arithmetic needs to take this into account. Issue - 1000/3 = 333.33, but 333.33*3 = 999.99 which is one penny short. Since this would not work in an accounting application, need to consider an api where the penny is accounted for, Several options - return an array where the first element is the quotient, and the second element is the excpetion: [333.33, 333.34] Or represent the result and remainder [333.33, .01] Both of these approaches would require a third long to represent the remainder or exception. In both approaches, the remainder or exception needs to be included in further calculations. So 100/3 = [33, 34]. Now let's say we want to divide that by 4, so the 33 term produces [8,9] and the 34 term produces [8,10], so how do you capture all of those remainders? Another issue. To show it clearly, assume 0 decimal precision, so - 34/4 = [8, 10] using exception approach, or [8, 2] using remainder approach. In either case, "multiplying" back yields the correct result: 8+8+8+10 = 34. But shouldn't that be better represented as 8+8+9+9? so how do you represent that. Another approach - retain the fractional representation and work with the formatter to iterate through the results, adding the missing penny to the last one. Then all arithmetic would be fractional arithmetic.