mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
changes for complex and power (**) operator
This commit is contained in:
parent
8a5c5d277e
commit
50564e8dae
2 changed files with 136 additions and 30 deletions
|
@ -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();
|
||||
|
@ -2204,6 +2214,34 @@ mod(v, w)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue