diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-03-14 16:50:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-03-14 16:50:37 +0000 |
commit | 286d1fc3823890be3b695dfa7a02f77b7c47a7de (patch) | |
tree | 31ac9dff7b6f9cdb55633f3827f7feffe8a8b265 /src/backend/utils/adt/numeric.c | |
parent | 2e7835f7f833657304e3df298b81a6d821edecc3 (diff) | |
download | postgresql-286d1fc3823890be3b695dfa7a02f77b7c47a7de.tar.gz postgresql-286d1fc3823890be3b695dfa7a02f77b7c47a7de.zip |
Fix numeric modulo operator for case of fractional right argument.
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r-- | src/backend/utils/adt/numeric.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index 3eb733c6d71..d18d3003a08 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -5,7 +5,7 @@ * * 1998 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.36 2000/12/07 02:47:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.37 2001/03/14 16:50:37 tgl Exp $ * * ---------- */ @@ -3355,16 +3355,19 @@ mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result) init_var(&tmp); /* ---------- - * We do it by fiddling around with global_rscale and truncating - * the result of the division. + * We do this using the equation + * mod(x,y) = x - trunc(x/y)*y + * We fiddle a bit with global_rscale to control result precision. * ---------- */ save_global_rscale = global_rscale; global_rscale = var2->rscale + 2; div_var(var1, var2, &tmp); + + /* do trunc() by forgetting digits to the right of the decimal point */ + tmp.ndigits = MAX(0, MIN(tmp.ndigits, tmp.weight + 1)); tmp.rscale = var2->rscale; - tmp.ndigits = MAX(0, MIN(tmp.ndigits, tmp.weight + tmp.rscale + 1)); global_rscale = var2->rscale; mul_var(var2, &tmp, &tmp); |