Proposal for modifying gnucash to use exact quantities

Bill Gribble grib@billgribble.com
25 Jul 2000 10:27:25 -0500


Steven Murdoch <sjmurdoch@linuxfan.com> writes:
> "Floor(X):  returns the largest (most positive) integral value less than
> or equal to X. When X is zero, the result has the sign of X; a zero
> result otherwise has a positive sign.
> 
> Ceil(X) returns the smallest (most negative) integral value greater than
> or equal to X. When X is zero, the result has the sign of X; a zero
> result otherwise has a negative sign when SíSigned_Zeros is True."

This is what's actually done in the code; your description is better,
thanks. 

> The solution I would suggest would be to use instead the technique
> called either "Banker's Rounding" or "Unbiased Rounding". In this way .5
> up sometimes and down sometimes. Normally we round to the nearest even
> number, so 1.5 and 2.5 round to 2, and 3.5 and 4.5 round to 4. A precise
> definition can be found in the Ada 95 RM[0]:
> "Unbiased_Round(X) yields the integral value nearest to X, rounding
> toward the even integer if X lies exactly halfway between two integers.
> A zero result has the sign of X when SíSigned_Zeros is True."

Thanks; I wasn't aware of this rounding strategy.  I'll add it to the
API right away.

> If you wish Round and Round_Half_Up to remain in the API then may I
> suggest altering the specification that in the case of a value exactly
> halfway between two integers, that Round(X) rounds towards zero rather
> than downwards.

In fact that's how it works; the proposal text is unclear.  I'll
change it.  I think the Ada rounding strategies you mention after
provide better names; I'll use them.

> For all operations I would think that Unbiased_Round should be used, so
> it would be a performance issue whether any or all of the other
> operations remain in the API. (I haven't though about this much, but I
> would tend toward leaving them in for versatility, if the cost is low)

I definitely don't think rounding should be a default.  For most
financial transactions, the math you're doing won't require any
rounding/truncation at all, and for the ones that do (total-value
computations, for example) you probably want to use RND_CEIL more
often than you want to round; if you owe the bank a tenth of a cent,
they'll bill you a whole cent, if I'm not mistaken (please let 
me know if I am!)

Thanks for the comments.

Bill Gribble