Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 1841:23f03ef00361 legacy-trunk
Python/bltinmodule.c: mods by Andrew Kuchling to implement
pow(x,y,z) == pow(x,y)%z, but without incurring overflow
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Aug 1994 12:52:37 +0000 |
| parents | bfd11620a2d8 |
| children | 65cc727f1436 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Mon Aug 29 12:52:16 1994 +0000 +++ b/Python/bltinmodule.c Mon Aug 29 12:52:37 1994 +0000 @@ -859,19 +859,32 @@ object *self; object *args; { - object *v, *w, *x; - if (!getargs(args, "(OO)", &v, &w)) - return NULL; + object *v, *w, *z, *x; + z = None; + if (!getargs(args, "(OO)", &v, &w)) { + err_clear(); + if (!getargs(args, "(OOO)", &v, &w, &z)) { + return NULL; + } + } if (v->ob_type->tp_as_number == NULL || - w->ob_type->tp_as_number == NULL) { + (z!=None && z->ob_type->tp_as_number == NULL) || + w->ob_type->tp_as_number == NULL) { err_setstr(TypeError, "pow() requires numeric arguments"); return NULL; } if (coerce(&v, &w) != 0) return NULL; - x = (*v->ob_type->tp_as_number->nb_power)(v, w); + if (z!=None) { + if (coerce(&w, &z) != 0) + return NULL; + if (coerce(&v, &z) != 0) + return NULL; + } + x = (*v->ob_type->tp_as_number->nb_power)(v, w, z); DECREF(v); DECREF(w); + if (z!=None) {DECREF(w); DECREF(v); DECREF(z); DECREF(z);} return x; }
