|
5 | 5 | *
|
6 | 6 | *1998 Jan Wieck
|
7 | 7 | *
|
8 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.36 2000/12/07 02:47:35 tgl Exp $ |
| 8 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.37 2001/03/14 16:50:37 tgl Exp $ |
9 | 9 | *
|
10 | 10 | * ----------
|
11 | 11 | */
|
@@ -3355,16 +3355,19 @@ mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
|
3355 | 3355 | init_var(&tmp);
|
3356 | 3356 |
|
3357 | 3357 | /* ----------
|
3358 |
| - * We do it by fiddling around with global_rscale and truncating |
3359 |
| - * the result of the division. |
| 3358 | + * We do this using the equation |
| 3359 | + *mod(x,y) = x - trunc(x/y)*y |
| 3360 | + * We fiddle a bit with global_rscale to control result precision. |
3360 | 3361 | * ----------
|
3361 | 3362 | */
|
3362 | 3363 | save_global_rscale=global_rscale;
|
3363 | 3364 | global_rscale=var2->rscale+2;
|
3364 | 3365 |
|
3365 | 3366 | div_var(var1,var2,&tmp);
|
| 3367 | + |
| 3368 | +/* do trunc() by forgetting digits to the right of the decimal point */ |
| 3369 | +tmp.ndigits=MAX(0,MIN(tmp.ndigits,tmp.weight+1)); |
3366 | 3370 | tmp.rscale=var2->rscale;
|
3367 |
| -tmp.ndigits=MAX(0,MIN(tmp.ndigits,tmp.weight+tmp.rscale+1)); |
3368 | 3371 |
|
3369 | 3372 | global_rscale=var2->rscale;
|
3370 | 3373 | mul_var(var2,&tmp,&tmp);
|
|