]> granicus.if.org Git - clang/commitdiff
Portable Python script across Python version
authorSerge Guelton <sguelton@quarkslab.com>
Tue, 18 Dec 2018 08:38:50 +0000 (08:38 +0000)
committerSerge Guelton <sguelton@quarkslab.com>
Tue, 18 Dec 2018 08:38:50 +0000 (08:38 +0000)
In Python2, division between integer yields an integer, while it yields a float in Python3.
Use a combination of from __future__ import division and // operator to get a portable behavior.

Differential Revision: https://reviews.llvm.org/D55204

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349455 91177308-0d34-0410-b5e6-96231b3b80d8

utils/ABITest/TypeGen.py
utils/analyzer/CmpRuns.py

index 608089429ac840759082846491758c8a3386c723..698e358829f92368bc38832b11b57ff8d680ce58 100644 (file)
@@ -1,5 +1,5 @@
 """Flexible enumeration of C types."""
-from __future__ import print_function
+from __future__ import division, print_function
 
 from Enumeration import *
 
@@ -235,7 +235,7 @@ def fact(n):
 
 # Compute the number of combinations (n choose k)
 def num_combinations(n, k): 
-    return fact(n) / (fact(k) * fact(n - k))
+    return fact(n) // (fact(k) * fact(n - k))
 
 # Enumerate the combinations choosing k elements from the list of values
 def combinations(values, k):
index 14be963296a7423d5b74b2ae90dc473289ed5d07..87d5eda7a1806319e86b0e7d674075b810a9cf0a 100755 (executable)
@@ -25,7 +25,7 @@ Usage:
     diff = compareResults(resultsA, resultsB)
 
 """
-from __future__ import print_function
+from __future__ import division, print_function
 
 from collections import defaultdict
 
@@ -308,7 +308,7 @@ def deriveStats(results):
             "mean": sum(values) / len(values),
             "90th %tile": computePercentile(values, 0.9),
             "95th %tile": computePercentile(values, 0.95),
-            "median": sorted(values)[len(values) / 2],
+            "median": sorted(values)[len(values) // 2],
             "total": sum(values)
         }
     return combined_stats