summaryrefslogtreecommitdiff
path: root/tests/float
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2020-03-22 21:26:08 -0500
committerDamien George <damien.p.george@gmail.com>2020-03-30 13:21:58 +1100
commit3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch)
tree94ff44f8eabba0039582c245b901173597edd11e /tests/float
parent488613bca6c460340ed2995ae5cafafe22d0bfff (diff)
tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/array_construct.py4
-rw-r--r--tests/float/builtin_float_abs.py18
-rw-r--r--tests/float/builtin_float_hash.py32
-rw-r--r--tests/float/builtin_float_minmax.py1
-rw-r--r--tests/float/builtin_float_pow.py6
-rw-r--r--tests/float/builtin_float_round.py16
-rw-r--r--tests/float/builtin_float_round_intbig.py2
-rw-r--r--tests/float/bytearray_construct.py2
-rw-r--r--tests/float/bytes_construct.py2
-rw-r--r--tests/float/cmath_fun.py34
-rw-r--r--tests/float/cmath_fun_special.py13
-rw-r--r--tests/float/complex1.py37
-rw-r--r--tests/float/complex1_intbig.py3
-rw-r--r--tests/float/float1.py10
-rw-r--r--tests/float/float2int_doubleprec_intbig.py81
-rw-r--r--tests/float/float2int_fp30_intbig.py75
-rw-r--r--tests/float/float2int_intbig.py72
-rw-r--r--tests/float/float_array.py14
-rw-r--r--tests/float/float_compare.py2
-rw-r--r--tests/float/float_divmod.py4
-rw-r--r--tests/float/float_divmod_relaxed.py4
-rw-r--r--tests/float/float_format.py14
-rw-r--r--tests/float/float_parse.py38
-rw-r--r--tests/float/float_parse_doubleprec.py24
-rw-r--r--tests/float/float_struct.py7
-rw-r--r--tests/float/int_power.py2
-rw-r--r--tests/float/math_domain.py56
-rw-r--r--tests/float/math_domain_special.py39
-rw-r--r--tests/float/math_factorial_intbig.py7
-rw-r--r--tests/float/math_fun.py90
-rw-r--r--tests/float/math_fun_bool.py3
-rw-r--r--tests/float/math_fun_int.py2
-rw-r--r--tests/float/math_fun_intbig.py2
-rw-r--r--tests/float/math_fun_special.py47
-rw-r--r--tests/float/math_isclose.py13
-rw-r--r--tests/float/python36.py8
-rw-r--r--tests/float/string_format.py19
-rw-r--r--tests/float/string_format2.py168
-rw-r--r--tests/float/string_format_fp30.py23
-rw-r--r--tests/float/string_format_modulo.py40
-rw-r--r--tests/float/string_format_modulo2.py14
-rw-r--r--tests/float/string_format_modulo2_intbig.py12
-rw-r--r--tests/float/string_format_modulo3.py4
-rw-r--r--tests/float/true_value.py2
44 files changed, 618 insertions, 448 deletions
diff --git a/tests/float/array_construct.py b/tests/float/array_construct.py
index eb735c67c..f6a3a9dc9 100644
--- a/tests/float/array_construct.py
+++ b/tests/float/array_construct.py
@@ -9,5 +9,5 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(array('f', array('h', [1, 2])))
-print(array('d', array('f', [1, 2])))
+print(array("f", array("h", [1, 2])))
+print(array("d", array("f", [1, 2])))
diff --git a/tests/float/builtin_float_abs.py b/tests/float/builtin_float_abs.py
index c0935c6ee..f7ce9e156 100644
--- a/tests/float/builtin_float_abs.py
+++ b/tests/float/builtin_float_abs.py
@@ -1,13 +1,13 @@
# test builtin abs function with float args
for val in (
- '1.0',
- '-1.0',
- '0.0',
- '-0.0',
- 'nan',
- '-nan',
- 'inf',
- '-inf',
- ):
+ "1.0",
+ "-1.0",
+ "0.0",
+ "-0.0",
+ "nan",
+ "-nan",
+ "inf",
+ "-inf",
+):
print(val, abs(float(val)))
diff --git a/tests/float/builtin_float_hash.py b/tests/float/builtin_float_hash.py
index 7a7e37401..1388bb0e8 100644
--- a/tests/float/builtin_float_hash.py
+++ b/tests/float/builtin_float_hash.py
@@ -2,24 +2,24 @@
# these should hash to an integer with a specific value
for val in (
- '0.0',
- '-0.0',
- '1.0',
- '2.0',
- '-12.0',
- '12345.0',
- ):
+ "0.0",
+ "-0.0",
+ "1.0",
+ "2.0",
+ "-12.0",
+ "12345.0",
+):
print(val, hash(float(val)))
# just check that these values are hashable
for val in (
- '0.1',
- '-0.1',
- '10.3',
- '0.4e3',
- '1e16',
- 'inf',
- '-inf',
- 'nan',
- ):
+ "0.1",
+ "-0.1",
+ "10.3",
+ "0.4e3",
+ "1e16",
+ "inf",
+ "-inf",
+ "nan",
+):
print(val, type(hash(float(val))))
diff --git a/tests/float/builtin_float_minmax.py b/tests/float/builtin_float_minmax.py
index 266ed133d..8a53746e5 100644
--- a/tests/float/builtin_float_minmax.py
+++ b/tests/float/builtin_float_minmax.py
@@ -29,4 +29,3 @@ print(min([1, 2.9, 4, 6.5, -1, 2]))
print(max([1, 2.9, 4, 6.5, -1, 2]))
print(min([1, 2.9, 4, -6.5, -1, 2]))
print(max([1, 2.9, 4, -6.5, -1, 2]))
-
diff --git a/tests/float/builtin_float_pow.py b/tests/float/builtin_float_pow.py
index 2de1b4817..98998bdc7 100644
--- a/tests/float/builtin_float_pow.py
+++ b/tests/float/builtin_float_pow.py
@@ -6,6 +6,6 @@ print(pow(1.0, 1))
print(pow(2.0, 3.0))
print(pow(2.0, -4.0))
-print(pow(0.0, float('inf')))
-print(pow(0.0, float('-inf')))
-print(pow(0.0, float('nan')))
+print(pow(0.0, float("inf")))
+print(pow(0.0, float("-inf")))
+print(pow(0.0, float("nan")))
diff --git a/tests/float/builtin_float_round.py b/tests/float/builtin_float_round.py
index 63cb39aa3..1153b8a2b 100644
--- a/tests/float/builtin_float_round.py
+++ b/tests/float/builtin_float_round.py
@@ -2,8 +2,18 @@
# check basic cases
tests = [
- [0.0], [1.0], [0.1], [-0.1], [123.4], [123.6], [-123.4], [-123.6],
- [1.234567, 5], [1.23456, 1], [1.23456, 0], [1234.56, -2]
+ [0.0],
+ [1.0],
+ [0.1],
+ [-0.1],
+ [123.4],
+ [123.6],
+ [-123.4],
+ [-123.6],
+ [1.234567, 5],
+ [1.23456, 1],
+ [1.23456, 0],
+ [1234.56, -2],
]
for t in tests:
print(round(*t))
@@ -17,7 +27,7 @@ for i in range(-1, 3):
print(round(1.47, i))
# test inf and nan
-for val in (float('inf'), float('nan')):
+for val in (float("inf"), float("nan")):
try:
round(val)
except (ValueError, OverflowError) as e:
diff --git a/tests/float/builtin_float_round_intbig.py b/tests/float/builtin_float_round_intbig.py
index 2083e3ea3..c8a338eef 100644
--- a/tests/float/builtin_float_round_intbig.py
+++ b/tests/float/builtin_float_round_intbig.py
@@ -1,4 +1,4 @@
# test round() with floats that return large integers
for x in (-1e25, 1e25):
- print('%.3g' % round(x))
+ print("%.3g" % round(x))
diff --git a/tests/float/bytearray_construct.py b/tests/float/bytearray_construct.py
index 4e7631b2b..257d37d1b 100644
--- a/tests/float/bytearray_construct.py
+++ b/tests/float/bytearray_construct.py
@@ -9,4 +9,4 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(bytearray(array('f', [1, 2.3])))
+print(bytearray(array("f", [1, 2.3])))
diff --git a/tests/float/bytes_construct.py b/tests/float/bytes_construct.py
index 96294659b..0806087b0 100644
--- a/tests/float/bytes_construct.py
+++ b/tests/float/bytes_construct.py
@@ -9,4 +9,4 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(bytes(array('f', [1, 2.3])))
+print(bytes(array("f", [1, 2.3])))
diff --git a/tests/float/cmath_fun.py b/tests/float/cmath_fun.py
index d3df25e11..7b5e69245 100644
--- a/tests/float/cmath_fun.py
+++ b/tests/float/cmath_fun.py
@@ -11,29 +11,33 @@ print("%.5g" % e)
print("%.5g" % pi)
test_values_non_zero = []
-base_values = (0.0, 0.5, 1.2345, 10.)
+base_values = (0.0, 0.5, 1.2345, 10.0)
for r in base_values:
for i in base_values:
- if r != 0. or i != 0.:
+ if r != 0.0 or i != 0.0:
test_values_non_zero.append(complex(r, i))
- if r != 0.:
+ if r != 0.0:
test_values_non_zero.append(complex(-r, i))
- if i != 0.:
+ if i != 0.0:
test_values_non_zero.append(complex(r, -i))
- if r != 0. and i != 0.:
+ if r != 0.0 and i != 0.0:
test_values_non_zero.append(complex(-r, -i))
-test_values = [complex(0., 0.),] + test_values_non_zero
+test_values = [complex(0.0, 0.0),] + test_values_non_zero
print(test_values)
functions = [
- ('phase', phase, test_values),
- ('polar', polar, test_values),
- ('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))),
- ('exp', exp, test_values),
- ('log', log, test_values_non_zero),
- ('sqrt', sqrt, test_values),
- ('cos', cos, test_values),
- ('sin', sin, test_values),
+ ("phase", phase, test_values),
+ ("polar", polar, test_values),
+ (
+ "rect",
+ rect,
+ ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123.0, -456.0)),
+ ),
+ ("exp", exp, test_values),
+ ("log", log, test_values_non_zero),
+ ("sqrt", sqrt, test_values),
+ ("cos", cos, test_values),
+ ("sin", sin, test_values),
]
for f_name, f, test_vals in functions:
@@ -51,5 +55,5 @@ for f_name, f, test_vals in functions:
# some test (eg cmath.sqrt(-0.5)) disagree with CPython with tiny real part
real = ret.real
if abs(real) < 1e-6:
- real = 0.
+ real = 0.0
print("complex(%.5g, %.5g)" % (real, ret.imag))
diff --git a/tests/float/cmath_fun_special.py b/tests/float/cmath_fun_special.py
index 471fda8c0..33b94d04d 100644
--- a/tests/float/cmath_fun_special.py
+++ b/tests/float/cmath_fun_special.py
@@ -2,26 +2,27 @@
try:
from cmath import *
+
log10
except (ImportError, NameError):
print("SKIP")
raise SystemExit
test_values_non_zero = []
-base_values = (0.0, 0.5, 1.2345, 10.)
+base_values = (0.0, 0.5, 1.2345, 10.0)
for r in base_values:
for i in base_values:
- if r != 0. or i != 0.:
+ if r != 0.0 or i != 0.0:
test_values_non_zero.append(complex(r, i))
- if r != 0.:
+ if r != 0.0:
test_values_non_zero.append(complex(-r, i))
- if i != 0.:
+ if i != 0.0:
test_values_non_zero.append(complex(r, -i))
- if r != 0. and i != 0.:
+ if r != 0.0 and i != 0.0:
test_values_non_zero.append(complex(-r, -i))
functions = [
- ('log10', log10, test_values_non_zero),
+ ("log10", log10, test_values_non_zero),
]
for f_name, f, test_vals in functions:
diff --git a/tests/float/complex1.py b/tests/float/complex1.py
index c1fa61ba3..a510ffc83 100644
--- a/tests/float/complex1.py
+++ b/tests/float/complex1.py
@@ -27,11 +27,16 @@ print(1j * 2j)
print(1j / 2)
print((1j / 2j).real)
print(1j / (1 + 2j))
-ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag))
-ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag))
-ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag))
-ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag))
-ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
+ans = 0j ** 0
+print("%.5g %.5g" % (ans.real, ans.imag))
+ans = 0j ** 1
+print("%.5g %.5g" % (ans.real, ans.imag))
+ans = 0j ** 0j
+print("%.5g %.5g" % (ans.real, ans.imag))
+ans = 1j ** 2.5
+print("%.5g %.5g" % (ans.real, ans.imag))
+ans = 1j ** 2.5j
+print("%.5g %.5g" % (ans.real, ans.imag))
# comparison
print(1j == 1)
@@ -40,7 +45,7 @@ print(0 + 0j == False, 1 + 0j == True)
print(False == 0 + 0j, True == 1 + 0j)
# comparison of nan is special
-nan = float('nan') * 1j
+nan = float("nan") * 1j
print(nan == 1j)
print(nan == nan)
@@ -56,20 +61,22 @@ print(type(hash(1j)))
print(1.2 + 3j)
# negative base and fractional power should create a complex
-ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag))
-ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag))
+ans = (-1) ** 2.3
+print("%.5g %.5g" % (ans.real, ans.imag))
+ans = (-1.2) ** -3.4
+print("%.5g %.5g" % (ans.real, ans.imag))
# check printing of inf/nan
-print(float('nan') * 1j)
-print(float('-nan') * 1j)
-print(float('inf') * (1 + 1j))
-print(float('-inf') * (1 + 1j))
+print(float("nan") * 1j)
+print(float("-nan") * 1j)
+print(float("inf") * (1 + 1j))
+print(float("-inf") * (1 + 1j))
# can't assign to attributes
try:
(1j).imag = 0
except AttributeError:
- print('AttributeError')
+ print("AttributeError")
# can't convert rhs to complex
try:
@@ -95,11 +102,11 @@ try:
except TypeError:
print("TypeError")
-#small int on LHS, complex on RHS, unsupported op
+# small int on LHS, complex on RHS, unsupported op
try:
print(1 | 1j)
except TypeError:
- print('TypeError')
+ print("TypeError")
# zero division
try:
diff --git a/tests/float/complex1_intbig.py b/tests/float/complex1_intbig.py
index ed2390bba..864036b99 100644
--- a/tests/float/complex1_intbig.py
+++ b/tests/float/complex1_intbig.py
@@ -1,4 +1,5 @@
# test basic complex number functionality
# convert bignum to complex on rhs
-ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))
+ans = 1j + (1 << 70)
+print("%.5g %.5g" % (ans.real, ans.imag))
diff --git a/tests/float/float1.py b/tests/float/float1.py
index f6d69e390..efde5146b 100644
--- a/tests/float/float1.py
+++ b/tests/float/float1.py
@@ -1,11 +1,11 @@
# test basic float capabilities
# literals
-print(.12)
-print(1.)
+print(0.12)
+print(1.0)
print(1.2)
print(0e0)
-print(0e+0)
+print(0e0)
print(0e-0)
# float construction
@@ -68,7 +68,7 @@ print(0.0 == False, 1.0 == True)
print(False == 0.0, True == 1.0)
# comparison of nan is special
-nan = float('nan')
+nan = float("nan")
print(nan == 1.2)
print(nan == nan)
@@ -108,7 +108,7 @@ except TypeError:
try:
print(1 | 1.0)
except TypeError:
- print('TypeError')
+ print("TypeError")
# can't convert list to float
try:
diff --git a/tests/float/float2int_doubleprec_intbig.py b/tests/float/float2int_doubleprec_intbig.py
index de2137d66..24d30fe69 100644
--- a/tests/float/float2int_doubleprec_intbig.py
+++ b/tests/float/float2int_doubleprec_intbig.py
@@ -6,6 +6,7 @@ except:
import struct
import sys
+
maxsize_bits = 0
maxsize = sys.maxsize
while maxsize:
@@ -31,32 +32,33 @@ if ll_type is None:
# This case occurs with time.time() values
if ll_type != 0:
- print(int(1418774543.))
- print("%d" % 1418774543.)
+ print(int(1418774543.0))
+ print("%d" % 1418774543.0)
if ll_type == 3:
- print(int(2.**100))
- print("%d" % 2.**100)
+ print(int(2.0 ** 100))
+ print("%d" % 2.0 ** 100)
else:
- print(int(1073741823.))
- print("%d" % 1073741823.)
+ print(int(1073741823.0))
+ print("%d" % 1073741823.0)
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.**i))) - 3;
+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
if i != bitcnt:
- print('fail: 2**%u was %u bits long' % (i, bitcnt));
+ print("fail: 2**%u was %u bits long" % (i, bitcnt))
testpass = False
-print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
+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.**i))) - 1;
+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
if i != digcnt:
- print('fail: 10**%u was %u digits long' % (i, digcnt));
+ print("fail: 10**%u was %u digits long" % (i, digcnt))
testpass = False
-print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
+print("power of 10 test: %s" % (testpass and "passed" or "failed"))
+
def fp2int_test(num, name, should_fail):
try:
@@ -64,37 +66,38 @@ def fp2int_test(num, name, should_fail):
passed = ~should_fail
except:
passed = should_fail
- print('%s: %s' % (name, passed and 'passed' or 'failed'))
+ print("%s: %s" % (name, passed and "passed" or "failed"))
+
if ll_type != 2:
if ll_type == 0:
if is_64bit:
- neg_bad_fp = -1.00000005*2.**62.
- pos_bad_fp = 2.**62.
- neg_good_fp = -2.**62.
- pos_good_fp = 0.99999993*2.**62.
+ 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.**30.
- pos_bad_fp = 2.**30.
- neg_good_fp = -2.**30.
- pos_good_fp = 0.9999999499*2.**30.
+ 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.**64.
- pos_bad_fp = 2.**63.
- neg_good_fp = -2.**63.
- pos_good_fp = 1.9999998*2.**62.
+ 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)
+ 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.**1023., 'large neg', False)
- fp2int_test(1.9999999999999981*2.**1023., '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('nan'), 'NaN test', True)
+fp2int_test(float("inf"), "inf test", True)
+fp2int_test(float("nan"), "NaN test", True)
# test numbers < 1 (this used to fail; see issue #1044)
-fp2int_test(0.0001, 'small num', False)
-struct.pack('I', int(1/2))
+fp2int_test(0.0001, "small num", False)
+struct.pack("I", int(1 / 2))
diff --git a/tests/float/float2int_fp30_intbig.py b/tests/float/float2int_fp30_intbig.py
index fbb94a4cc..da3980040 100644
--- a/tests/float/float2int_fp30_intbig.py
+++ b/tests/float/float2int_fp30_intbig.py
@@ -6,6 +6,7 @@ except:
import struct
import sys
+
maxsize_bits = 0
maxsize = sys.maxsize
while maxsize:
@@ -30,30 +31,31 @@ if ll_type is None:
ll_type = 2
# basic conversion
-print(int(14187744.))
-print("%d" % 14187744.)
+print(int(14187744.0))
+print("%d" % 14187744.0)
if ll_type == 2:
- print(int(2.**100))
- print("%d" % 2.**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.**i))) - 3;
+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
if i != bitcnt:
- print('fail: 2.**%u was %u bits long' % (i, bitcnt));
+ print("fail: 2.**%u was %u bits long" % (i, bitcnt))
testpass = False
-print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
+print("power of 2 test: %s" % (testpass and "passed" or "failed"))
# TODO why does 10**12 fail this test for single precision float?
testpass = True
p10_rng = 9
-for i in range(0,p10_rng):
- digcnt = len(str(int(10.**i))) - 1;
+for i in range(0, p10_rng):
+ digcnt = len(str(int(10.0 ** i))) - 1
if i != digcnt:
- print('fail: 10.**%u was %u digits long' % (i, digcnt));
+ print("fail: 10.**%u was %u digits long" % (i, digcnt))
testpass = False
-print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
+print("power of 10 test: %s" % (testpass and "passed" or "failed"))
+
def fp2int_test(num, name, should_fail):
try:
@@ -61,37 +63,38 @@ def fp2int_test(num, name, should_fail):
passed = ~should_fail
except:
passed = should_fail
- print('%s: %s' % (name, passed and 'passed' or 'failed'))
+ print("%s: %s" % (name, passed and "passed" or "failed"))
+
if ll_type != 2:
if ll_type == 0:
if is_64bit:
- neg_bad_fp = -1.00000005*2.**62.
- pos_bad_fp = 2.**62.
- neg_good_fp = -2.**62.
- pos_good_fp = 0.99999993*2.**62.
+ 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.**30.
- pos_bad_fp = 2.**30.
- neg_good_fp = -2.**30.
- pos_good_fp = 0.9999999499*2.**30.
+ 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.**64.
- pos_bad_fp = 2.**63.
- neg_good_fp = -2.**63.
- pos_good_fp = 1.9999998*2.**62.
+ 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)
+ 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.**126., 'large neg', False)
- fp2int_test(1.999999879*2.**126., '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('nan'), 'NaN test', True)
+fp2int_test(float("inf"), "inf test", True)
+fp2int_test(float("nan"), "NaN test", True)
# test numbers < 1 (this used to fail; see issue #1044)
-fp2int_test(0.0001, 'small num', False)
-struct.pack('I', int(1/2))
+fp2int_test(0.0001, "small num", False)
+struct.pack("I", int(1 / 2))
diff --git a/tests/float/float2int_intbig.py b/tests/float/float2int_intbig.py
index 3596d2f73..62aca3963 100644
--- a/tests/float/float2int_intbig.py
+++ b/tests/float/float2int_intbig.py
@@ -32,30 +32,33 @@ if ll_type is None:
# basic conversion
+# fmt: off
print(int(14187745.))
print("%d" % 14187745.)
+# fmt: on
if ll_type == 2:
- print(int(2.**100))
- print("%d" % 2.**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.**i))) - 3;
+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
if i != bitcnt:
- print('fail: 2.**%u was %u bits long' % (i, bitcnt));
+ print("fail: 2.**%u was %u bits long" % (i, bitcnt))
testpass = False
-print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
+print("power of 2 test: %s" % (testpass and "passed" or "failed"))
# TODO why does 10**12 fail this test for single precision float?
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.**i))) - 1;
+for i in range(0, p10_rng):
+ digcnt = len(str(int(10.0 ** i))) - 1
if i != digcnt:
- print('fail: 10.**%u was %u digits long' % (i, digcnt));
+ print("fail: 10.**%u was %u digits long" % (i, digcnt))
testpass = False
-print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
+print("power of 10 test: %s" % (testpass and "passed" or "failed"))
+
def fp2int_test(num, name, should_fail):
try:
@@ -63,37 +66,38 @@ def fp2int_test(num, name, should_fail):
passed = ~should_fail
except:
passed = should_fail
- print('%s: %s' % (name, passed and 'passed' or 'failed'))
+ print("%s: %s" % (name, passed and "passed" or "failed"))
+
if ll_type != 2:
if ll_type == 0:
if is_64bit:
- neg_bad_fp = -1.00000005*2.**62.
- pos_bad_fp = 2.**62.
- neg_good_fp = -2.**62.
- pos_good_fp = 0.99999993*2.**62.
+ 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.**30.
- pos_bad_fp = 2.**30.
- neg_good_fp = -2.**30.
- pos_good_fp = 0.9999999499*2.**30.
+ 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.**64.
- pos_bad_fp = 2.**63.
- neg_good_fp = -2.**63.
- pos_good_fp = 1.9999998*2.**62.
+ 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)
+ 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.**127., 'large neg', False)
- fp2int_test(1.999999879*2.**127., '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)
+fp2int_test(float("inf"), "inf test", True)
+fp2int_test(float("nan"), "NaN test", True)
# test numbers < 1 (this used to fail; see issue #1044)
-fp2int_test(0.0001, 'small num', False)
-struct.pack('I', int(1/2))
+fp2int_test(0.0001, "small num", False)
+struct.pack("I", int(1 / 2))
diff --git a/tests/float/float_array.py b/tests/float/float_array.py
index 0c7f1b3ad..3c2189869 100644
--- a/tests/float/float_array.py
+++ b/tests/float/float_array.py
@@ -7,17 +7,19 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def test(a):
print(a)
a.append(1.2)
- print(len(a), '%.3f' % a[0])
+ print(len(a), "%.3f" % a[0])
a.append(1)
a.append(False)
- print(len(a), '%.3f %.3f' % (a[1], a[2]))
+ print(len(a), "%.3f %.3f" % (a[1], a[2]))
a[-1] = 3.45
- print('%.3f' % a[-1])
+ print("%.3f" % a[-1])
+
-test(array('f'))
-test(array('d'))
+test(array("f"))
+test(array("d"))
-print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0]))
+print("{:.4f}".format(array("f", b"\xcc\xcc\xcc=")[0]))
diff --git a/tests/float/float_compare.py b/tests/float/float_compare.py
index 105923ac7..c177aa7e8 100644
--- a/tests/float/float_compare.py
+++ b/tests/float/float_compare.py
@@ -1,8 +1,10 @@
# Extended float comparisons
+
class Foo:
pass
+
foo = Foo()
print(foo == 1.0)
diff --git a/tests/float/float_divmod.py b/tests/float/float_divmod.py
index 8e7cd435a..ec83ce2d1 100644
--- a/tests/float/float_divmod.py
+++ b/tests/float/float_divmod.py
@@ -1,11 +1,13 @@
# test floating point floor divide and modulus
# it has some tricky corner cases
+
def test(x, y):
div, mod = divmod(x, y)
- print('%.8f %.8f %.8f %.8f' % (x // y, x % y, div, mod))
+ print("%.8f %.8f %.8f %.8f" % (x // y, x % y, div, mod))
print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-15)
+
test(1.23456, 0.7)
test(-1.23456, 0.7)
test(1.23456, -0.7)
diff --git a/tests/float/float_divmod_relaxed.py b/tests/float/float_divmod_relaxed.py
index a9450fa2c..ef5a6ad2e 100644
--- a/tests/float/float_divmod_relaxed.py
+++ b/tests/float/float_divmod_relaxed.py
@@ -4,10 +4,12 @@
# pyboard has 32-bit floating point and gives different (but still
# correct) answers for certain combinations of divmod arguments.
+
def test(x, y):
div, mod = divmod(x, y)
print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-6)
+
test(1.23456, 0.7)
test(-1.23456, 0.7)
test(1.23456, -0.7)
@@ -30,4 +32,4 @@ for i in range(25):
try:
divmod(1.0, 0)
except ZeroDivisionError:
- print('ZeroDivisionError')
+ print("ZeroDivisionError")
diff --git a/tests/float/float_format.py b/tests/float/float_format.py
index d43535cf2..4c8a21756 100644
--- a/tests/float/float_format.py
+++ b/tests/float/float_format.py
@@ -2,18 +2,18 @@
# general rounding
for val in (116, 1111, 1234, 5010, 11111):
- print('%.0f' % val)
- print('%.1f' % val)
- print('%.3f' % val)
+ print("%.0f" % val)
+ print("%.1f" % val)
+ print("%.3f" % val)
# make sure rounding is done at the correct precision
for prec in range(8):
- print(('%%.%df' % prec) % 6e-5)
+ print(("%%.%df" % prec) % 6e-5)
# check certain cases that had a digit value of 10 render as a ":" character
-print('%.2e' % float('9' * 51 + 'e-39'))
-print('%.2e' % float('9' * 40 + 'e-21'))
+print("%.2e" % float("9" * 51 + "e-39"))
+print("%.2e" % float("9" * 40 + "e-21"))
# check a case that would render negative digit values, eg ")" characters
# the string is converted back to a float to check for no illegal characters
-float('%.23e' % 1e-80)
+float("%.23e" % 1e-80)
diff --git a/tests/float/float_parse.py b/tests/float/float_parse.py
index 4b5fc613d..de27c33e7 100644
--- a/tests/float/float_parse.py
+++ b/tests/float/float_parse.py
@@ -1,36 +1,36 @@
# test parsing of floats
-inf = float('inf')
+inf = float("inf")
# it shouldn't matter where the decimal point is if the exponent balances the value
-print(float('1234') - float('0.1234e4'))
-print(float('1.015625') - float('1015625e-6'))
+print(float("1234") - float("0.1234e4"))
+print(float("1.015625") - float("1015625e-6"))
# very large integer part with a very negative exponent should cancel out
-print('%.4e' % float('9' * 60 + 'e-60'))
-print('%.4e' % float('9' * 60 + 'e-40'))
+print("%.4e" % float("9" * 60 + "e-60"))
+print("%.4e" % float("9" * 60 + "e-40"))
# many fractional digits
-print(float('.' + '9' * 70))
-print(float('.' + '9' * 70 + 'e20'))
-print(float('.' + '9' * 70 + 'e-50') == float('1e-50'))
+print(float("." + "9" * 70))
+print(float("." + "9" * 70 + "e20"))
+print(float("." + "9" * 70 + "e-50") == float("1e-50"))
# tiny fraction with large exponent
-print(float('.' + '0' * 60 + '1e10') == float('1e-51'))
-print(float('.' + '0' * 60 + '9e25') == float('9e-36'))
-print(float('.' + '0' * 60 + '9e40') == float('9e-21'))
+print(float("." + "0" * 60 + "1e10") == float("1e-51"))
+print(float("." + "0" * 60 + "9e25") == float("9e-36"))
+print(float("." + "0" * 60 + "9e40") == float("9e-21"))
# ensure that accuracy is retained when value is close to a subnormal
-print(float('1.00000000000000000000e-37'))
-print(float('10.0000000000000000000e-38'))
-print(float('100.000000000000000000e-39'))
+print(float("1.00000000000000000000e-37"))
+print(float("10.0000000000000000000e-38"))
+print(float("100.000000000000000000e-39"))
# very large exponent literal
-print(float('1e4294967301'))
-print(float('1e-4294967301'))
-print(float('1e18446744073709551621'))
-print(float('1e-18446744073709551621'))
+print(float("1e4294967301"))
+print(float("1e-4294967301"))
+print(float("1e18446744073709551621"))
+print(float("1e-18446744073709551621"))
# check small decimals are as close to their true value as possible
for n in range(1, 10):
- print(float('0.%u' % n) == n / 10)
+ print(float("0.%u" % n) == n / 10)
diff --git a/tests/float/float_parse_doubleprec.py b/tests/float/float_parse_doubleprec.py
index dcc0dd592..81fcadcee 100644
--- a/tests/float/float_parse_doubleprec.py
+++ b/tests/float/float_parse_doubleprec.py
@@ -1,21 +1,21 @@
# test parsing of floats, requiring double-precision
# very large integer part with a very negative exponent should cancel out
-print(float('9' * 400 + 'e-100'))
-print(float('9' * 400 + 'e-200'))
-print(float('9' * 400 + 'e-400'))
+print(float("9" * 400 + "e-100"))
+print(float("9" * 400 + "e-200"))
+print(float("9" * 400 + "e-400"))
# many fractional digits
-print(float('.' + '9' * 400))
-print(float('.' + '9' * 400 + 'e100'))
-print(float('.' + '9' * 400 + 'e-100'))
+print(float("." + "9" * 400))
+print(float("." + "9" * 400 + "e100"))
+print(float("." + "9" * 400 + "e-100"))
# tiny fraction with large exponent
-print('%.14e' % float('.' + '0' * 400 + '9e100'))
-print('%.14e' % float('.' + '0' * 400 + '9e200'))
-print('%.14e' % float('.' + '0' * 400 + '9e400'))
+print("%.14e" % float("." + "0" * 400 + "9e100"))
+print("%.14e" % float("." + "0" * 400 + "9e200"))
+print("%.14e" % float("." + "0" * 400 + "9e400"))
# ensure that accuracy is retained when value is close to a subnormal
-print(float('1.00000000000000000000e-307'))
-print(float('10.0000000000000000000e-308'))
-print(float('100.000000000000000000e-309'))
+print(float("1.00000000000000000000e-307"))
+print(float("10.0000000000000000000e-308"))
+print(float("100.000000000000000000e-309"))
diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py
index c4c186b89..18893af0e 100644
--- a/tests/float/float_struct.py
+++ b/tests/float/float_struct.py
@@ -8,11 +8,10 @@ except ImportError:
print("SKIP")
raise SystemExit
-i = 1. + 1/2
+i = 1.0 + 1 / 2
# TODO: it looks like '=' format modifier is not yet supported
# for fmt in ('f', 'd', '>f', '>d', '<f', '<d', '=f', '=d'):
-for fmt in ('f', 'd', '>f', '>d', '<f', '<d'):
+for fmt in ("f", "d", ">f", ">d", "<f", "<d"):
x = struct.pack(fmt, i)
v = struct.unpack(fmt, x)[0]
- print('%2s: %.17f - %s' % (fmt, v, (i == v) and 'passed' or 'failed'))
-
+ print("%2s: %.17f - %s" % (fmt, v, (i == v) and "passed" or "failed"))
diff --git a/tests/float/int_power.py b/tests/float/int_power.py
index 649d4d415..ba79247a5 100644
--- a/tests/float/int_power.py
+++ b/tests/float/int_power.py
@@ -5,4 +5,4 @@ print(x ** -2)
x = 3
x **= -2
-print('%.5f' % x)
+print("%.5f" % x)
diff --git a/tests/float/math_domain.py b/tests/float/math_domain.py
index 0cf10fb2a..2d4670f75 100644
--- a/tests/float/math_domain.py
+++ b/tests/float/math_domain.py
@@ -6,46 +6,46 @@ except ImportError:
print("SKIP")
raise SystemExit
-inf = float('inf')
-nan = float('nan')
+inf = float("inf")
+nan = float("nan")
# single argument functions
for name, f, args in (
- ('fabs', math.fabs, ()),
- ('ceil', math.ceil, ()),
- ('floor', math.floor, ()),
- ('trunc', math.trunc, ()),
- ('sqrt', math.sqrt, (-1, 0)),
- ('exp', math.exp, ()),
- ('sin', math.sin, ()),
- ('cos', math.cos, ()),
- ('tan', math.tan, ()),
- ('asin', math.asin, (-1.1, 1, 1.1)),
- ('acos', math.acos, (-1.1, 1, 1.1)),
- ('atan', math.atan, ()),
- ('ldexp', lambda x: math.ldexp(x, 0), ()),
- ('radians', math.radians, ()),
- ('degrees', math.degrees, ()),
- ):
+ ("fabs", math.fabs, ()),
+ ("ceil", math.ceil, ()),
+ ("floor", math.floor, ()),
+ ("trunc", math.trunc, ()),
+ ("sqrt", math.sqrt, (-1, 0)),
+ ("exp", math.exp, ()),
+ ("sin", math.sin, ()),
+ ("cos", math.cos, ()),
+ ("tan", math.tan, ()),
+ ("asin", math.asin, (-1.1, 1, 1.1)),
+ ("acos", math.acos, (-1.1, 1, 1.1)),
+ ("atan", math.atan, ()),
+ ("ldexp", lambda x: math.ldexp(x, 0), ()),
+ ("radians", math.radians, ()),
+ ("degrees", math.degrees, ()),
+):
for x in args + (inf, nan):
try:
ans = f(x)
- print('%.4f' % ans)
+ print("%.4f" % ans)
except ValueError:
- print(name, 'ValueError')
+ print(name, "ValueError")
except OverflowError:
- print(name, 'OverflowError')
+ print(name, "OverflowError")
# double argument functions
for name, f, args in (
- ('pow', math.pow, ((0, 2), (-1, 2), (0, -1), (-1, 2.3))),
- ('fmod', math.fmod, ((1.2, inf), (1.2, 0), (inf, 1.2))),
- ('atan2', math.atan2, ((0, 0),)),
- ('copysign', math.copysign, ()),
- ):
+ ("pow", math.pow, ((0, 2), (-1, 2), (0, -1), (-1, 2.3))),
+ ("fmod", math.fmod, ((1.2, inf), (1.2, 0), (inf, 1.2))),
+ ("atan2", math.atan2, ((0, 0),)),
+ ("copysign", math.copysign, ()),
+):
for x in args + ((0, inf), (inf, 0), (inf, inf), (inf, nan), (nan, inf), (nan, nan)):
try:
ans = f(*x)
- print('%.4f' % ans)
+ print("%.4f" % ans)
except ValueError:
- print(name, 'ValueError')
+ print(name, "ValueError")
diff --git a/tests/float/math_domain_special.py b/tests/float/math_domain_special.py
index 5650c35fe..880594dce 100644
--- a/tests/float/math_domain_special.py
+++ b/tests/float/math_domain_special.py
@@ -2,35 +2,36 @@
try:
import math
+
math.erf
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
-inf = float('inf')
-nan = float('nan')
+inf = float("inf")
+nan = float("nan")
# single argument functions
for name, f, args in (
- ('expm1', math.exp, ()),
- ('log2', math.log2, (-1, 0)),
- ('log10', math.log10, (-1, 0)),
- ('sinh', math.sinh, ()),
- ('cosh', math.cosh, ()),
- ('tanh', math.tanh, ()),
- ('asinh', math.asinh, ()),
- ('acosh', math.acosh, (-1, 0.9, 1)),
- ('atanh', math.atanh, (-1, 1)),
- ('erf', math.erf, ()),
- ('erfc', math.erfc, ()),
- ('gamma', math.gamma, (-2, -1, 0, 1)),
- ('lgamma', math.lgamma, (-2, -1, 0, 1)),
- ):
+ ("expm1", math.exp, ()),
+ ("log2", math.log2, (-1, 0)),
+ ("log10", math.log10, (-1, 0)),
+ ("sinh", math.sinh, ()),
+ ("cosh", math.cosh, ()),
+ ("tanh", math.tanh, ()),
+ ("asinh", math.asinh, ()),
+ ("acosh", math.acosh, (-1, 0.9, 1)),
+ ("atanh", math.atanh, (-1, 1)),
+ ("erf", math.erf, ()),
+ ("erfc", math.erfc, ()),
+ ("gamma", math.gamma, (-2, -1, 0, 1)),
+ ("lgamma", math.lgamma, (-2, -1, 0, 1)),
+):
for x in args + (inf, -inf, nan):
try:
ans = f(x)
- print('%.4f' % ans)
+ print("%.4f" % ans)
except ValueError:
- print(name, 'ValueError')
+ print(name, "ValueError")
except OverflowError:
- print(name, 'OverflowError')
+ print(name, "OverflowError")
diff --git a/tests/float/math_factorial_intbig.py b/tests/float/math_factorial_intbig.py
index 19d853df2..a4694b3d6 100644
--- a/tests/float/math_factorial_intbig.py
+++ b/tests/float/math_factorial_intbig.py
@@ -1,14 +1,15 @@
try:
import math
+
math.factorial
except (ImportError, AttributeError):
- print('SKIP')
+ print("SKIP")
raise SystemExit
for fun in (math.factorial,):
for x in range(-1, 30):
try:
- print('%d' % fun(x))
+ print("%d" % fun(x))
except ValueError as e:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py
index 2835b9bfb..7b6bb8648 100644
--- a/tests/float/math_fun.py
+++ b/tests/float/math_fun.py
@@ -6,26 +6,36 @@ except ImportError:
print("SKIP")
raise SystemExit
-test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.]
-test_values_small = [-10., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 10.] # so we don't overflow 32-bit precision
-unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.]
-
-functions = [('sqrt', sqrt, test_values),
- ('exp', exp, test_values_small),
- ('log', log, test_values),
- ('cos', cos, test_values),
- ('sin', sin, test_values),
- ('tan', tan, test_values),
- ('acos', acos, unit_range_test_values),
- ('asin', asin, unit_range_test_values),
- ('atan', atan, test_values),
- ('ceil', ceil, test_values),
- ('fabs', fabs, test_values),
- ('floor', floor, test_values),
- ('trunc', trunc, test_values),
- ('radians', radians, test_values),
- ('degrees', degrees, test_values),
- ]
+test_values = [-100.0, -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.0]
+test_values_small = [
+ -10.0,
+ -1.23456,
+ -1,
+ -0.5,
+ 0.0,
+ 0.5,
+ 1.23456,
+ 10.0,
+] # so we don't overflow 32-bit precision
+unit_range_test_values = [-1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75, 1.0]
+
+functions = [
+ ("sqrt", sqrt, test_values),
+ ("exp", exp, test_values_small),
+ ("log", log, test_values),
+ ("cos", cos, test_values),
+ ("sin", sin, test_values),
+ ("tan", tan, test_values),
+ ("acos", acos, unit_range_test_values),
+ ("asin", asin, unit_range_test_values),
+ ("atan", atan, test_values),
+ ("ceil", ceil, test_values),
+ ("fabs", fabs, test_values),
+ ("floor", floor, test_values),
+ ("trunc", trunc, test_values),
+ ("radians", radians, test_values),
+ ("degrees", degrees, test_values),
+]
for function_name, function, test_vals in functions:
print(function_name)
@@ -35,9 +45,10 @@ for function_name, function, test_vals in functions:
except ValueError as e:
print(str(e))
-tuple_functions = [('frexp', frexp, test_values),
- ('modf', modf, test_values),
- ]
+tuple_functions = [
+ ("frexp", frexp, test_values),
+ ("modf", modf, test_values),
+]
for function_name, function, test_vals in tuple_functions:
print(function_name)
@@ -45,14 +56,31 @@ for function_name, function, test_vals in tuple_functions:
x, y = function(value)
print("{:.5g} {:.5g}".format(x, y))
-binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.),
- (-23., -42.), (1., 0.0), (1., -0.0)]),
- ('pow', pow, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
- ('atan2', atan2, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
- ('fmod', fmod, ((1., 1.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
- ('ldexp', ldexp, ((1., 0), (0., 1), (2., 2), (3., -2), (-3., -4),)),
- ('log', log, ((2., 2.), (3., 2.), (4., 5.), (0., 1.), (1., 0.), (-1., 1.), (1., -1.), (2., 1.))),
- ]
+binary_functions = [
+ (
+ "copysign",
+ copysign,
+ [(23.0, 42.0), (-23.0, 42.0), (23.0, -42.0), (-23.0, -42.0), (1.0, 0.0), (1.0, -0.0)],
+ ),
+ ("pow", pow, ((1.0, 0.0), (0.0, 1.0), (2.0, 0.5), (-3.0, 5.0), (-3.0, -4.0),)),
+ ("atan2", atan2, ((1.0, 0.0), (0.0, 1.0), (2.0, 0.5), (-3.0, 5.0), (-3.0, -4.0),)),
+ ("fmod", fmod, ((1.0, 1.0), (0.0, 1.0), (2.0, 0.5), (-3.0, 5.0), (-3.0, -4.0),)),
+ ("ldexp", ldexp, ((1.0, 0), (0.0, 1), (2.0, 2), (3.0, -2), (-3.0, -4),)),
+ (
+ "log",
+ log,
+ (
+ (2.0, 2.0),
+ (3.0, 2.0),
+ (4.0, 5.0),
+ (0.0, 1.0),
+ (1.0, 0.0),
+ (-1.0, 1.0),
+ (1.0, -1.0),
+ (2.0, 1.0),
+ ),
+ ),
+]
for function_name, function, test_vals in binary_functions:
print(function_name)
diff --git a/tests/float/math_fun_bool.py b/tests/float/math_fun_bool.py
index 30ab14a52..6e9af0dd3 100644
--- a/tests/float/math_fun_bool.py
+++ b/tests/float/math_fun_bool.py
@@ -6,8 +6,7 @@ except ImportError:
print("SKIP")
raise SystemExit
-test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'),
- -float('NaN'), -float('Inf')]
+test_values = [1, 0, -1, 1.0, 0.0, -1.0, float("NaN"), float("Inf"), -float("NaN"), -float("Inf")]
functions = [isfinite, isnan, isinf]
diff --git a/tests/float/math_fun_int.py b/tests/float/math_fun_int.py
index 5cadbb1e5..2cabad4e0 100644
--- a/tests/float/math_fun_int.py
+++ b/tests/float/math_fun_int.py
@@ -7,7 +7,7 @@ except ImportError:
raise SystemExit
for fun in (math.ceil, math.floor, math.trunc):
- for x in (-1.6, -0.2, 0, 0.6, 1.4, float('inf'), float('nan')):
+ for x in (-1.6, -0.2, 0, 0.6, 1.4, float("inf"), float("nan")):
try:
print(fun(x))
except (ValueError, OverflowError) as e:
diff --git a/tests/float/math_fun_intbig.py b/tests/float/math_fun_intbig.py
index 697ca7a6d..7169b8017 100644
--- a/tests/float/math_fun_intbig.py
+++ b/tests/float/math_fun_intbig.py
@@ -8,4 +8,4 @@ except ImportError:
for fun in (math.ceil, math.floor, math.trunc):
for x in (-1e25, 1e25):
- print('%.3g' % fun(x))
+ print("%.3g" % fun(x))
diff --git a/tests/float/math_fun_special.py b/tests/float/math_fun_special.py
index e676a6fc9..c101a7e50 100644
--- a/tests/float/math_fun_special.py
+++ b/tests/float/math_fun_special.py
@@ -2,28 +2,45 @@
try:
from math import *
+
erf
except (ImportError, NameError):
print("SKIP")
raise SystemExit
-test_values = [-8., -2.5, -1, -0.5, 0.0, 0.5, 2.5, 8.,]
-pos_test_values = [0.001, 0.1, 0.5, 1.0, 1.5, 10.,]
+test_values = [
+ -8.0,
+ -2.5,
+ -1,
+ -0.5,
+ 0.0,
+ 0.5,
+ 2.5,
+ 8.0,
+]
+pos_test_values = [
+ 0.001,
+ 0.1,
+ 0.5,
+ 1.0,
+ 1.5,
+ 10.0,
+]
functions = [
- ('expm1', expm1, test_values),
- ('log2', log2, test_values),
- ('log10', log10, test_values),
- ('cosh', cosh, test_values),
- ('sinh', sinh, test_values),
- ('tanh', tanh, [-1e6, -100] + test_values + [100, 1e6]),
- ('acosh', acosh, [1.0, 5.0, 1.0]),
- ('asinh', asinh, test_values),
- ('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]),
- ('erf', erf, test_values),
- ('erfc', erfc, test_values),
- ('gamma', gamma, pos_test_values),
- ('lgamma', lgamma, pos_test_values + [50., 100.,]),
+ ("expm1", expm1, test_values),
+ ("log2", log2, test_values),
+ ("log10", log10, test_values),
+ ("cosh", cosh, test_values),
+ ("sinh", sinh, test_values),
+ ("tanh", tanh, [-1e6, -100] + test_values + [100, 1e6]),
+ ("acosh", acosh, [1.0, 5.0, 1.0]),
+ ("asinh", asinh, test_values),
+ ("atanh", atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]),
+ ("erf", erf, test_values),
+ ("erfc", erfc, test_values),
+ ("gamma", gamma, pos_test_values),
+ ("lgamma", lgamma, pos_test_values + [50.0, 100.0,]),
]
for function_name, function, test_vals in functions:
diff --git a/tests/float/math_isclose.py b/tests/float/math_isclose.py
index 13dfff75f..ef3e20f4f 100644
--- a/tests/float/math_isclose.py
+++ b/tests/float/math_isclose.py
@@ -6,19 +6,22 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def test(a, b, **kwargs):
print(isclose(a, b, **kwargs))
+
def test_combinations(a, b, **kwargs):
test(a, a, **kwargs)
test(a, b, **kwargs)
test(b, a, **kwargs)
test(b, b, **kwargs)
+
# Special numbers
-test_combinations(float('nan'), 1)
-test_combinations(float('inf'), 1)
-test_combinations(float('-inf'), 1)
+test_combinations(float("nan"), 1)
+test_combinations(float("inf"), 1)
+test_combinations(float("-inf"), 1)
# Equality
test(1.0, 1.0, rel_tol=0.0, abs_tol=0.0)
@@ -40,8 +43,8 @@ test(0.0, 1e-10, abs_tol=0.0, rel_tol=0.1)
try:
isclose(0, 0, abs_tol=-1)
except ValueError:
- print('ValueError')
+ print("ValueError")
try:
isclose(0, 0, rel_tol=-1)
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/float/python36.py b/tests/float/python36.py
index 6e8fb1f21..9e64e7a06 100644
--- a/tests/float/python36.py
+++ b/tests/float/python36.py
@@ -2,9 +2,9 @@
# underscores in numeric literals
print(1_000.1_8)
-print('%.2g' % 1e1_2)
+print("%.2g" % 1e1_2)
# underscore supported by int/float constructors
-print(float('1_2_3'))
-print(float('1_2_3.4'))
-print('%.2g' % float('1e1_3'))
+print(float("1_2_3"))
+print(float("1_2_3.4"))
+print("%.2g" % float("1e1_3"))
diff --git a/tests/float/string_format.py b/tests/float/string_format.py
index 54f127077..13382b903 100644
--- a/tests/float/string_format.py
+++ b/tests/float/string_format.py
@@ -1,5 +1,6 @@
def test(fmt, *args):
- print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
+ print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<")
+
test("{:10.4}", 123.456)
test("{:10.4e}", 123.456)
@@ -24,21 +25,21 @@ test("{:06e}", float("inf"))
test("{:06e}", float("-inf"))
test("{:06e}", float("nan"))
-test('{:f}', False)
-test('{:f}', True)
+test("{:f}", False)
+test("{:f}", True)
# The following fails right now
-#test("{:10.1}", 0.0)
+# test("{:10.1}", 0.0)
print("%.0f" % (1.750000 % 0.08333333333))
# Below isn't compatible with single-precision float
-#print("%.1f" % (1.750000 % 0.08333333333))
-#print("%.2f" % (1.750000 % 0.08333333333))
-#print("%.12f" % (1.750000 % 0.08333333333))
+# print("%.1f" % (1.750000 % 0.08333333333))
+# print("%.2f" % (1.750000 % 0.08333333333))
+# print("%.12f" % (1.750000 % 0.08333333333))
# tests for errors in format string
try:
- '{:10.1b}'.format(0.0)
+ "{:10.1b}".format(0.0)
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/float/string_format2.py b/tests/float/string_format2.py
index 269023e7f..7a36f4d2f 100644
--- a/tests/float/string_format2.py
+++ b/tests/float/string_format2.py
@@ -3,15 +3,17 @@
full_tests = False
+
def test(fmt, *args):
- print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
+ print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<")
+
def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
- fmt = '{'
+ fmt = "{"
if conv:
- fmt += '!'
+ fmt += "!"
fmt += conv
- fmt += ':'
+ fmt += ":"
if alignment:
fmt += fill
fmt += alignment
@@ -19,88 +21,162 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
fmt += prefix
fmt += width
if precision:
- fmt += '.'
+ fmt += "."
fmt += precision
fmt += type
- fmt += '}'
- test(fmt, arg)
- if fill == '0' and alignment == '=':
- fmt = '{:'
+ fmt += "}"
+ test(fmt, arg)
+ if fill == "0" and alignment == "=":
+ fmt = "{:"
fmt += sign
fmt += prefix
fmt += width
if precision:
- fmt += '.'
+ fmt += "."
fmt += precision
fmt += type
- fmt += '}'
+ fmt += "}"
test(fmt, arg)
-eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0,
- -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10,
- 1e37, -1e37, 1e-37, -1e-37,
- 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0,
- 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8,
- -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0,
- -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8)
+
+eg_nums = (
+ 0.0,
+ -0.0,
+ 0.1,
+ 1.234,
+ 12.3459,
+ 1.23456789,
+ 123456789.0,
+ -0.0,
+ -0.1,
+ -1.234,
+ -12.3459,
+ 1e4,
+ 1e-4,
+ 1e5,
+ 1e-5,
+ 1e6,
+ 1e-6,
+ 1e10,
+ 1e37,
+ -1e37,
+ 1e-37,
+ -1e-37,
+ 1.23456e8,
+ 1.23456e7,
+ 1.23456e6,
+ 1.23456e5,
+ 1.23456e4,
+ 1.23456e3,
+ 1.23456e2,
+ 1.23456e1,
+ 1.23456e0,
+ 1.23456e-1,
+ 1.23456e-2,
+ 1.23456e-3,
+ 1.23456e-4,
+ 1.23456e-5,
+ 1.23456e-6,
+ 1.23456e-7,
+ 1.23456e-8,
+ -1.23456e8,
+ -1.23456e7,
+ -1.23456e6,
+ -1.23456e5,
+ -1.23456e4,
+ -1.23456e3,
+ -1.23456e2,
+ -1.23456e1,
+ -1.23456e0,
+ -1.23456e-1,
+ -1.23456e-2,
+ -1.23456e-3,
+ -1.23456e-4,
+ -1.23456e-5,
+ -1.23456e-6,
+ -1.23456e-7,
+ -1.23456e-8,
+)
if full_tests:
- for type in ('e', 'E', 'g', 'G', 'n'):
- for width in ('', '4', '6', '8', '10'):
- for alignment in ('', '<', '>', '=', '^'):
- for fill in ('', '@', '0', ' '):
- for sign in ('', '+', '-', ' '):
- for prec in ('', '1', '3', '6'):
+ for type in ("e", "E", "g", "G", "n"):
+ for width in ("", "4", "6", "8", "10"):
+ for alignment in ("", "<", ">", "=", "^"):
+ for fill in ("", "@", "0", " "):
+ for sign in ("", "+", "-", " "):
+ for prec in ("", "1", "3", "6"):
for num in eg_nums:
- test_fmt('', fill, alignment, sign, '', width, prec, type, num)
+ test_fmt("", fill, alignment, sign, "", width, prec, type, num)
# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
# rounds differently than print("%.3f", 1.2345);
-f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0,
- 0.0012, 0.0123, 0.1234, 1.23459, 12.3456,
- -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0,
- -0.0012, -0.0123, -0.1234, -1.23459, -12.3456)
+f_nums = (
+ 0.0,
+ -0.0,
+ 0.0001,
+ 0.001,
+ 0.01,
+ 0.1,
+ 1.0,
+ 10.0,
+ 0.0012,
+ 0.0123,
+ 0.1234,
+ 1.23459,
+ 12.3456,
+ -0.0001,
+ -0.001,
+ -0.01,
+ -0.1,
+ -1.0,
+ -10.0,
+ -0.0012,
+ -0.0123,
+ -0.1234,
+ -1.23459,
+ -12.3456,
+)
if full_tests:
- for type in ('f', 'F'):
- for width in ('', '4', '6', '8', '10'):
- for alignment in ('', '<', '>', '=', '^'):
- for fill in ('', ' ', '0', '@'):
- for sign in ('', '+', '-', ' '):
+ for type in ("f", "F"):
+ for width in ("", "4", "6", "8", "10"):
+ for alignment in ("", "<", ">", "=", "^"):
+ for fill in ("", " ", "0", "@"):
+ for sign in ("", "+", "-", " "):
# An empty precision defaults to 6, but when uPy is
# configured to use a float, we can only use a
# precision of 6 with numbers less than 10 and still
# get results that compare to CPython (which uses
# long doubles).
- for prec in ('1', '2', '3'):
+ for prec in ("1", "2", "3"):
for num in f_nums:
- test_fmt('', fill, alignment, sign, '', width, prec, type, num)
+ test_fmt("", fill, alignment, sign, "", width, prec, type, num)
for num in int_nums2:
- test_fmt('', fill, alignment, sign, '', width, '', type, num)
+ test_fmt("", fill, alignment, sign, "", width, "", type, num)
pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99)
pct_nums2 = (True, False, 1, 0, -1)
if full_tests:
- type = '%'
- for width in ('', '4', '6', '8', '10'):
- for alignment in ('', '<', '>', '=', '^'):
- for fill in ('', ' ', '0', '@'):
- for sign in ('', '+', '-', ' '):
+ type = "%"
+ for width in ("", "4", "6", "8", "10"):
+ for alignment in ("", "<", ">", "=", "^"):
+ for fill in ("", " ", "0", "@"):
+ for sign in ("", "+", "-", " "):
# An empty precision defaults to 6, but when uPy is
# configured to use a float, we can only use a
# precision of 6 with numbers less than 10 and still
# get results that compare to CPython (which uses
# long doubles).
- for prec in ('1', '2', '3'):
+ for prec in ("1", "2", "3"):
for num in pct_nums1:
- test_fmt('', fill, alignment, sign, '', width, prec, type, num)
+ test_fmt("", fill, alignment, sign, "", width, prec, type, num)
for num in pct_nums2:
- test_fmt('', fill, alignment, sign, '', width, '', type, num)
+ test_fmt("", fill, alignment, sign, "", width, "", type, num)
else:
for num in pct_nums1:
- test_fmt('', '', '', '', '', '', '1', '%', num)
+ test_fmt("", "", "", "", "", "", "1", "%", num)
# We don't currently test a type of '' with floats (see the detailed comment
# in objstr.c)
diff --git a/tests/float/string_format_fp30.py b/tests/float/string_format_fp30.py
index 77b2a5288..5f0b213da 100644
--- a/tests/float/string_format_fp30.py
+++ b/tests/float/string_format_fp30.py
@@ -1,11 +1,12 @@
def test(fmt, *args):
- print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
+ print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<")
+
test("{:10.4}", 123.456)
test("{:10.4e}", 123.456)
test("{:10.4e}", -123.456)
-#test("{:10.4f}", 123.456)
-#test("{:10.4f}", -123.456)
+# test("{:10.4f}", 123.456)
+# test("{:10.4f}", -123.456)
test("{:10.4g}", 123.456)
test("{:10.4g}", -123.456)
test("{:10.4n}", 123.456)
@@ -15,8 +16,8 @@ test("{:g}", 300)
test("{:10.4E}", 123.456)
test("{:10.4E}", -123.456)
-#test("{:10.4F}", 123.456)
-#test("{:10.4F}", -123.456)
+# test("{:10.4F}", 123.456)
+# test("{:10.4F}", -123.456)
test("{:10.4G}", 123.456)
test("{:10.4G}", -123.456)
@@ -25,17 +26,17 @@ test("{:06e}", float("-inf"))
test("{:06e}", float("nan"))
# The following fails right now
-#test("{:10.1}", 0.0)
+# test("{:10.1}", 0.0)
print("%.0f" % (1.750000 % 0.08333333333))
# Below isn't compatible with single-precision float
-#print("%.1f" % (1.750000 % 0.08333333333))
-#print("%.2f" % (1.750000 % 0.08333333333))
-#print("%.12f" % (1.750000 % 0.08333333333))
+# print("%.1f" % (1.750000 % 0.08333333333))
+# print("%.2f" % (1.750000 % 0.08333333333))
+# print("%.12f" % (1.750000 % 0.08333333333))
# tests for errors in format string
try:
- '{:10.1b}'.format(0.0)
+ "{:10.1b}".format(0.0)
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py
index aea534247..094461538 100644
--- a/tests/float/string_format_modulo.py
+++ b/tests/float/string_format_modulo.py
@@ -7,9 +7,9 @@ print("%u" % 1.0)
# these 3 have different behaviour in Python 3.x versions
# uPy raises a TypeError, following Python 3.5 (earlier versions don't)
-#print("%x" % 18.0)
-#print("%o" % 18.0)
-#print("%X" % 18.0)
+# print("%x" % 18.0)
+# print("%o" % 18.0)
+# print("%X" % 18.0)
print("%e" % 1.23456)
print("%E" % 1.23456)
@@ -22,28 +22,28 @@ print("%06e" % float("inf"))
print("%06e" % float("-inf"))
print("%06e" % float("nan"))
-print("%02.3d" % 123) # prec > width
-print("%+f %+f" % (1.23, -1.23)) # float sign
-print("% f % f" % (1.23, -1.23)) # float space sign
-print("%0f" % -1.23) # negative number with 0 padding
+print("%02.3d" % 123) # prec > width
+print("%+f %+f" % (1.23, -1.23)) # float sign
+print("% f % f" % (1.23, -1.23)) # float space sign
+print("%0f" % -1.23) # negative number with 0 padding
# numbers with large negative exponents
-print('%f' % 1e-10)
-print('%f' % 1e-20)
-print('%f' % 1e-50)
-print('%f' % 1e-100)
-print('%f' % 1e-300)
+print("%f" % 1e-10)
+print("%f" % 1e-20)
+print("%f" % 1e-50)
+print("%f" % 1e-100)
+print("%f" % 1e-300)
# large decimal precision should be truncated and not overflow buffer
# the output depends on the FP calculation so only first 2 digits are printed
# (the 'g' with small e are printed using 'f' style, so need to be checked)
-print(('%.40f' % 1e-300)[:2])
-print(('%.40g' % 1e-1)[:2])
-print(('%.40g' % 1e-2)[:2])
-print(('%.40g' % 1e-3)[:2])
-print(('%.40g' % 1e-4)[:2])
+print(("%.40f" % 1e-300)[:2])
+print(("%.40g" % 1e-1)[:2])
+print(("%.40g" % 1e-2)[:2])
+print(("%.40g" % 1e-3)[:2])
+print(("%.40g" % 1e-4)[:2])
-print("%.0g" % 1) # 0 precision 'g'
+print("%.0g" % 1) # 0 precision 'g'
-print('%.1e' % 9.99) # round up with positive exponent
-print('%.1e' % 0.999) # round up with negative exponent
+print("%.1e" % 9.99) # round up with positive exponent
+print("%.1e" % 0.999) # round up with negative exponent
diff --git a/tests/float/string_format_modulo2.py b/tests/float/string_format_modulo2.py
index f6b1ae537..b22021c5d 100644
--- a/tests/float/string_format_modulo2.py
+++ b/tests/float/string_format_modulo2.py
@@ -1,24 +1,26 @@
# test formatting floats with large precision, that it doesn't overflow the buffer
+
def test(num, num_str):
- if num == float('inf') or num == 0.0 and num_str != '0.0':
+ if num == float("inf") or num == 0.0 and num_str != "0.0":
# skip numbers that overflow or underflow the FP precision
return
- for kind in ('e', 'f', 'g'):
+ for kind in ("e", "f", "g"):
# check precision either side of the size of the buffer (32 bytes)
for prec in range(23, 36, 2):
- fmt = '%.' + '%d' % prec + kind
+ fmt = "%." + "%d" % prec + kind
s = fmt % num
check = abs(float(s) - num)
if num > 1:
check /= num
if check > 1e-6:
- print('FAIL', num_str, fmt, s, len(s), check)
+ print("FAIL", num_str, fmt, s, len(s), check)
+
# check pure zero
-test(0.0, '0.0')
+test(0.0, "0.0")
# check some powers of 10, making sure to include exponents with 3 digits
for e in range(-8, 8):
num = pow(10, e)
- test(num, '1e%d' % e)
+ test(num, "1e%d" % e)
diff --git a/tests/float/string_format_modulo2_intbig.py b/tests/float/string_format_modulo2_intbig.py
index 9992ba65d..8110bc7f6 100644
--- a/tests/float/string_format_modulo2_intbig.py
+++ b/tests/float/string_format_modulo2_intbig.py
@@ -1,21 +1,23 @@
# test formatting floats with large precision, that it doesn't overflow the buffer
+
def test(num, num_str):
- if num == float('inf') or num == 0.0 and num_str != '0.0':
+ if num == float("inf") or num == 0.0 and num_str != "0.0":
# skip numbers that overflow or underflow the FP precision
return
- for kind in ('e', 'f', 'g'):
+ for kind in ("e", "f", "g"):
# check precision either side of the size of the buffer (32 bytes)
for prec in range(23, 36, 2):
- fmt = '%.' + '%d' % prec + kind
+ fmt = "%." + "%d" % prec + kind
s = fmt % num
check = abs(float(s) - num)
if num > 1:
check /= num
if check > 1e-6:
- print('FAIL', num_str, fmt, s, len(s), check)
+ print("FAIL", num_str, fmt, s, len(s), check)
+
# check most powers of 10, making sure to include exponents with 3 digits
for e in range(-101, 102):
num = pow(10, e)
- test(num, '1e%d' % e)
+ test(num, "1e%d" % e)
diff --git a/tests/float/string_format_modulo3.py b/tests/float/string_format_modulo3.py
index 5d26f2575..f9d9c43cd 100644
--- a/tests/float/string_format_modulo3.py
+++ b/tests/float/string_format_modulo3.py
@@ -1,3 +1,3 @@
# uPy and CPython outputs differ for the following
-print("%.1g" % -9.9) # round up 'g' with '-' sign
-print("%.2g" % 99.9) # round up
+print("%.1g" % -9.9) # round up 'g' with '-' sign
+print("%.2g" % 99.9) # round up
diff --git a/tests/float/true_value.py b/tests/float/true_value.py
index df415f003..4c8d2e5c8 100644
--- a/tests/float/true_value.py
+++ b/tests/float/true_value.py
@@ -3,5 +3,5 @@
if not 0.0:
print("float 0")
-if not 0+0j:
+if not 0 + 0j:
print("complex 0")