the neverending rational vs. integer (they're really the same) saga

Richard Wackerbarth rkw@dataplex.net
Tue, 1 Aug 2000 23:25:02 -0500


On Tue, 01 Aug 2000, Jason Rennie wrote:

> sjmurdoch@linuxfan.com said:
> > Most book keeping is done within a currency and this will be
> > dramatically faster.
>
> Nope.  Using the integer representation, you'll need one `if' statement
> to determine that you're dealing with two numbers of the same currency.
>  Bill can do the same to determine that he's dealing with two rationals
> with the same denominators.  With denominators being equal, Bill can
> ignore the denominator for the add/subtract and simply slap on the
> denominator when returning the final value.

You will probably not need any 'if' statements because you KNOW that the 
numbers came from the same source and must, therefore, be in the same 
currency.

> sjmurdoch@linuxfan.com said:
> > Also the storage required is about half the size, so decreasing memory
> > usage, disk space and more importantly disk transfer time
>
> You would get a win here---one denominator/SCU per account instead of
> one per number.

Yep. that is what I have been saying for months now.

> So, I think Bill's API is a great foundation.  One change that I think
> would make many happier would be to have the denominator of each number
> be represented by a (pointer to a) gnc_commodity.  This would make it
> easier to ensure one denominator per account without fully exposing the
> underlying rational representation.

That is certainly a first step.

The other thing that I would do is eliminate all of the variants which Bill 
has folded into one function call and selects by a calling parameter.

In their place, I would have an individual function for each of the variants.

This makes the calling sequence more efficient and easier to maintain.

As for the "quality" of the foundation, I think it is a poor one because it 
requires a conversion to a more complex notation and back again to accomplish 
a simple operation.