Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit286d1fc

Browse files
committed
Fix numeric modulo operator for case of fractional right argument.
1 parent2e7835f commit286d1fc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

‎src/backend/utils/adt/numeric.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*1998 Jan Wieck
77
*
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 $
99
*
1010
* ----------
1111
*/
@@ -3355,16 +3355,19 @@ mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
33553355
init_var(&tmp);
33563356

33573357
/* ----------
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.
33603361
* ----------
33613362
*/
33623363
save_global_rscale=global_rscale;
33633364
global_rscale=var2->rscale+2;
33643365

33653366
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));
33663370
tmp.rscale=var2->rscale;
3367-
tmp.ndigits=MAX(0,MIN(tmp.ndigits,tmp.weight+tmp.rscale+1));
33683371

33693372
global_rscale=var2->rscale;
33703373
mul_var(var2,&tmp,&tmp);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp