diff options
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 35c8998..fb3d1fe 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -82,6 +82,7 @@ static int call_trace PROTO((object **, object **, frameobject *, char *, object *)); static object *add PROTO((object *, object *)); static object *sub PROTO((object *, object *)); +static object *pow PROTO((object *, object *)); static object *mul PROTO((object *, object *)); static object *divide PROTO((object *, object *)); static object *mod PROTO((object *, object *)); @@ -675,6 +676,15 @@ eval_code2(co, globals, locals, PUSH(x); break; + case BINARY_POWER: + w = POP(); + v = POP(); + x = pow(v, w); + DECREF(v); + DECREF(w); + PUSH(x); + break; + case BINARY_MULTIPLY: w = POP(); v = POP(); @@ -2205,6 +2215,34 @@ mod(v, w) } static object * +pow(v, w) + object *v, *w; +{ + object *res; + BINOP("__pow__", "__rpow__", pow); + if (v->ob_type->tp_as_number == NULL || + w->ob_type->tp_as_number == NULL) { + err_setstr(TypeError, "pow() requires numeric arguments"); + return NULL; + } + if ( +#ifndef WITHOUT_COMPLEX + !is_complexobject(v) && +#endif + is_floatobject(w) && getfloatvalue(v) < 0.0) { + if (!err_occurred()) + err_setstr(ValueError, "negative number to float power"); + return NULL; + } + if (coerce(&v, &w) != 0) + return NULL; + res = (*v->ob_type->tp_as_number->nb_power)(v, w, None); + DECREF(v); + DECREF(w); + return res; +} + +static object * neg(v) object *v; { |