Re: Native type for storing fractions (e.g 1/3)?

Поиск
Список
Период
Сортировка
От John D. Burger
Тема Re: Native type for storing fractions (e.g 1/3)?
Дата
Msg-id 581EF10B-CAB4-4D5F-BDB8-D5DDA7DA8872@mitre.org
обсуждение исходный текст
Ответ на Re: Native type for storing fractions (e.g 1/3)?  (Stephane Bortzmeyer <bortzmeyer@nic.fr>)
Ответы Re: Native type for storing fractions (e.g 1/3)?  (Ken Johanson <pg-user@kensystem.com>)
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: PgSql on Vista?
Следующее
От: George Weaver
Дата:
Сообщение: Re: Is This A Set Based Solution?