Commit d455a565 authored by Leandro Lameiro's avatar Leandro Lameiro

Adds a non-optimal implementation of int.__divmod__

parent b0d50771
......@@ -297,6 +297,25 @@ extern "C" Box* intMod(BoxedInt* lhs, Box* rhs) {
return boxInt(mod_i64_i64(lhs->n, rhs_int->n));
}
extern "C" Box* intDivmod(BoxedInt* lhs, Box* rhs) {
assert(lhs->cls == int_cls);
Box* divResult = intDiv(lhs, rhs);
if (divResult == NotImplemented) {
return NotImplemented;
}
Box* modResult = intMod(lhs, rhs);
if (modResult == NotImplemented) {
return NotImplemented;
}
Box* arg[2] = { divResult, modResult };
return createTuple(2, arg);
}
extern "C" Box* intMulInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(lhs->cls == int_cls);
assert(rhs->cls == int_cls);
......@@ -519,6 +538,7 @@ void setupInt() {
int_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)intRepr, STR, 1, false)));
int_cls->setattr("__str__", int_cls->peekattr("__repr__"), NULL, NULL);
int_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)intHash, BOXED_INT, 1, false)));
int_cls->giveAttr("__divmod__", new BoxedFunction(boxRTFunction((void*)intDivmod, BOXED_TUPLE, 2, false)));
CLFunction* __new__ = boxRTFunction((void*)intNew1, NULL, 1, false);
addRTFunction(__new__, (void*)intNew2, NULL, 2, false);
......
# can't try large numbers yet due to lack of long
for i in xrange(1, 100):
for j in xrange(1, 100):
print i.__divmod__(j)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment