summaryrefslogtreecommitdiff
path: root/tests/float
diff options
context:
space:
mode:
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/builtin_float_hash.py3
-rw-r--r--tests/float/builtin_float_pow.py11
-rw-r--r--tests/float/float1.py4
-rw-r--r--tests/float/float_format.py19
-rw-r--r--tests/float/float_parse.py32
-rw-r--r--tests/float/float_parse_doubleprec.py21
-rw-r--r--tests/float/python36.py10
-rw-r--r--tests/float/python36.py.exp5
8 files changed, 105 insertions, 0 deletions
diff --git a/tests/float/builtin_float_hash.py b/tests/float/builtin_float_hash.py
index ba6b63907..7a7e37401 100644
--- a/tests/float/builtin_float_hash.py
+++ b/tests/float/builtin_float_hash.py
@@ -3,6 +3,7 @@
# these should hash to an integer with a specific value
for val in (
'0.0',
+ '-0.0',
'1.0',
'2.0',
'-12.0',
@@ -15,6 +16,8 @@ for val in (
'0.1',
'-0.1',
'10.3',
+ '0.4e3',
+ '1e16',
'inf',
'-inf',
'nan',
diff --git a/tests/float/builtin_float_pow.py b/tests/float/builtin_float_pow.py
new file mode 100644
index 000000000..2de1b4817
--- /dev/null
+++ b/tests/float/builtin_float_pow.py
@@ -0,0 +1,11 @@
+# test builtin pow function with float args
+
+print(pow(0.0, 0.0))
+print(pow(0, 1.0))
+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')))
diff --git a/tests/float/float1.py b/tests/float/float1.py
index c64f965a7..54807e5ac 100644
--- a/tests/float/float1.py
+++ b/tests/float/float1.py
@@ -36,6 +36,10 @@ try:
except ValueError:
print("ValueError")
+# construct from something with the buffer protocol
+print(float(b"1.2"))
+print(float(bytearray(b"3.4")))
+
# unary operators
print(bool(0.0))
print(bool(1.2))
diff --git a/tests/float/float_format.py b/tests/float/float_format.py
new file mode 100644
index 000000000..d43535cf2
--- /dev/null
+++ b/tests/float/float_format.py
@@ -0,0 +1,19 @@
+# test float formatting
+
+# general rounding
+for val in (116, 1111, 1234, 5010, 11111):
+ 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)
+
+# 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'))
+
+# 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)
diff --git a/tests/float/float_parse.py b/tests/float/float_parse.py
new file mode 100644
index 000000000..4b026de1c
--- /dev/null
+++ b/tests/float/float_parse.py
@@ -0,0 +1,32 @@
+# test parsing of floats
+
+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'))
+
+# 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'))
+
+# many fractional digits
+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'))
+
+# 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'))
+
+# very large exponent literal
+print(float('1e4294967301'))
+print(float('1e-4294967301'))
+print(float('1e18446744073709551621'))
+print(float('1e-18446744073709551621'))
diff --git a/tests/float/float_parse_doubleprec.py b/tests/float/float_parse_doubleprec.py
new file mode 100644
index 000000000..dcc0dd592
--- /dev/null
+++ b/tests/float/float_parse_doubleprec.py
@@ -0,0 +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'))
+
+# many fractional digits
+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'))
+
+# 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'))
diff --git a/tests/float/python36.py b/tests/float/python36.py
new file mode 100644
index 000000000..6e8fb1f21
--- /dev/null
+++ b/tests/float/python36.py
@@ -0,0 +1,10 @@
+# tests for things that only Python 3.6 supports, needing floats
+
+# underscores in numeric literals
+print(1_000.1_8)
+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'))
diff --git a/tests/float/python36.py.exp b/tests/float/python36.py.exp
new file mode 100644
index 000000000..3febfed9a
--- /dev/null
+++ b/tests/float/python36.py.exp
@@ -0,0 +1,5 @@
+1000.18
+1e+12
+123.0
+123.4
+1e+13