diff options
author | Guido van Rossum <guido@python.org> | 1994-08-29 12:52:37 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-08-29 12:52:37 (GMT) |
commit | df05ac6dfb9f7210cf332ec288493c27d72ba0e7 (patch) | |
tree | 64b65d15e611d74d9d3e8d6b1f41c4cc9e2e57a4 /Python | |
parent | 2d9518585cf9411bf311bcb9d4e578d255e98c9b (diff) | |
download | cpython-df05ac6dfb9f7210cf332ec288493c27d72ba0e7.zip cpython-df05ac6dfb9f7210cf332ec288493c27d72ba0e7.tar.gz cpython-df05ac6dfb9f7210cf332ec288493c27d72ba0e7.tar.bz2 |
Python/bltinmodule.c: mods by Andrew Kuchling to implement
pow(x,y,z) == pow(x,y)%z, but without incurring overflow
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index d8e0d26..7e872ad 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -859,19 +859,32 @@ builtin_pow(self, args) 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; } |