Re: Arbitrary precision modulo operation

Поиск
Список
Период
Сортировка
От Dann Corbit
Тема Re: Arbitrary precision modulo operation
Дата
Msg-id D90A5A6C612A39408103E6ECDD77B829408D6E@voyager.corporate.connx.com
обсуждение исходный текст
Ответ на Arbitrary precision modulo operation  (Chadwick Boggs <chadwickboggs@yahoo.com>)
Список pgsql-general
I do not know how division is performed in numeric quantities for
PostgreSQL.

However, if the algorithm is being revised, here is a possible outline:

1.  Convert to double and perform the division to get an estimate
2.  Use Newton's method for division, starting at 30 digits and doubling
the digits for each iteration.
3.  Stop when you have reached 50% excess digits or so
4.  Round to the correct value.

Since the computations use smaller significant digits until the last
iteration, there is typically a large savings compared to performing all
calculations in full precision.

So, if the target is 70 digits you will have:

~15 digits precision after the double precision floating point divide
30 digits after one iteration
60 digits after two iterations
120 digits after three iterations

Then round to the correct length.

See:
http://www.azillionmonkeys.com/qed/adiv.html

For a short discussion of Newton's method for division.

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

Предыдущее
От: "Dann Corbit"
Дата:
Сообщение: Re: Arbitrary precision modulo operation
Следующее
От: "Dann Corbit"
Дата:
Сообщение: Re: Arbitrary precision modulo operation