Stephane Bortzmeyer wrote:
> But he can write one in PostgreSQL quite easily. Rational numbers are
> always the first exercice in CS courses about Abstract Data Types :-)
It's a little tricky to get good performance for all the operations:
> The addition and subtraction operations are complex. They will
> require approximately two gcd operations, 3 divisions, 3
> multiplications and an addition on the underlying integer type.
> The multiplication and division operations require two gcd
> operations, two multiplications, and four divisions. The
> comparison operations require two gcd operations, two
> multiplications, four divisions and a comparison in the worst
> case. On the assumption that IntType comparisons are the cheapest
> of these operations (and that comparisons agains zero may be
> cheaper still), these operations have a number of special case
> optimisations to reduce the overhead where possible. In
> particular, equality and inequality tests are only as expensive as
> two of the equivalent tests on the underlying integer type.
(From the Booost rational package - http://www.boost.org/libs/
rational/rational.html)
I'd try to link to an existing library that provides rationals, or
model my code closely after one.
- John D. Burger
MITRE