diff --git a/src/modules/Gmp/mpz_glue.c b/src/modules/Gmp/mpz_glue.c index c1f179ecc305cc2787e71ae13f8f1a29d8c140dc..5e4bbed6f65f7f83baab500dbd5a39538f24b1b0 100644 --- a/src/modules/Gmp/mpz_glue.c +++ b/src/modules/Gmp/mpz_glue.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: mpz_glue.c,v 1.15 1997/04/26 01:12:31 nisse Exp $"); +RCSID("$Id: mpz_glue.c,v 1.16 1997/04/28 23:49:11 hubbe Exp $"); #include "gmp_machine.h" #include "types.h" @@ -177,7 +177,7 @@ static struct pike_string *low_get_digits(MP_INT *mpz, int base) while(i--) { s->str[i] = mpz_get_ui(tmp) & 0xff; - mpz_tdiv_q_2exp(tmp, tmp, 8); + mpz_fdiv_q_2exp(tmp, tmp, 8); } mpz_clear(tmp); s = end_shared_string(s); @@ -406,7 +406,7 @@ static void mpzmod_div(INT32 args) res = clone_object(mpzmod_program, 0); mpz_set(OBTOMPZ(res), THIS); for(e=0;e<args;e++) - mpz_tdiv_q(OBTOMPZ(res), OBTOMPZ(res), OBTOMPZ(sp[e-args].u.object)); + mpz_fdiv_q(OBTOMPZ(res), OBTOMPZ(res), OBTOMPZ(sp[e-args].u.object)); pop_n_elems(args); push_object(res); @@ -424,7 +424,7 @@ static void mpzmod_mod(INT32 args) res = clone_object(mpzmod_program, 0); mpz_set(OBTOMPZ(res), THIS); for(e=0;e<args;e++) - mpz_tdiv_r(OBTOMPZ(res), OBTOMPZ(res), OBTOMPZ(sp[e-args].u.object)); + mpz_fdiv_r(OBTOMPZ(res), OBTOMPZ(res), OBTOMPZ(sp[e-args].u.object)); pop_n_elems(args); push_object(res); @@ -650,7 +650,7 @@ static void mpzmod_rsh(INT32 args) if (sp[-1].u.integer < 0) error("Gmp.mpz->rsh: Shift count must be positive.\n"); res = clone_object(mpzmod_program, 0); - mpz_tdiv_q_2exp(OBTOMPZ(res), THIS, sp[-1].u.integer); + mpz_fdiv_q_2exp(OBTOMPZ(res), THIS, sp[-1].u.integer); pop_n_elems(args); push_object(res); } diff --git a/src/operators.c b/src/operators.c index 7ff23d9bf8ce63beb784018e3a293e5ac4962db8..988f76051672c5e9e8a737ce96c3f8041aa8329c 100644 --- a/src/operators.c +++ b/src/operators.c @@ -5,7 +5,7 @@ \*/ #include <math.h> #include "global.h" -RCSID("$Id: operators.c,v 1.13 1997/04/16 03:09:15 hubbe Exp $"); +RCSID("$Id: operators.c,v 1.14 1997/04/28 23:48:42 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "multiset.h" @@ -991,11 +991,19 @@ void o_divide() return; case T_INT: + { + INT32 tmp; if (sp[-1].u.integer == 0) error("Division by zero\n"); sp--; - sp[-1].u.integer /= sp[0].u.integer; + + tmp=sp[-1].u.integer / sp[0].u.integer; + if(tmp<0) + if(tmp * sp[0].u.integer > sp[-1].u.integer) + tmp--; + sp[-1].u.integer=tmp; return; + } default: error("Bad argument 1 to divide.\n"); @@ -1047,7 +1055,22 @@ void o_mod() case T_INT: if (sp[-1].u.integer == 0) error("Modulo by zero.\n"); sp--; - sp[-1].u.integer %= sp[0].u.integer; + if(sp[-1].u.integer>=0) + { + if(sp[0].u.integer>=0) + { + sp[-1].u.integer %= sp[0].u.integer; + }else{ + sp[-1].u.integer=sp[0].u.integer+(sp[-1].u.integer % -sp[0].u.integer); + } + }else{ + if(sp[0].u.integer>=0) + { + sp[-1].u.integer=sp[0].u.integer-(-sp[-1].u.integer % sp[0].u.integer); + }else{ + sp[-1].u.integer=-(-sp[-1].u.integer % -sp[0].u.integer); + } + } return; default: diff --git a/src/testsuite.in b/src/testsuite.in index 769dbcb1c24ce76303f4fc85aa33972f1549accd..6ddc9a4898adceef9f05802cf44161281c548c9f 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,4 +1,4 @@ -test_true([["$Id: testsuite.in,v 1.39 1997/04/23 01:59:41 hubbe Exp $"]]) +test_true([["$Id: testsuite.in,v 1.40 1997/04/28 23:48:42 hubbe Exp $"]]) test_any([[class foo { constant x=17; }; class bar { inherit foo; constant x=18; }; return bar()->x;]],18) test_program([[inline string foo(string s){ while(s[0] == ' ' || s[0] == '\t') s = s[1..]; return(s); } string a() { return foo(" bar"); }]]) test_true([[lambda(function f) {return 1;}(object_program(this_object()));]]) @@ -587,6 +587,10 @@ test_eq(12/3,4) test_eq(13/3,4) test_eq(14/3,4) test_eq(15/3,5) +test_eq(-12/3,-4) +test_eq(-13/3,-5) +test_eq(-14/3,-5) +test_eq(-15/3,-5) test_eval_error(return 15/0) test_eq(12.0/3.0,4.0) test_eq(14.0/4.0,3.5) @@ -610,6 +614,10 @@ test_eq(12%3,0) test_eq(13%3,1) test_eq(14%3,2) test_eq(15%3,0) +test_eq(2%17,2) +test_eq(2%-17,-15) +test_eq(-2%17,15) +test_eq(-2%-17,-2) test_eval_error(return 15 % 0) test_eq(12.0 % 3.0,0.0) test_eq(13.0 % 3.0,1.0)