Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
a55d387a
Commit
a55d387a
authored
Apr 15, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
e1324fc1
0d5437f8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
42 deletions
+66
-42
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+20
-18
tests/run/unsigned.pyx
tests/run/unsigned.pyx
+46
-24
No files found.
Cython/Compiler/PyrexTypes.py
View file @
a55d387a
...
...
@@ -2327,25 +2327,27 @@ def widest_numeric_type(type1, type2):
# Given two numeric types, return the narrowest type
# encompassing both of them.
if
type1
==
type2
:
return
type1
if
type1
.
is_complex
:
if
type2
.
is_complex
:
return
CComplexType
(
widest_numeric_type
(
type1
.
real_type
,
type2
.
real_type
))
else
:
return
CComplexType
(
widest_numeric_type
(
type1
.
real_type
,
type2
))
elif
type2
.
is_complex
:
return
CComplexType
(
widest_numeric_type
(
type1
,
type2
.
real_type
))
if
type1
.
is_enum
and
type2
.
is_enum
:
return
c_int_type
elif
type1
is
type2
:
return
type1
elif
(
type1
.
signed
and
type2
.
signed
)
or
(
not
type1
.
signed
and
not
type2
.
signed
):
if
type2
.
rank
>
type1
.
rank
:
return
type2
else
:
return
type1
widest_type
=
type1
elif
type1
.
is_complex
or
type2
.
is_complex
:
def
real_type
(
ntype
):
if
ntype
.
is_complex
:
return
ntype
.
real_type
return
ntype
widest_type
=
CComplexType
(
widest_numeric_type
(
real_type
(
type1
),
real_type
(
type2
)))
elif
type1
.
is_enum
and
type2
.
is_enum
:
widest_type
=
c_int_type
elif
type1
.
rank
<
type2
.
rank
:
widest_type
=
type2
elif
type1
.
rank
>
type2
.
rank
:
widest_type
=
type1
elif
type1
.
signed
<
type2
.
signed
:
widest_type
=
type1
else
:
return
sign_and_rank_to_type
[
min
(
type1
.
signed
,
type2
.
signed
),
max
(
type1
.
rank
,
type2
.
rank
)]
widest_type
=
type2
return
widest_type
def
spanning_type
(
type1
,
type2
):
# Return a type assignable from both type1 and type2.
...
...
tests/run/unsigned.pyx
View file @
a55d387a
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
u"""
>>> test_signed()
3 <class 'int'>
9 <class 'int'>
6 <class 'int'>
12 <class 'int'>
"""
else
:
__doc__
=
u"""
>>> test_signed()
3 <type 'int'>
9 <type 'long'>
6 <type 'long'>
12 <type 'long'>
"""
cdef
int
i
=
1
cdef
long
l
=
2
cdef
unsigned
int
ui
=
4
cdef
unsigned
long
ul
=
8
def
test_signed
():
print
i
+
l
,
type
(
i
+
l
)
print
i
+
ul
,
type
(
i
+
ul
)
print
ui
+
l
,
type
(
ui
+
l
)
print
ui
+
ul
,
type
(
ui
+
ul
)
def
test_add
():
"""
>>> test_add()
3
9
6
12
"""
print
i
+
l
print
i
+
ul
print
ui
+
l
print
ui
+
ul
def
test_add_sshort_ulong
(
signed
short
a
,
unsigned
long
b
):
"""
>>> test_add_sshort_ulong(1, 1) == 2
True
>>> test_add_sshort_ulong(-1, 1) == 0
True
>>> test_add_sshort_ulong(-2, 1) == -1
False
"""
return
a
+
b
def
test_add_ushort_slonglong
(
unsigned
short
a
,
signed
long
long
b
):
"""
>>> test_add_ushort_slonglong(1, 1) == 2
True
>>> test_add_ushort_slonglong(1, -1) == 0
True
>>> test_add_ushort_slonglong(1, -2) == -1
True
"""
return
a
+
b
def
test_add_slong_ulong
(
signed
long
a
,
unsigned
long
b
):
"""
>>> test_add_slong_ulong(1, 1) == 2
True
>>> test_add_slong_ulong(-1, 1) == 0
True
>>> test_add_slong_ulong(-2, 1) == -1
False
"""
return
a
+
b
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