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
Boxiang Sun
cython
Commits
64724e68
Commit
64724e68
authored
Mar 14, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pow operator on ints
parent
c14da739
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
20 deletions
+44
-20
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+44
-20
No files found.
Cython/Compiler/ExprNodes.py
View file @
64724e68
...
@@ -4255,29 +4255,22 @@ class ModNode(NumBinopNode):
...
@@ -4255,29 +4255,22 @@ class ModNode(NumBinopNode):
class
PowNode
(
NumBinopNode
):
class
PowNode
(
NumBinopNode
):
# '**' operator.
# '**' operator.
def
compute_c_result_type
(
self
,
type1
,
type2
):
def
analyse_c_operation
(
self
,
env
):
if
self
.
c_types_okay
(
type1
,
type2
):
NumBinopNode
.
analyse_c_operation
(
self
,
env
)
return
PyrexTypes
.
c_double_type
if
self
.
operand1
.
type
.
is_float
or
self
.
operand2
.
type
.
is_float
:
self
.
pow_func
=
"pow"
else
:
else
:
return
None
self
.
pow_func
=
"__Pyx_pow_%s"
%
self
.
type
.
declaration_code
(
''
).
replace
(
' '
,
'_'
)
env
.
use_utility_code
(
def
c_types_okay
(
self
,
type1
,
type2
):
int_pow_utility_code
.
specialize
(
func_name
=
self
.
pow_func
,
return
(
type1
.
is_float
or
type2
.
is_float
)
and
\
type
=
self
.
type
.
declaration_code
(
''
)))
NumBinopNode
.
c_types_okay
(
self
,
type1
,
type2
)
def
type_error
(
self
):
if
not
(
self
.
operand1
.
type
.
is_error
or
self
.
operand2
.
type
.
is_error
):
if
self
.
operand1
.
type
.
is_int
and
self
.
operand2
.
type
.
is_int
:
error
(
self
.
pos
,
"C has no integer powering, use python ints or floats instead '%s' (%s; %s)"
%
(
self
.
operator
,
self
.
operand1
.
type
,
self
.
operand2
.
type
))
else
:
NumBinopNode
.
type_error
(
self
)
self
.
type
=
PyrexTypes
.
error_type
def
calculate_result_code
(
self
):
def
calculate_result_code
(
self
):
return
"pow(%s, %s)"
%
(
return
"%s(%s, %s)"
%
(
self
.
operand1
.
result
(),
self
.
operand2
.
result
())
self
.
pow_func
,
self
.
operand1
.
result
(),
self
.
operand2
.
result
())
# Note: This class is temporary "shut down" into an ineffective mode temp
# Note: This class is temporary "shut down" into an ineffective mode temp
...
@@ -5611,3 +5604,34 @@ static int __Pyx_EndUnpack(PyObject *iter) {
...
@@ -5611,3 +5604,34 @@ static int __Pyx_EndUnpack(PyObject *iter) {
requires
=
[
raise_need_more_values_to_unpack
,
requires
=
[
raise_need_more_values_to_unpack
,
raise_too_many_values_to_unpack
]
raise_too_many_values_to_unpack
]
)
)
#------------------------------------------------------------------------------------
int_pow_utility_code
=
UtilityCode
(
proto
=
"""
static INLINE %(type)s %(func_name)s(%(type)s, %(type)s); /* proto */
"""
,
impl
=
"""
static INLINE %(type)s %(func_name)s(%(type)s b, %(type)s e) {
%(type)s t = b;
switch (e) {
case 3:
t *= b;
case 2:
t *= b;
case 1:
return t;
case 0:
return 1;
}
if (unlikely(e<0)) return 0;
t = 1;
while (likely(e)) {
t *= (b * (e&1)) | ((~e)&1); /* 1 or b */
b *= b;
e >>= 1;
}
return t;
}
"""
)
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