diff --git a/src/modules/Gmp/mpf.cmod b/src/modules/Gmp/mpf.cmod index 47344b26186acfcb06a579cbab730c2811725a4c..c515834b9092a670d3de56779b85eec9d00fdb48 100644 --- a/src/modules/Gmp/mpf.cmod +++ b/src/modules/Gmp/mpf.cmod @@ -111,79 +111,66 @@ PIKECLASS mpf { CVAR MP_FLT n; - static void get_mpf_from_digits(MP_FLT *UNUSED(tmp), - struct pike_string *digits, - int base) - { - p_wchar0 *str; - - if(digits->size_shift) - Pike_error("Illegal characters, cannot convert to Gmp.mpf.\n"); - str=STR0(digits); - - mpf_set_str(THISMPF, (char *)str, base); - } - static void get_new_mpf(MP_FLT *tmp, struct svalue *s) + { + switch(TYPEOF(*s)) { - switch(TYPEOF(*s)) - { - case T_FLOAT: + case T_FLOAT: { mpf_set_d(tmp, (double) s->u.float_number); break; } - - case T_INT: - mpf_set_si(tmp, (signed long int) s->u.integer); - break; - - case T_OBJECT: - if((s->u.object->prog == mpzmod_program) || - (s->u.object->prog == bignum_program)) - { - mpf_set_z(tmp, OBTOMPZ(s->u.object)); - break; - } - if(s->u.object->prog == mpq_program) - { - mpf_set_q(tmp, OBTOMPQ(s->u.object)); - break; - } - - if(s->u.object->prog == mpf_program) - { - mpf_set(tmp, OBTOMPF(s->u.object)); - break; - } - - if (s->u.object->prog) { - Pike_error("Wrong type of object (id:%d), cannot convert to Gmp.mpf.\n", - s->u.object->prog->id); - } else { - /* Destructed object. Use as zero. */ - mpf_set_si(tmp, 0); - } - break; - - default: - Pike_error("Cannot convert argument to Gmp.mpf.\n"); - } + case T_INT: + mpf_set_si(tmp, (signed long int) s->u.integer); + break; + + case T_OBJECT: + if((s->u.object->prog == mpzmod_program) || + (s->u.object->prog == bignum_program)) + { + mpf_set_z(tmp, OBTOMPZ(s->u.object)); + break; + } + + if(s->u.object->prog == mpq_program) + { + mpf_set_q(tmp, OBTOMPQ(s->u.object)); + break; + } + + if(s->u.object->prog == mpf_program) + { + mpf_set(tmp, OBTOMPF(s->u.object)); + break; + } + + if (s->u.object->prog) { + Pike_error("Wrong type of object (id:%d), cannot convert to Gmp.mpf.\n", + s->u.object->prog->id); + } else { + /* Destructed object. Use as zero. */ + mpf_set_si(tmp, 0); + } + break; + + default: + Pike_error("Cannot convert argument to Gmp.mpf.\n"); } - + } + /* FIXME: */ /*! @decl static void create(void|int|string|float|object x, @ *! void|int(0..) precision) *! @decl static void create(string x, int(0..) precision, int(2..36) base) */ - PIKEFUN void create(void|string|int|float|object x, void|int precision, - void|int base) + PIKEFUN void create(void|string|int|float|object x, void|int UNUSED, + void|int UNUSED) type function(void|string|int|float|object,void|int(1..):void)|function(string,int(0..),int(2..36):void); flags ID_PROTECTED; { int base=0; - + switch(args) { case 3: @@ -310,28 +297,9 @@ PIKECLASS mpf RETURN end_and_resize_shared_string(ret, out - outbase); } - static int lookup(char *name, - struct mapping *m, - char *ind, - int def) - { - struct svalue *sv; - if((sv=simple_mapping_string_lookup(m,ind))) - { - if(TYPEOF(*sv) == T_INT) - { - return sv->u.integer; - }else{ - Pike_error("\"%s\" argument to %s is not an integer.\n",ind,name); - - } - } - return def; - } - /*! @decl static string _sprintf(int c, mapping flags) */ - PIKEFUN string _sprintf(int c, mapping flags) + PIKEFUN string _sprintf(int c, mapping UNUSED) flags ID_PROTECTED; { /* We should use this code for good... @@ -373,7 +341,7 @@ PIKECLASS mpf *! @fixme *! Perhaps it should also return true for @expr{"object"@}? */ - PIKEFUN int(0..1) _is_type(string arg) + PIKEFUN int(0..1) _is_type(string UNUSED) flags ID_PROTECTED; { push_constant_text("float"); @@ -551,7 +519,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf `+(int|float|object ... a) */ - PIKEFUN object `+(int|float|object ... a) + PIKEFUN object `+(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res; @@ -565,7 +533,7 @@ PIKECLASS mpf /* @decl static Gmp.mpf ``+(int|float|object ... a) */ - PIKEFUN object ``+(int|float|object ... a) + PIKEFUN object ``+(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res = NULL; @@ -581,7 +549,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf `+=(int|float|object ... a) */ - PIKEFUN object `+=(int|float|object ... a) + PIKEFUN object `+=(int|float|object ... UNUSED) flags ID_PROTECTED; { unsigned long int prec; @@ -632,7 +600,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf `*(int|float|object ... a) */ - PIKEFUN object `*(int|float|object ... a) + PIKEFUN object `*(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res; @@ -645,7 +613,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf ``*(int|float|object ... a) */ - PIKEFUN object ``*(int|float|object ... a) + PIKEFUN object ``*(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res; @@ -659,7 +627,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf `*=(int|float|object ... a) */ - PIKEFUN object `*=(int|float|object ... a) + PIKEFUN object `*=(int|float|object ... UNUSED) flags ID_PROTECTED; { unsigned long int prec; @@ -687,7 +655,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf `-(int|float|object ... a) */ - PIKEFUN object `-(int|float|object ... a) + PIKEFUN object `-(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res; @@ -720,7 +688,7 @@ PIKECLASS mpf /*! @decl static Gmp.mpf `/(int|float|object ... a) */ - PIKEFUN object `/(int|float|object ... a) + PIKEFUN object `/(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; diff --git a/src/modules/Gmp/mpq.cmod b/src/modules/Gmp/mpq.cmod index 943ce0c623facb75c6fda336208a22bab3d59bdf..d64d3a2a6afe047d3b39785f39fb68a222afe159 100644 --- a/src/modules/Gmp/mpq.cmod +++ b/src/modules/Gmp/mpq.cmod @@ -282,42 +282,42 @@ PIKECLASS mpq switch(args) { case 1: - if(TYPEOF(sp[-args]) == T_STRING) - get_mpq_from_digits(THISMPQ, sp[-args].u.string, 0); + if(TYPEOF(*x) == T_STRING) + get_mpq_from_digits(THISMPQ, x->u.string, 0); else - get_new_mpq(THISMPQ, sp-args, 1, "Gmp.mpq", 1, args); + get_new_mpq(THISMPQ, x, 1, "Gmp.mpq", 1, args); break; - + case 2: /* Args are string of digits and integer base */ /* or int num / den */ - - if (TYPEOF(sp[1-args]) != T_INT) - if(TYPEOF(sp[1-args]) != T_OBJECT || - sp[1-args].u.object->prog != bignum_program || - TYPEOF(sp[-args]) == T_STRING) + + if (TYPEOF(*base) != T_INT) + if(TYPEOF(*base) != T_OBJECT || + base->u.object->prog != bignum_program || + TYPEOF(*x) == T_STRING) SIMPLE_ARG_TYPE_ERROR ("Gmp.mpq", 2, "int"); - switch(TYPEOF(sp[-args])) + switch(TYPEOF(*x)) { case T_STRING: - get_mpq_from_digits(THISMPQ, sp[-args].u.string, sp[1-args].u.integer); + get_mpq_from_digits(THISMPQ, x->u.string, base->u.integer); break; case T_OBJECT: - if(sp[-args].u.object->prog != bignum_program) + if(x->u.object->prog != bignum_program) default: SIMPLE_ARG_TYPE_ERROR ("Gmp.mpq", 1, "int|string"); case T_INT: - mpq_set_num(THISMPQ,get_mpz(sp-args, 1, "Gmp.mpq", 1, args)); - mpq_set_den(THISMPQ,get_mpz(sp-args+1, 1, "Gmp.mpq", 2, args)); + mpq_set_num(THISMPQ,get_mpz(x, 1, "Gmp.mpq", 1, args)); + mpq_set_den(THISMPQ,get_mpz(base, 1, "Gmp.mpq", 2, args)); mpq_canonicalize(THISMPQ); break; } break; - + default: SIMPLE_WRONG_NUM_ARGS_ERROR ("Gmp.mpq", 2); @@ -325,7 +325,7 @@ PIKECLASS mpq break; /* Needed by AIX cc */ } } - + /*! @decl int get_int() */ PIKEFUN int get_int() @@ -566,16 +566,12 @@ PIKECLASS mpq PIKEFUN string _sprintf(int c, mapping flags) flags ID_PROTECTED; { - INT_TYPE precision, width, base = 0, mask_shift = 0; - struct pike_string *s = 0; - INT_TYPE flag_left; + INT_TYPE precision; precision=lookup("Gmp.Mpq->_sprintf",flags,"precision",7, 2, args); - width=lookup("Gmp.Mpq->_sprintf",flags,"width",-1, 2, args); - flag_left=lookup("Gmp.Mpq->_sprintf",flags,"flag_left",0, 2, args); pop_n_elems(args); if(precision<0) precision=0; - + switch(c) { default: @@ -596,7 +592,6 @@ PIKECLASS mpq case 'f': { mpz_t tmp; - ptrdiff_t len; mpz_init(tmp); mpz_ui_pow_ui(tmp, 10, precision); @@ -617,7 +612,7 @@ PIKECLASS mpq /*! @decl static int(0..1) _is_type(string arg) */ - PIKEFUN int(0..1) _is_type(string arg) + PIKEFUN int(0..1) _is_type(string UNUSED) flags ID_PROTECTED; { push_constant_text("float"); @@ -691,7 +686,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `+(int|float|object ... a) */ - PIKEFUN object `+(int|float|object ... a) + PIKEFUN object `+(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; @@ -702,13 +697,13 @@ PIKECLASS mpq mpq_set(OBTOMPQ(res), THISMPQ); for(e=0;e<args;e++) mpq_add(OBTOMPQ(res), OBTOMPQ(res), OBTOMPQ(sp[e-args].u.object)); - + RETURN res; } /*! @decl static Gmp.mpq ``+(int|float|object ... a) */ - PIKEFUN object ``+(int|float|object ... a) + PIKEFUN object ``+(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; @@ -725,7 +720,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `+=(int|float|object ... a) */ - PIKEFUN object `+=(int|float|object ... a) + PIKEFUN object `+=(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; @@ -793,7 +788,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `*(int|float|object ... a) */ - PIKEFUN object `*(int|float|object ... a) + PIKEFUN object `*(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res; @@ -808,7 +803,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq ``*(int|float|object ... a) */ - PIKEFUN object ``*(int|float|object ... a) + PIKEFUN object ``*(int|float|object ... UNUSED) flags ID_PROTECTED; { struct object *res; @@ -823,7 +818,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `*=(int|float|object ... a) */ - PIKEFUN object `*=(int|float|object ... a) + PIKEFUN object `*=(int|float|object ... UNUSED) flags ID_PROTECTED; { mult_convert_args(args, "Gmp.mpq->`*="); @@ -833,7 +828,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `-(int|float|object ... a) */ - PIKEFUN object `-(int|float|object ... a) + PIKEFUN object `-(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; @@ -871,7 +866,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `/(int|float|object ... a) */ - PIKEFUN object `/(int|float|object ... a) + PIKEFUN object `/(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; @@ -910,7 +905,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq `%(int|float|object ... a) *! @expr{a%b = a - floor(a/b)*b @} */ - PIKEFUN object `%(int|float|object ... a) + PIKEFUN object `%(int|float|object ... UNUSED) flags ID_PROTECTED; { INT32 e; @@ -952,7 +947,7 @@ PIKECLASS mpq /*! @decl static Gmp.mpq ``%(int|float|object a) */ - PIKEFUN object ``%(int|float|object a) + PIKEFUN object ``%(int|float|object UNUSED) flags ID_PROTECTED; { MP_RAT *a;