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
5003059e
Commit
5003059e
authored
Aug 29, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some misc int functions
parent
3a80543e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
3 deletions
+28
-3
src/runtime/int.cpp
src/runtime/int.cpp
+13
-2
test/tests/arith.py
test/tests/arith.py
+9
-1
test/tests/random_test.py
test/tests/random_test.py
+6
-0
No files found.
src/runtime/int.cpp
View file @
5003059e
...
...
@@ -23,6 +23,7 @@
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/float.h"
#include "runtime/inline/boxing.h"
#include "runtime/long.h"
#include "runtime/objmodel.h"
...
...
@@ -143,11 +144,13 @@ extern "C" i64 mod_i64_i64(i64 lhs, i64 rhs) {
}
extern
"C"
Box
*
pow_i64_i64
(
i64
lhs
,
i64
rhs
)
{
// TODO overflow very possible
i64
orig_rhs
=
rhs
;
i64
rtn
=
1
,
curpow
=
lhs
;
RELEASE_ASSERT
(
rhs
>=
0
,
""
);
if
(
rhs
<
0
)
return
boxFloat
(
pow_float_float
(
lhs
,
rhs
));
assert
(
rhs
>
0
);
while
(
rhs
)
{
if
(
rhs
&
1
)
{
// TODO: could potentially avoid restarting the entire computation on overflow?
...
...
@@ -445,6 +448,10 @@ extern "C" Box* intGe(BoxedInt* lhs, Box* rhs) {
extern
"C"
Box
*
intLShiftInt
(
BoxedInt
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
int_cls
);
assert
(
rhs
->
cls
==
int_cls
);
if
(
rhs
->
n
<
0
)
raiseExcHelper
(
ValueError
,
"negative shift count"
);
// TODO overflow?
return
boxInt
(
lhs
->
n
<<
rhs
->
n
);
}
...
...
@@ -546,6 +553,10 @@ extern "C" Box* intPow(BoxedInt* lhs, Box* rhs) {
extern
"C"
Box
*
intRShiftInt
(
BoxedInt
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
int_cls
);
assert
(
rhs
->
cls
==
int_cls
);
if
(
rhs
->
n
<
0
)
raiseExcHelper
(
ValueError
,
"negative shift count"
);
return
boxInt
(
lhs
->
n
>>
rhs
->
n
);
}
...
...
test/tests/arith.py
View file @
5003059e
...
...
@@ -31,4 +31,12 @@ print 2.5 ** 2
print
-
1.0
**
0.3
print
-
2.5
**
2
f
(
2.0
,
1.0
)
try
:
f
(
2.0
,
1.0
)
except
TypeError
,
e
:
print
e
try
:
f
(
2
,
-
2
)
except
ValueError
,
e
:
print
e
test/tests/random_test.py
0 → 100644
View file @
5003059e
# expected: fail
# - wip
import
random
print
type
(
random
.
random
())
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