Commit b7beaf6f authored by Marius Wachtler's avatar Marius Wachtler

Add round(f, 0) support

parent 145872ea
......@@ -998,6 +998,22 @@ Box* input(Box* prompt) {
Py_FatalError("unimplemented");
}
Box* builtinRound(Box* _number, Box* _ndigits) {
if (!isSubclass(_number->cls, float_cls))
raiseExcHelper(TypeError, "a float is required");
BoxedFloat* number = (BoxedFloat*)_number;
if (isSubclass(_ndigits->cls, int_cls)) {
BoxedInt* ndigits = (BoxedInt*)_ndigits;
if (ndigits->n == 0)
return boxFloat(round(number->d));
}
Py_FatalError("unimplemented");
}
Box* builtinCmp(Box* lhs, Box* rhs) {
Py_FatalError("unimplemented");
}
......@@ -1129,6 +1145,10 @@ void setupBuiltins() {
{ NULL, NULL });
builtins_module->giveAttr("range", range_obj);
auto* round_obj = new BoxedBuiltinFunctionOrMethod(
boxRTFunction((void*)builtinRound, BOXED_FLOAT, 2, 1, false, false), "round", { boxInt(0) });
builtins_module->giveAttr("round", round_obj);
setupXrange();
builtins_module->giveAttr("xrange", xrange_cls);
......
......@@ -103,6 +103,8 @@ print callable(lambda: 1)
print range(5L, 7L)
print round(-1.1), round(-1.9)
print round(0.5), round(-0.5)
print list(iter(xrange(100).__iter__().next, 20))
......
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