Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
b7beaf6f
Commit
b7beaf6f
authored
Mar 18, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add round(f, 0) support
parent
145872ea
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+20
-0
test/tests/builtins.py
test/tests/builtins.py
+2
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
b7beaf6f
...
@@ -998,6 +998,22 @@ Box* input(Box* prompt) {
...
@@ -998,6 +998,22 @@ Box* input(Box* prompt) {
Py_FatalError
(
"unimplemented"
);
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
)
{
Box
*
builtinCmp
(
Box
*
lhs
,
Box
*
rhs
)
{
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
}
}
...
@@ -1129,6 +1145,10 @@ void setupBuiltins() {
...
@@ -1129,6 +1145,10 @@ void setupBuiltins() {
{
NULL
,
NULL
});
{
NULL
,
NULL
});
builtins_module
->
giveAttr
(
"range"
,
range_obj
);
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
();
setupXrange
();
builtins_module
->
giveAttr
(
"xrange"
,
xrange_cls
);
builtins_module
->
giveAttr
(
"xrange"
,
xrange_cls
);
...
...
test/tests/builtins.py
View file @
b7beaf6f
...
@@ -103,6 +103,8 @@ print callable(lambda: 1)
...
@@ -103,6 +103,8 @@ print callable(lambda: 1)
print
range
(
5L
,
7L
)
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
))
print
list
(
iter
(
xrange
(
100
).
__iter__
().
next
,
20
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment