"+": "PyNumber_Add",
"-": "PyNumber_Subtract",
"*": "PyNumber_Multiply",
- "/": "PyNumber_Divide",
+ "/": "__Pyx_PyNumber_Divide",
"//": "PyNumber_FloorDivide",
"%": "PyNumber_Remainder",
"**": "PyNumber_Power"
import os, time
from cStringIO import StringIO
from PyrexTypes import CPtrType
+import Future
try:
set
code.putln(" #define PyInt_AsSsize_t PyLong_AsSsize_t")
code.putln(" #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask")
code.putln(" #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask")
- code.putln(" #define PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)")
+ code.putln(" #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)")
code.putln("#else")
+ if Future.division in env.context.future_directives:
+ code.putln(" #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)")
+ else:
+ code.putln(" #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)")
code.putln(" #define PyBytes_Type PyString_Type")
code.putln("#endif")
--- /dev/null
+from __future__ import division
+
+__doc__ = """
+>>> from future_division import doit
+>>> doit(1,2)
+(0.5, 0)
+>>> doit(4,3)
+(1.3333333333333333, 1)
+>>> doit(4,3.0)
+(1.3333333333333333, 1.0)
+>>> doit(4,2)
+(2.0, 2)
+"""
+
+def doit(x,y):
+ return x/y, x//y