From a0fad9762a22e739de69c85b51ff7a47e672732f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 4 Apr 2008 18:45:36 +0000 Subject: 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. --- src/include/utils/builtins.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/include/utils/builtins.h') diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index f80802f9bff..c14fcab72e8 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.311 2008/04/04 16:57:21 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.312 2008/04/04 18:45:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -845,6 +845,7 @@ extern Datum numeric_add(PG_FUNCTION_ARGS); extern Datum numeric_sub(PG_FUNCTION_ARGS); extern Datum numeric_mul(PG_FUNCTION_ARGS); extern Datum numeric_div(PG_FUNCTION_ARGS); +extern Datum numeric_div_trunc(PG_FUNCTION_ARGS); extern Datum numeric_mod(PG_FUNCTION_ARGS); extern Datum numeric_inc(PG_FUNCTION_ARGS); extern Datum numeric_smaller(PG_FUNCTION_ARGS); -- cgit v1.2.3