Cython has moved to github.

cython-devel

view tests/run/non_future_division.pyx @ 2299:a3ad25325fe4

fix __future__ division semantics for constant expressions and C integers
author Stefan Behnel <scoder@users.berlios.de>
date Wed Jul 08 21:13:14 2009 +0200 (2 years ago)
parents tests/run/future_division.pyx@0310198e281e
children 4c1766b9f8e5
line source
1 # Py2.x mixed true-div/floor-div behaviour of '/' operator
3 __doc__ = u"""
4 >>> doit(1,2)
5 (0, 0)
6 >>> doit(4,3)
7 (1, 1)
8 >>> doit(4,3.0)
9 (1.3333333333333333, 1.0)
10 >>> doit(4,2)
11 (2, 2)
13 >>> constants()
14 (0, 0, 2.5, 2.0, 2, 2)
16 >>> py_mix(1)
17 (0, 0, 0.5, 0.0, 0, 0)
19 >>> py_mix_rev(4)
20 (0, 0, 1.25, 1.0, 1, 1)
22 >>> py_mix(1.0)
23 (0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
25 >>> py_mix_rev(4.0)
26 (0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
28 >>> int_mix(1)
29 (0, 0, 0.5, 0.0, 0, 0)
31 >>> int_mix_rev(4)
32 (0, 0, 1.25, 1.0, 1, 1)
34 >>> float_mix(1.0)
35 (0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
37 >>> float_mix_rev(4.0)
38 (0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
39 """
41 def doit(x,y):
42 return x/y, x//y
44 def constants():
45 return 1/2, 1//2, 5/2.0, 5//2.0, 5/2, 5//2
47 def py_mix(a):
48 return a/2, a//2, a/2.0, a//2.0, a/2, a//2
50 def py_mix_rev(a):
51 return 1/a, 1//a, 5.0/a, 5.0//a, 5/a, 5//a
53 def int_mix(int a):
54 return a/2, a//2, a/2.0, a//2.0, a/2, a//2
56 def int_mix_rev(int a):
57 return 1/a, 1//a, 5.0/a, 5.0//a, 5/a, 5//a
59 def float_mix(float a):
60 return a/2, a//2, a/2.0, a//2.0, a/2, a//2
62 def float_mix_rev(float a):
63 return 1/a, 1//a, 5.0/a, 5.0//a, 5/a, 5//a