[PATCH] D67821: [LNT] Python 3 support: use Python 2's division behavior

Hubert Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 08:49:57 PDT 2019


hubert.reinterpretcast added inline comments.


================
Comment at: examples/functions.py:33
 
-    offset = math.pi/5
+    offset = old_div(math.pi, 5)
     delay = 120.
----------------
Clearly float division.


================
Comment at: examples/functions.py:44
     tests = [TestSamples('simple.%s' % name,
-                         [fn(start*2*math.pi / delay + j * offset)],
+                         [fn(old_div(start * 2 * math.pi, delay)
+                             + j * offset)],
----------------
Same.


================
Comment at: lnt/external/stats/pstat.py:142
             if len(source) % len(addon) == 0:        # are they integer multiples?
-                repeats = len(source)/len(addon)    # repeat addon n times
+                repeats = old_div(len(source), len(addon))    # repeat addon n times
                 origadd = copy.deepcopy(addon)
----------------
Clearly floor division (`len(source) // len(addon)`). Also for the rest of the changes in the file.


================
Comment at: lnt/external/stats/stats.py:295
         sum = sum + 1.0/item
-    return len(inlist) / sum
+    return old_div(len(inlist), sum)
 
----------------
Except for division by zero (which is equally bad between floor division and float division), this is float division. 


================
Comment at: lnt/external/stats/stats.py:343
     if len(newlist) % 2 == 0:   # if even number of scores, average middle 2
-        index = len(newlist)/2  # integer division correct
+        index = old_div(len(newlist), 2)  # integer division correct
         median = float(newlist[index] + newlist[index-1]) /2
----------------
There are a few instances in the patch where the change is made where integer division is clearly stated to be the intent, and many cases where it is clear which division operation would have taken place in Python 2 (or cases where the floor division occurs only in degenerate cases and float division is fine anyway).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67821/new/

https://reviews.llvm.org/D67821





More information about the llvm-commits mailing list