[Piglit] [PATCH 32/34] gen_cl_int_builtins.py: use __future__ division

Dylan Baker baker.dylan.c at gmail.com
Fri Feb 20 18:18:19 PST 2015


in python2 without future division the division operator is retarded:

1/2 = 0
1/2.0 = 0.5

In python3 or python2 with future division there are two division
operators: / and //, and they behave sanely:

1/2 = 0.5
1//2 = 0
1/2.0 = 0.5
1//2.0 = 0.0

This is obviously necessary for porting to python3 to get the same
behavior between the python2 and the python3 generators.

This generator produces teh same result before and after this change.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/gen_cl_int_builtins.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/generated_tests/gen_cl_int_builtins.py b/generated_tests/gen_cl_int_builtins.py
index 15ce308..c86bdd0 100644
--- a/generated_tests/gen_cl_int_builtins.py
+++ b/generated_tests/gen_cl_int_builtins.py
@@ -1,3 +1,4 @@
+from __future__ import division
 import os
 from genclbuiltins import gen, DATA_SIZES, MAX_VALUES, MAX, MIN, BMIN, BMAX, \
                           SMIN, SMAX, UMIN, UMAX, TYPE, SIZE, T, U, B
@@ -84,7 +85,7 @@ def clz(type, val):
 
 
 def div(val1, val2):
-    return val1 / val2
+    return val1 // val2
 
 
 def mad_hi(x, y, z, type):
-- 
2.3.0



More information about the Piglit mailing list