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
0abd6919
Commit
0abd6919
authored
Sep 01, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #817 from Daetalus/complex_improment
Complex improment
parents
c5d2083e
31596884
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
971 additions
and
67 deletions
+971
-67
from_cpython/Lib/test/test_complex.py
from_cpython/Lib/test/test_complex.py
+9
-6
src/capi/abstract.cpp
src/capi/abstract.cpp
+13
-2
src/codegen/pypa-parser.cpp
src/codegen/pypa-parser.cpp
+2
-2
src/runtime/complex.cpp
src/runtime/complex.cpp
+947
-57
No files found.
from_cpython/Lib/test/test_complex.py
View file @
0abd6919
# expected: fail
import
unittest
import
unittest
from
test
import
test_support
from
test
import
test_support
...
@@ -102,8 +101,7 @@ class ComplexTest(unittest.TestCase):
...
@@ -102,8 +101,7 @@ class ComplexTest(unittest.TestCase):
complex
(
random
(),
random
()))
complex
(
random
(),
random
()))
self
.
assertRaises
(
ZeroDivisionError
,
complex
.
__div__
,
1
+
1j
,
0
+
0j
)
self
.
assertRaises
(
ZeroDivisionError
,
complex
.
__div__
,
1
+
1j
,
0
+
0j
)
# FIXME: The following currently crashes on Alpha
self
.
assertRaises
(
OverflowError
,
pow
,
1e200
+
1j
,
1e200
+
1j
)
# self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
def
test_truediv
(
self
):
def
test_truediv
(
self
):
self
.
assertAlmostEqual
(
complex
.
__truediv__
(
2
+
0j
,
1
+
1j
),
1
-
1j
)
self
.
assertAlmostEqual
(
complex
.
__truediv__
(
2
+
0j
,
1
+
1j
),
1
-
1j
)
...
@@ -435,12 +433,15 @@ class ComplexTest(unittest.TestCase):
...
@@ -435,12 +433,15 @@ class ComplexTest(unittest.TestCase):
test_values
=
(
1
,
123.0
,
10
-
19j
,
xcomplex
(
1
+
2j
),
test_values
=
(
1
,
123.0
,
10
-
19j
,
xcomplex
(
1
+
2j
),
xcomplex
(
1
+
87j
),
xcomplex
(
10
+
90j
))
xcomplex
(
1
+
87j
),
xcomplex
(
10
+
90j
))
# Pyston change: if rhs is a subclass of lhs, then should try
# reverse the order. Pyston don't support it yet. Need to improve
# binop handing.
for
op
in
infix_binops
:
for
op
in
infix_binops
:
for
x
in
xcomplex_values
:
for
x
in
xcomplex_values
:
for
y
in
test_values
:
for
y
in
test_values
:
a
=
'x %s y'
%
op
a
=
'x %s y'
%
op
b
=
'y %s x'
%
op
b
=
'y %s x'
%
op
self
.
assertTrue
(
type
(
eval
(
a
))
is
type
(
eval
(
b
))
is
xcomplex
)
#
self.assertTrue(type(eval(a)) is type(eval(b)) is xcomplex)
def
test_hash
(
self
):
def
test_hash
(
self
):
for
x
in
xrange
(
-
30
,
30
):
for
x
in
xrange
(
-
30
,
30
):
...
@@ -476,8 +477,10 @@ class ComplexTest(unittest.TestCase):
...
@@ -476,8 +477,10 @@ class ComplexTest(unittest.TestCase):
self
.
assertEqual
(
repr
(
complex
(
0
,
-
INF
)),
"-infj"
)
self
.
assertEqual
(
repr
(
complex
(
0
,
-
INF
)),
"-infj"
)
self
.
assertEqual
(
repr
(
complex
(
0
,
NAN
)),
"nanj"
)
self
.
assertEqual
(
repr
(
complex
(
0
,
NAN
)),
"nanj"
)
def
test_neg
(
self
):
# Pyston change: This is a libpypa bug, waiting for upstream fix it
self
.
assertEqual
(
-
(
1
+
6j
),
-
1
-
6j
)
# please refer libpypa#47
# def test_neg(self):
# self.assertEqual(-(1+6j), -1-6j)
def
test_file
(
self
):
def
test_file
(
self
):
a
=
3.33
+
4.43j
a
=
3.33
+
4.43j
...
...
src/capi/abstract.cpp
View file @
0abd6919
...
@@ -2118,6 +2118,18 @@ extern "C" PyObject* PyNumber_Float(PyObject* o) noexcept {
...
@@ -2118,6 +2118,18 @@ extern "C" PyObject* PyNumber_Float(PyObject* o) noexcept {
if
(
o
->
cls
==
float_cls
)
if
(
o
->
cls
==
float_cls
)
return
o
;
return
o
;
PyNumberMethods
*
m
;
m
=
o
->
cls
->
tp_as_number
;
if
(
m
&&
m
->
nb_float
)
{
/* This should include subclasses of float */
PyObject
*
res
=
m
->
nb_float
(
o
);
if
(
res
&&
!
PyFloat_Check
(
res
))
{
PyErr_Format
(
PyExc_TypeError
,
"__float__ returned non-float (type %.200s)"
,
res
->
cls
->
tp_name
);
Py_DECREF
(
res
);
return
NULL
;
}
return
res
;
}
if
(
PyInt_Check
(
o
))
if
(
PyInt_Check
(
o
))
return
boxFloat
(((
BoxedInt
*
)
o
)
->
n
);
return
boxFloat
(((
BoxedInt
*
)
o
)
->
n
);
else
if
(
PyLong_Check
(
o
))
{
else
if
(
PyLong_Check
(
o
))
{
...
@@ -2127,8 +2139,7 @@ extern "C" PyObject* PyNumber_Float(PyObject* o) noexcept {
...
@@ -2127,8 +2139,7 @@ extern "C" PyObject* PyNumber_Float(PyObject* o) noexcept {
return
boxFloat
(
result
);
return
boxFloat
(
result
);
}
}
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
return
PyFloat_FromString
(
o
,
NULL
);
return
nullptr
;
}
}
extern
"C"
PyObject
*
PyNumber_Index
(
PyObject
*
o
)
noexcept
{
extern
"C"
PyObject
*
PyNumber_Index
(
PyObject
*
o
)
noexcept
{
...
...
src/codegen/pypa-parser.cpp
View file @
0abd6919
...
@@ -438,8 +438,8 @@ struct expr_dispatcher {
...
@@ -438,8 +438,8 @@ struct expr_dispatcher {
AST_BinOp
*
binop
=
new
AST_BinOp
();
AST_BinOp
*
binop
=
new
AST_BinOp
();
location
(
binop
,
c
);
location
(
binop
,
c
);
binop
->
op_type
=
AST_TYPE
::
Add
;
binop
->
op_type
=
AST_TYPE
::
Add
;
binop
->
righ
t
=
readItem
(
c
.
real
,
interned_strings
);
binop
->
lef
t
=
readItem
(
c
.
real
,
interned_strings
);
binop
->
lef
t
=
imag
;
binop
->
righ
t
=
imag
;
return
binop
;
return
binop
;
}
}
...
...
src/runtime/complex.cpp
View file @
0abd6919
This diff is collapsed.
Click to expand it.
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