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
2520038e
Commit
2520038e
authored
Jan 24, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #480: float() as a type cast for function return values
parent
bf325529
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
+23
-6
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+6
-3
tests/run/float_len_T480.pyx
tests/run/float_len_T480.pyx
+17
-3
No files found.
Cython/Compiler/Optimize.py
View file @
2520038e
...
...
@@ -960,13 +960,15 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
if
func_arg
.
type
==
node
.
type
:
return
func_arg
elif
node
.
type
.
assignable_from
(
func_arg
.
type
)
or
func_arg
.
type
.
is_float
:
return
ExprNodes
.
CastNode
(
func_arg
,
node
.
type
)
return
ExprNodes
.
TypecastNode
(
node
.
pos
,
operand
=
func_arg
,
type
=
node
.
type
)
elif
function
.
name
==
'float'
:
if
func_arg
.
type
.
is_float
or
node
.
type
.
is_float
:
if
func_arg
.
type
==
node
.
type
:
return
func_arg
elif
node
.
type
.
assignable_from
(
func_arg
.
type
)
or
func_arg
.
type
.
is_float
:
return
ExprNodes
.
CastNode
(
func_arg
,
node
.
type
)
return
ExprNodes
.
TypecastNode
(
node
.
pos
,
operand
=
func_arg
,
type
=
node
.
type
)
return
node
### dispatch to specific optimisers
...
...
@@ -1115,7 +1117,8 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
if
func_arg
.
type
is
PyrexTypes
.
c_double_type
:
return
func_arg
elif
node
.
type
.
assignable_from
(
func_arg
.
type
)
or
func_arg
.
type
.
is_numeric
:
return
ExprNodes
.
CastNode
(
func_arg
,
node
.
type
)
return
ExprNodes
.
TypecastNode
(
node
.
pos
,
operand
=
func_arg
,
type
=
node
.
type
)
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_PyObject_AsDouble"
,
self
.
PyObject_AsDouble_func_type
,
...
...
tests/run/float_len_T480.pyx
View file @
2520038e
def
f
(
x
):
return
x
def
float_len
(
x
):
def
len_f
(
x
):
"""
>>> float_len([1,2,3])
>>> len_f([1,2,3])
3
"""
return
len
(
f
(
x
))
def
float_len_f
(
x
):
"""
>>> float_len_f([1,2,3])
3.0
"""
return
float
(
len
(
f
(
x
)))
def
cast_len_f
(
x
):
"""
>>> cast_len_f([1,2,3])
3.0
"""
float
(
len
(
f
(
x
)
))
return
<
double
>
len
(
f
(
x
))
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