# Proposal for modifying gnucash to use exact quantities]

Christopher Browne cbbrowne@hex.net
Fri, 28 Jul 2000 00:27:32 -0500

```On Wed, 26 Jul 2000 18:07:36 +0100, the world broke into rejoicing as
Steven Murdoch <sjmurdoch@linuxfan.com>  said:
>  Richard Wackerbarth wrote:
>  >
>  > On Tue, 25 Jul 2000, Terry wrote:
>  > > Actually - yes - the stock are purchased through dividend
> re-investment.
>  > > The dividend is computed to 1/1,000 USD (stock total is carried on
> their
>  > > books to 1/1,000 and the dividend is computed to 1/1,000 USD per
> stock
>  > > unit.) Thus the transaction value in USD is computed to 1/1,000
> USD. They
>  > > then purchase additional stock to 1/1,000 stock at the total value
> computed
>  > > in 1/1,000 USD. The whole transaction is carried out "on the
> books", no
>  > > cash changes hands, but the transaction value is computed to
> 1/1,000 and
>  > > that is the smallest unit of the transaction that is accounted for.
> Granted
>  > > if I sold the stock, I would be paid to within 1/100 USD. But the
> dividend
>  > > reinvestment is done to 1/1,000 USD.
>  > I don't think so. Rather than computing a dividend to the mill and
> shares
>  > from that, I suspect that they either compute "exact" dividend
> shares/share
>  > and round that to milli-shares and then compute the value to the
> penny or
>  > they compute the dividend to the penny and then convert that into
> fractional
>  > shares.
>  >
>  > I would be very interested in seeing a real example that contradicts
> my
>  > hypothesis.
>  I use Gnucash to track my shares, and in the UK shares are quoted in
> 1/4
>  of a pence, but in every source I have seen they are listed to 2
> decimal
>  places (in pence).
>  I happen to have a prime number of shares, so I often have fractions
>  when I am calculating the total worth of my investment. I also have a
>  share investment fund  with the same company which I represent with an
>  equity account, when I buy shares money is transfered from my dealing
>  account to the precision of 2 decimal places of a penny (i.e. GBP
>  1/10,000). For this to be represented with no chance of rounding errors
>  the quantity of shares should be an integer, price an integer number of
>  1/10,000 of GBP and value should either be calculated as an integer
>  numebr of 1/10,000 GBP.
>
>  In none of my applications I need rational numbers though, as
> everything
>  can be represented exactly in fixed decimal point notation. The only
>  case I could forsee this would be if one could buy 1/3 of something or
>  if prices were quoted as 1/3 of a dollar (or other currency unit).
>  If rational numbers are indeed not required then the implementation of
>  the library would be simplified and more importantly the integration
>  into Gnucash would be easier. This isn't a flame, I am just curious to
>  see if there are situations in finance where rational numbers are used,
>  as opposed to fixed decimal point.

Some stocks are priced in units of 1/8, 1/16, 1/32, and some bonds are
priced in units of 1/64th.

None of those divide evenly into any power of ten that we'd be likely
to use.

<Warning: I'm playing a mathematician playing with a bit of number theory
here, and am decidedly _NOT_ taking an accounting approach...>

We could probably do _pretty well_ with some fixed base if we used a base
with quite a lot of useful divisors.  For instance, 360 has, as factors:
2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45,
60, 72, 90, 120, and 180

240 has a similarly large set of factors, which allows it to be used
to express quite a lot of the useful fractions that people actually
use, with the merit that it can express 16ths evenly.

Note that 240 is less than 255, and thus:
a) Nicely fits in a byte,
b) Provides lots more range than BCD, which can only express
values up to 100 in a byte, and
c) Due to all the divisors, LOTS of simple fractions work out
evenly so you don't get the situation where 1/9, in decimal
is expressed as 0.9090909090..., or where 1/10, in binary,
is expressed as 0.000110011001100...
In base 360, 1/9 is (0, 40), and 1/10 is (0, 36)
In base 240, 1/10 is (0, 24), and 1/9 is (0, 26, 160)

Admittedly, 1/7 and 1/11 are still continuing fractions,
but any values that are representable as
v = 2^k * 3^l * 5^m
can _all be represented _exactly_, and that's pretty valuable.

This is _probably_ part of why a full rotation represents a rotation of
360 degrees, rather than 100.

And the fact that only 2 divides into 2 is why base 2 sucks quite badly
for doing fractional math.

Base 12 is probably better than base 10, which takes me back to an old
anti-Metric System joke about how if "The Good Lord meant us to use the
metric system, there would have been _10_ disciples, rather than 12."

<end of "fun with bases" screed...  I'm having entirely too much
fun with this...>

In any case, YES, there ARE things that are denominated in such fractions.
Actually most _do_ seem representable using the formula
denominator = 2^k * 3^l * 5^m
which suggests that what I wrote up above _isn't_ just "mathematical
madness," but might reflect some things we actually see...
--
cbbrowne@ntlug.org - <http://www.hex.net/~cbbrowne/linux.html>
"Microsoft   builds   product  loyalty   on   the   part  of   network
administrators and consultants, [these are] the only people who really
count  in the  Microsoft scheme  of  things. Users  are an  expendable
commodity."  -- Mitch Stone 1997

```