Re-implement division for numeric values using the traditional "schoolbook"
Tom Lane <tgl@sss.pgh.pa.us>
Re-implement division for numeric values using the traditional "schoolbook" algorithm. This is a good deal slower than our old roundoff-error-prone code for long inputs, so we keep the old code for use in the transcendental functions, where everything is approximate anyway. Also create a user-accessible function div(numeric, numeric) to provide access to the exact result of trunc(x/y) --- since the regular numeric / operator will round off its result, simply computing that expression in SQL doesn't reliably give the desired answer. This fixes bug #3387 and various related corner cases, and improves the usefulness of PG for high-precision integer arithmetic.
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/func.sgml | modified | +13 −1 |
| src/backend/utils/adt/numeric.c | modified | +348 −26 |
| src/include/catalog/catversion.h | modified | +2 −2 |
| src/include/catalog/pg_proc.h | modified | +6 −2 |
| src/include/utils/builtins.h | modified | +2 −1 |
| src/test/regress/expected/numeric.out | modified | +81 −0 |
| src/test/regress/sql/numeric.sql | modified | +18 −0 |