enable two-value form of builtin pow()
authorStefan Behnel <scoder@users.berlios.de>
Thu, 4 Nov 2010 22:45:44 +0000 (23:45 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 4 Nov 2010 22:45:44 +0000 (23:45 +0100)
Cython/Compiler/Builtin.py
tests/compile/builtinfuncs.pyx
tests/run/builtin_pow.pyx [new file with mode: 0644]

index 63609c2ba83d66fe813662ab3618e3d7e99ca8b3..096af2e88c85405b58abce4223a67c3bf069518c 100644 (file)
@@ -44,6 +44,7 @@ builtin_function_table = [
     #('open',       "ss",   "O",     "PyFile_FromString"),
     #('ord',       "",     "",      ""),
     ('pow',        "OOO",  "O",     "PyNumber_Power"),
+    ('pow',        "OO",   "O",     "__Pyx_PyNumber_Power2"),
     #('range',     "",     "",      ""),
     #('raw_input', "",     "",      ""),
     #('reduce',    "",     "",      ""),
@@ -152,6 +153,11 @@ builtin_structs_table = [
       ])
 ]
 
+pow2_utility_code = UtilityCode(
+proto = """
+#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
+""")
+
 getattr3_utility_code = UtilityCode(
 proto = """
 static PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/
@@ -383,6 +389,7 @@ Py_XDECREF(__Pyx_PyFrozenSet_Type); __Pyx_PyFrozenSet_Type = NULL;
 builtin_utility_code = {
     'exec'      : pyexec_utility_code,
     'getattr3'  : getattr3_utility_code,
+    'pow'       : pow2_utility_code,
     'intern'    : intern_utility_code,
     'set'       : py23_set_utility_code,
     'frozenset' : py23_set_utility_code,
index 795826c887631a9b2435a2a3a23f40bf080a0fbe..096ee870e313e35feb83d66719659c6fda32965c 100644 (file)
@@ -15,6 +15,7 @@ cdef int f() except -1:
     i = len(x)
     x = open(y, z)
     x = pow(y, z, w)
+    x = pow(y, z)
     x = reload(y)
     x = repr(y)
     setattr(x, y, z)
diff --git a/tests/run/builtin_pow.pyx b/tests/run/builtin_pow.pyx
new file mode 100644 (file)
index 0000000..8b4b4f0
--- /dev/null
@@ -0,0 +1,32 @@
+
+def pow3(a,b,c):
+    """
+    >>> pow3(2,3,5)
+    3
+    >>> pow3(3,3,5)
+    2
+    """
+    return pow(a,b,c)
+
+def pow3_const():
+    """
+    >>> pow3_const()
+    3
+    """
+    return pow(2,3,5)
+
+def pow2(a,b):
+    """
+    >>> pow2(2,3)
+    8
+    >>> pow2(3,3)
+    27
+    """
+    return pow(a,b)
+
+def pow2_const():
+    """
+    >>> pow2_const()
+    8
+    """
+    return pow(2,3)