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
Gwenaël Samain
cython
Commits
76f1228e
Commit
76f1228e
authored
Apr 02, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for arithmetic promotion.
parent
62068b7b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
0 deletions
+89
-0
tests/run/arithmetic_analyse_types.pyx
tests/run/arithmetic_analyse_types.pyx
+62
-0
tests/run/arithmetic_analyse_types_helper.h
tests/run/arithmetic_analyse_types_helper.h
+27
-0
No files found.
tests/run/arithmetic_analyse_types.pyx
0 → 100644
View file @
76f1228e
# ticket: 676
# tag: cpp
from
cython
cimport
typeof
cdef
extern
from
"arithmetic_analyse_types_helper.h"
:
cdef
struct
short_return
:
char
*
msg
cdef
struct
int_return
:
char
*
msg
cdef
struct
longlong_return
:
char
*
msg
cdef
short_return
f
(
short
)
cdef
int_return
f
(
int
)
cdef
longlong_return
f
(
long
long
)
def
short_binop
(
short
val
):
"""
Arithmetic in C is always done with at least int precision.
>>> short_binop(3)
'int called'
"""
assert
typeof
(
val
+
val
)
==
"int"
,
typeof
(
val
+
val
)
assert
typeof
(
val
-
val
)
==
"int"
,
typeof
(
val
-
val
)
assert
typeof
(
val
&
val
)
==
"int"
,
typeof
(
val
&
val
)
cdef
int_return
x
=
f
(
val
+
val
)
return
x
.
msg
def
short_unnop
(
short
val
):
"""
Arithmetic in C is always done with at least int precision.
>>> short_unnop(3)
'int called'
"""
cdef
int_return
x
=
f
(
-
val
)
return
x
.
msg
def
longlong_binop
(
long
long
val
):
"""
>>> longlong_binop(3)
'long long called'
"""
cdef
longlong_return
x
=
f
(
val
*
val
)
return
x
.
msg
def
longlong_unnop
(
long
long
val
):
"""
>>> longlong_unnop(3)
'long long called'
"""
cdef
longlong_return
x
=
f
(
~
val
)
return
x
.
msg
def
test_bint
(
bint
a
):
"""
>>> test_bint(True)
"""
assert
typeof
(
a
+
a
)
==
"int"
,
typeof
(
a
+
a
)
assert
typeof
(
a
&
a
)
==
"bint"
,
typeof
(
a
&
a
)
tests/run/arithmetic_analyse_types_helper.h
0 → 100644
View file @
76f1228e
/* A set of mutually incompatable return types. */
struct
short_return
{
const
char
*
msg
;
};
struct
int_return
{
const
char
*
msg
;
};
struct
longlong_return
{
const
char
*
msg
;
};
/* A set of overloaded methods. */
short_return
f
(
short
arg
)
{
short_return
val
;
val
.
msg
=
"short called"
;
return
val
;
}
int_return
f
(
int
arg
)
{
int_return
val
;
val
.
msg
=
"int called"
;
return
val
;
}
longlong_return
f
(
long
long
arg
)
{
longlong_return
val
;
val
.
msg
=
"long long called"
;
return
val
;
}
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