Boost logo

Boost :

From: Andras Erdei (aerdei_at_[hidden])
Date: 2005-03-06 20:39:20


i've started to work on the variants that were brought up in
a previous discussion about boost::rational<>

the current code can be found at www.ccg.hu/pub/src/rat

atm it is only for getting the calculations right, so no
templates, optimizations, boostification, nice interface etc,
and i only tested it with MSVC 7.1

there is also no implementation yet geared towards an
unlimited precision representation

the variants are:

- legacy boost (no rounding, silently gives wrong results)
- exceptions are thrown if the result overflows or cannot
  be represented
- rounding
- rounding & maintaining an exactness indicator

is there anything missing from the list?

there is also a simple test-bed, it runs the four basic
operations 10000 times on random inputs, and collects some
statistics:

addition and substraction overflowed 0 times, and the result
was exactly representable 44 times; the average error of the
legacy code is 475%, and of the rounding code is 0.005% (the
exception-throwing variant throws, so there is no error
figure for that)

multiplication and division overflowed once, and the result
was exactly representable 79 times; the average error of the
legacy code is 2025%, and of the rounding code is 0.01%

it would be nice to get some advice on how the final
interface should look like (and of course regarding
everything else, including whether there is a point to
continue the work):

- any ideas for naming the variants?

- how should the parameters of rational<> look like?

my favourite would be rational<prec,method> where prec is
the maximum absolute value allowed for numerators and
denominators, and method is one of the variants from above,
e.g. rational<10000,round> would be a rounding rational with
four decimal digits for the numerator and denominator.
of course this would cripple rational<> to be int-based,
so maybe specifying the number of bits to be used instead of
the maximum value is a sensible approach. (still don't know
though how would user-defined types be selected based on
this, so maybe the original boost approach is the only
workable one.)

br,
andras

ps: i have tried to search the archive for past discussions about rational<>
to avoid repeating old stuff, but with very limited success (only the latest
posts seem to be accessible) -- any hints?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk