Skip to content

Commit

Permalink
Portable Python script across Python version
Browse files Browse the repository at this point in the history
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

llvm-svn: 349455
  • Loading branch information
serge-sans-paille-qb committed Dec 18, 2018
1 parent c0ebe77 commit 3744de5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clang/utils/ABITest/TypeGen.py
@@ -1,5 +1,5 @@
"""Flexible enumeration of C types."""
from __future__ import print_function
from __future__ import division, print_function

from Enumeration import *

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions clang/utils/analyzer/CmpRuns.py
Expand Up @@ -25,7 +25,7 @@
diff = compareResults(resultsA, resultsB)
"""
from __future__ import print_function
from __future__ import division, print_function

from collections import defaultdict

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3744de5

Please sign in to comment.