diff --git a/examples/rp2/pio_pwm.py b/examples/rp2/pio_pwm.py index 8e87448ca..176a23809 100644 --- a/examples/rp2/pio_pwm.py +++ b/examples/rp2/pio_pwm.py @@ -41,5 +41,5 @@ pwm = PIOPWM(0, 25, max_count=(1 << 16) - 1, count_freq=10_000_000) while True: for i in range(256): - pwm.set(i ** 2) + pwm.set(i**2) sleep(0.01) diff --git a/tests/cpydiff/modules_random_randint.py b/tests/cpydiff/modules_random_randint.py index b05908a15..90607400c 100644 --- a/tests/cpydiff/modules_random_randint.py +++ b/tests/cpydiff/modules_random_randint.py @@ -8,5 +8,5 @@ workaround: If you need integers larger than native wordsize use the random modu import random -x = random.randint(2 ** 128 - 1, 2 ** 128) +x = random.randint(2**128 - 1, 2**128) print("x={}".format(x)) diff --git a/tests/float/complex1.py b/tests/float/complex1.py index a510ffc83..139bb0c50 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -27,15 +27,15 @@ print(1j * 2j) print(1j / 2) print((1j / 2j).real) print(1j / (1 + 2j)) -ans = 0j ** 0 +ans = 0j**0 print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 0j ** 1 +ans = 0j**1 print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 0j ** 0j +ans = 0j**0j print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 1j ** 2.5 +ans = 1j**2.5 print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 1j ** 2.5j +ans = 1j**2.5j print("%.5g %.5g" % (ans.real, ans.imag)) # comparison @@ -116,10 +116,10 @@ except ZeroDivisionError: # zero division via power try: - 0j ** -1 + 0j**-1 except ZeroDivisionError: print("ZeroDivisionError") try: - 0j ** 1j + 0j**1j except ZeroDivisionError: print("ZeroDivisionError") diff --git a/tests/float/float1.py b/tests/float/float1.py index efde5146b..37f8b3fac 100644 --- a/tests/float/float1.py +++ b/tests/float/float1.py @@ -88,7 +88,7 @@ except ZeroDivisionError: print("ZeroDivisionError") try: - 0.0 ** -1 + 0.0**-1 except ZeroDivisionError: print("ZeroDivisionError") diff --git a/tests/float/float2int_doubleprec_intbig.py b/tests/float/float2int_doubleprec_intbig.py index 418eddb60..adc76d4ae 100644 --- a/tests/float/float2int_doubleprec_intbig.py +++ b/tests/float/float2int_doubleprec_intbig.py @@ -35,8 +35,8 @@ if ll_type != 0: print(int(1418774543.0)) print("%d" % 1418774543.0) if ll_type == 3: - print(int(2.0 ** 100)) - print("%d" % 2.0 ** 100) + print(int(2.0**100)) + print("%d" % 2.0**100) else: print(int(1073741823.0)) print("%d" % 1073741823.0) @@ -44,7 +44,7 @@ else: testpass = True p2_rng = ((30, 63, 1024), (62, 63, 1024))[is_64bit][ll_type] for i in range(0, p2_rng): - bitcnt = len(bin(int(2.0 ** i))) - 3 + bitcnt = len(bin(int(2.0**i))) - 3 if i != bitcnt: print("fail: 2**%u was %u bits long" % (i, bitcnt)) testpass = False @@ -53,7 +53,7 @@ print("power of 2 test: %s" % (testpass and "passed" or "failed")) testpass = True p10_rng = ((9, 18, 23), (18, 18, 23))[is_64bit][ll_type] for i in range(0, p10_rng): - digcnt = len(str(int(10.0 ** i))) - 1 + digcnt = len(str(int(10.0**i))) - 1 if i != digcnt: print("fail: 10**%u was %u digits long" % (i, digcnt)) testpass = False @@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail): if ll_type != 2: if ll_type == 0: if is_64bit: - neg_bad_fp = -1.00000005 * 2.0 ** 62.0 - pos_bad_fp = 2.0 ** 62.0 - neg_good_fp = -(2.0 ** 62.0) - pos_good_fp = 0.99999993 * 2.0 ** 62.0 + neg_bad_fp = -1.00000005 * 2.0**62.0 + pos_bad_fp = 2.0**62.0 + neg_good_fp = -(2.0**62.0) + pos_good_fp = 0.99999993 * 2.0**62.0 else: - neg_bad_fp = -1.00000005 * 2.0 ** 30.0 - pos_bad_fp = 2.0 ** 30.0 - neg_good_fp = -(2.0 ** 30.0) - pos_good_fp = 0.9999999499 * 2.0 ** 30.0 + neg_bad_fp = -1.00000005 * 2.0**30.0 + pos_bad_fp = 2.0**30.0 + neg_good_fp = -(2.0**30.0) + pos_good_fp = 0.9999999499 * 2.0**30.0 else: - neg_bad_fp = -0.51 * 2.0 ** 64.0 - pos_bad_fp = 2.0 ** 63.0 - neg_good_fp = -(2.0 ** 63.0) - pos_good_fp = 1.9999998 * 2.0 ** 62.0 + neg_bad_fp = -0.51 * 2.0**64.0 + pos_bad_fp = 2.0**63.0 + neg_good_fp = -(2.0**63.0) + pos_good_fp = 1.9999998 * 2.0**62.0 fp2int_test(neg_bad_fp, "neg bad", True) fp2int_test(pos_bad_fp, "pos bad", True) fp2int_test(neg_good_fp, "neg good", False) fp2int_test(pos_good_fp, "pos good", False) else: - fp2int_test(-1.9999999999999981 * 2.0 ** 1023.0, "large neg", False) - fp2int_test(1.9999999999999981 * 2.0 ** 1023.0, "large pos", False) + fp2int_test(-1.9999999999999981 * 2.0**1023.0, "large neg", False) + fp2int_test(1.9999999999999981 * 2.0**1023.0, "large pos", False) fp2int_test(float("inf"), "inf test", True) fp2int_test(float("-inf"), "inf test", True) diff --git a/tests/float/float2int_fp30_intbig.py b/tests/float/float2int_fp30_intbig.py index fcbe2e309..4e3c1fa21 100644 --- a/tests/float/float2int_fp30_intbig.py +++ b/tests/float/float2int_fp30_intbig.py @@ -34,13 +34,13 @@ if ll_type is None: print(int(14187744.0)) print("%d" % 14187744.0) if ll_type == 2: - print(int(2.0 ** 100)) - print("%d" % 2.0 ** 100) + print(int(2.0**100)) + print("%d" % 2.0**100) testpass = True p2_rng = ((30, 63, 127), (62, 63, 127))[is_64bit][ll_type] for i in range(0, p2_rng): - bitcnt = len(bin(int(2.0 ** i))) - 3 + bitcnt = len(bin(int(2.0**i))) - 3 if i != bitcnt: print("fail: 2.**%u was %u bits long" % (i, bitcnt)) testpass = False @@ -50,7 +50,7 @@ print("power of 2 test: %s" % (testpass and "passed" or "failed")) testpass = True p10_rng = 9 for i in range(0, p10_rng): - digcnt = len(str(int(10.0 ** i))) - 1 + digcnt = len(str(int(10.0**i))) - 1 if i != digcnt: print("fail: 10.**%u was %u digits long" % (i, digcnt)) testpass = False @@ -69,28 +69,28 @@ def fp2int_test(num, name, should_fail): if ll_type != 2: if ll_type == 0: if is_64bit: - neg_bad_fp = -1.00000005 * 2.0 ** 62.0 - pos_bad_fp = 2.0 ** 62.0 - neg_good_fp = -(2.0 ** 62.0) - pos_good_fp = 0.99999993 * 2.0 ** 62.0 + neg_bad_fp = -1.00000005 * 2.0**62.0 + pos_bad_fp = 2.0**62.0 + neg_good_fp = -(2.0**62.0) + pos_good_fp = 0.99999993 * 2.0**62.0 else: - neg_bad_fp = -1.00000005 * 2.0 ** 30.0 - pos_bad_fp = 2.0 ** 30.0 - neg_good_fp = -(2.0 ** 30.0) - pos_good_fp = 0.9999999499 * 2.0 ** 30.0 + neg_bad_fp = -1.00000005 * 2.0**30.0 + pos_bad_fp = 2.0**30.0 + neg_good_fp = -(2.0**30.0) + pos_good_fp = 0.9999999499 * 2.0**30.0 else: - neg_bad_fp = -0.51 * 2.0 ** 64.0 - pos_bad_fp = 2.0 ** 63.0 - neg_good_fp = -(2.0 ** 63.0) - pos_good_fp = 1.9999998 * 2.0 ** 62.0 + neg_bad_fp = -0.51 * 2.0**64.0 + pos_bad_fp = 2.0**63.0 + neg_good_fp = -(2.0**63.0) + pos_good_fp = 1.9999998 * 2.0**62.0 fp2int_test(neg_bad_fp, "neg bad", True) fp2int_test(pos_bad_fp, "pos bad", True) fp2int_test(neg_good_fp, "neg good", False) fp2int_test(pos_good_fp, "pos good", False) else: - fp2int_test(-1.999999879 * 2.0 ** 126.0, "large neg", False) - fp2int_test(1.999999879 * 2.0 ** 126.0, "large pos", False) + fp2int_test(-1.999999879 * 2.0**126.0, "large neg", False) + fp2int_test(1.999999879 * 2.0**126.0, "large pos", False) fp2int_test(float("inf"), "inf test", True) fp2int_test(float("-inf"), "inf test", True) diff --git a/tests/float/float2int_intbig.py b/tests/float/float2int_intbig.py index 865aeea7b..739f98f80 100644 --- a/tests/float/float2int_intbig.py +++ b/tests/float/float2int_intbig.py @@ -37,13 +37,13 @@ print(int(14187745.)) print("%d" % 14187745.) # fmt: on if ll_type == 2: - print(int(2.0 ** 100)) - print("%d" % 2.0 ** 100) + print(int(2.0**100)) + print("%d" % 2.0**100) testpass = True p2_rng = ((30, 63, 127), (62, 63, 127))[is_64bit][ll_type] for i in range(0, p2_rng): - bitcnt = len(bin(int(2.0 ** i))) - 3 + bitcnt = len(bin(int(2.0**i))) - 3 if i != bitcnt: print("fail: 2.**%u was %u bits long" % (i, bitcnt)) testpass = False @@ -53,7 +53,7 @@ print("power of 2 test: %s" % (testpass and "passed" or "failed")) testpass = True p10_rng = 9 if (ll_type == 0 and ~is_64bit) else 11 for i in range(0, p10_rng): - digcnt = len(str(int(10.0 ** i))) - 1 + digcnt = len(str(int(10.0**i))) - 1 if i != digcnt: print("fail: 10.**%u was %u digits long" % (i, digcnt)) testpass = False @@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail): if ll_type != 2: if ll_type == 0: if is_64bit: - neg_bad_fp = -1.00000005 * 2.0 ** 62.0 - pos_bad_fp = 2.0 ** 62.0 - neg_good_fp = -(2.0 ** 62.0) - pos_good_fp = 0.99999993 * 2.0 ** 62.0 + neg_bad_fp = -1.00000005 * 2.0**62.0 + pos_bad_fp = 2.0**62.0 + neg_good_fp = -(2.0**62.0) + pos_good_fp = 0.99999993 * 2.0**62.0 else: - neg_bad_fp = -1.00000005 * 2.0 ** 30.0 - pos_bad_fp = 2.0 ** 30.0 - neg_good_fp = -(2.0 ** 30.0) - pos_good_fp = 0.9999999499 * 2.0 ** 30.0 + neg_bad_fp = -1.00000005 * 2.0**30.0 + pos_bad_fp = 2.0**30.0 + neg_good_fp = -(2.0**30.0) + pos_good_fp = 0.9999999499 * 2.0**30.0 else: - neg_bad_fp = -0.51 * 2.0 ** 64.0 - pos_bad_fp = 2.0 ** 63.0 - neg_good_fp = -(2.0 ** 63.0) - pos_good_fp = 1.9999998 * 2.0 ** 62.0 + neg_bad_fp = -0.51 * 2.0**64.0 + pos_bad_fp = 2.0**63.0 + neg_good_fp = -(2.0**63.0) + pos_good_fp = 1.9999998 * 2.0**62.0 fp2int_test(neg_bad_fp, "neg bad", True) fp2int_test(pos_bad_fp, "pos bad", True) fp2int_test(neg_good_fp, "neg good", False) fp2int_test(pos_good_fp, "pos good", False) else: - fp2int_test(-1.999999879 * 2.0 ** 127.0, "large neg", False) - fp2int_test(1.999999879 * 2.0 ** 127.0, "large pos", False) + fp2int_test(-1.999999879 * 2.0**127.0, "large neg", False) + fp2int_test(1.999999879 * 2.0**127.0, "large pos", False) fp2int_test(float("inf"), "inf test", True) fp2int_test(float("nan"), "NaN test", True) diff --git a/tests/float/inf_nan_arith.py b/tests/float/inf_nan_arith.py index c27e38bc5..d1a6b1887 100644 --- a/tests/float/inf_nan_arith.py +++ b/tests/float/inf_nan_arith.py @@ -14,7 +14,7 @@ for x in values: except ZeroDivisionError: print(" / ZeroDivisionError") try: - print(" ** pow", x ** y, pow(x, y)) + print(" ** pow", x**y, pow(x, y)) except ZeroDivisionError: print(" ** pow ZeroDivisionError") print(" == != < <= > >=", x == y, x != y, x < y, x <= y, x > y, x >= y) diff --git a/tests/float/int_big_float.py b/tests/float/int_big_float.py index 0bd166218..dc13e8e0d 100644 --- a/tests/float/int_big_float.py +++ b/tests/float/int_big_float.py @@ -19,7 +19,7 @@ print("%.5g" % (i / 1.2)) print("%.5g" % (i * 1.2j).imag) # negative power should produce float -print("%.5g" % (i ** -1)) +print("%.5g" % (i**-1)) print("%.5g" % ((2 + i - i) ** -3)) try: diff --git a/tests/float/int_divzero.py b/tests/float/int_divzero.py index b311a1dbc..ef3531bee 100644 --- a/tests/float/int_divzero.py +++ b/tests/float/int_divzero.py @@ -4,6 +4,6 @@ except ZeroDivisionError: print("ZeroDivisionError") try: - 0 ** -1 + 0**-1 except ZeroDivisionError: print("ZeroDivisionError") diff --git a/tests/float/int_power.py b/tests/float/int_power.py index ba79247a5..bcda0f98e 100644 --- a/tests/float/int_power.py +++ b/tests/float/int_power.py @@ -1,7 +1,7 @@ # negative power should produce float x = 2 -print(x ** -2) +print(x**-2) x = 3 x **= -2 diff --git a/tests/micropython/import_mpy_native_x64.py b/tests/micropython/import_mpy_native_x64.py index cad59e991..ff0142a9c 100644 --- a/tests/micropython/import_mpy_native_x64.py +++ b/tests/micropython/import_mpy_native_x64.py @@ -9,7 +9,7 @@ except (ImportError, AttributeError): print("SKIP") raise SystemExit -if not (usys.platform == "linux" and usys.maxsize > 2 ** 32): +if not (usys.platform == "linux" and usys.maxsize > 2**32): print("SKIP") raise SystemExit diff --git a/tests/misc/rge_sm.py b/tests/misc/rge_sm.py index f3bb4189f..00b0a7a02 100644 --- a/tests/misc/rge_sm.py +++ b/tests/misc/rge_sm.py @@ -52,12 +52,12 @@ class RungeKutta(object): # couplings are: g1, g2, g3 of U(1), SU(2), SU(3); yt (top Yukawa), lambda (Higgs quartic) # see arxiv.org/abs/0812.4950, eqs 10-15 sysSM = ( - lambda *a: 41.0 / 96.0 / math.pi ** 2 * a[1] ** 3, # g1 - lambda *a: -19.0 / 96.0 / math.pi ** 2 * a[2] ** 3, # g2 - lambda *a: -42.0 / 96.0 / math.pi ** 2 * a[3] ** 3, # g3 + lambda *a: 41.0 / 96.0 / math.pi**2 * a[1] ** 3, # g1 + lambda *a: -19.0 / 96.0 / math.pi**2 * a[2] ** 3, # g2 + lambda *a: -42.0 / 96.0 / math.pi**2 * a[3] ** 3, # g3 lambda *a: 1.0 / 16.0 - / math.pi ** 2 + / math.pi**2 * ( 9.0 / 2.0 * a[4] ** 3 - 8.0 * a[3] ** 2 * a[4] @@ -66,7 +66,7 @@ sysSM = ( ), # yt lambda *a: 1.0 / 16.0 - / math.pi ** 2 + / math.pi**2 * ( 24.0 * a[5] ** 2 + 12.0 * a[4] ** 2 * a[5] @@ -137,5 +137,5 @@ def singleTraj(system, trajStart, h=0.02, tend=1.0): # initial conditions at M_Z singleTraj( - sysSM, [0.354, 0.654, 1.278, 0.983, 0.131], h=0.5, tend=math.log(10 ** 17) + sysSM, [0.354, 0.654, 1.278, 0.983, 0.131], h=0.5, tend=math.log(10**17) ) # true values diff --git a/tests/perf_bench/bm_chaos.py b/tests/perf_bench/bm_chaos.py index 55d282561..d0f1337db 100644 --- a/tests/perf_bench/bm_chaos.py +++ b/tests/perf_bench/bm_chaos.py @@ -15,7 +15,7 @@ class GVector(object): self.z = z def Mag(self): - return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2) + return math.sqrt(self.x**2 + self.y**2 + self.z**2) def dist(self, other): return math.sqrt( diff --git a/tests/perf_bench/misc_raytrace.py b/tests/perf_bench/misc_raytrace.py index b51acacca..a729af99c 100644 --- a/tests/perf_bench/misc_raytrace.py +++ b/tests/perf_bench/misc_raytrace.py @@ -22,7 +22,7 @@ class Vec: return Vec(self.x * rhs, self.y * rhs, self.z * rhs) def length(self): - return (self.x ** 2 + self.y ** 2 + self.z ** 2) ** 0.5 + return (self.x**2 + self.y**2 + self.z**2) ** 0.5 def normalise(self): l = self.length() @@ -87,12 +87,12 @@ class Sphere: def __init__(self, surface, centre, radius): self.surface = surface self.centre = centre - self.radsq = radius ** 2 + self.radsq = radius**2 def intersect(self, ray): v = self.centre - ray.p b = v.dot(ray.d) - det = b ** 2 - v.dot(v) + self.radsq + det = b**2 - v.dot(v) + self.radsq if det > 0: det **= 0.5 t1 = b - det @@ -180,7 +180,7 @@ def trace_ray(scene, ray, depth): if ndotl > 0: col += light_col * surf.diffuse * ndotl if ldotv > 0: - col += light_col * surf.specular * ldotv ** surf.spec_idx + col += light_col * surf.specular * ldotv**surf.spec_idx # Reflections if depth > 0 and surf.reflect > 0: diff --git a/tests/run-perfbench.py b/tests/run-perfbench.py index bcdbe69ab..5f299281f 100755 --- a/tests/run-perfbench.py +++ b/tests/run-perfbench.py @@ -33,8 +33,8 @@ def compute_stats(lst): avg += x var += x * x avg /= len(lst) - var = max(0, var / len(lst) - avg ** 2) - return avg, var ** 0.5 + var = max(0, var / len(lst) - avg**2) + return avg, var**0.5 def run_script_on_target(target, script): @@ -201,7 +201,7 @@ def compute_diff(file1, file2, diff_score): sd1 *= av1 / 100 # convert from percent sd to absolute sd sd2 *= av2 / 100 # convert from percent sd to absolute sd av_diff = av2 - av1 - sd_diff = (sd1 ** 2 + sd2 ** 2) ** 0.5 + sd_diff = (sd1**2 + sd2**2) ** 0.5 percent = 100 * av_diff / av1 percent_sd = 100 * sd_diff / av1 print(