summaryrefslogtreecommitdiff
path: root/tests/float
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2017-10-04 21:45:04 +0200
committerGlenn Ruben Bakke <glennbakke@gmail.com>2017-10-04 21:45:04 +0200
commitbcab2ba0a80297100919366add6bada140c6ed75 (patch)
tree5133218f4fc010d5688f006dbdd1e2f346a843f7 /tests/float
parent4468731e3d039a3f72ac25aa43e936cf5ebb3f78 (diff)
parentf869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c (diff)
ports/nrf: Upmerging port with upstream master
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/complex1.py9
-rw-r--r--tests/float/float1.py5
-rw-r--r--tests/float/float_compare.py22
3 files changed, 36 insertions, 0 deletions
diff --git a/tests/float/complex1.py b/tests/float/complex1.py
index a6038de04..854410545 100644
--- a/tests/float/complex1.py
+++ b/tests/float/complex1.py
@@ -37,6 +37,11 @@ ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
print(1j == 1)
print(1j == 1j)
+# comparison of nan is special
+nan = float('nan') * 1j
+print(nan == 1j)
+print(nan == nan)
+
# builtin abs
print(abs(1j))
print("%.5g" % abs(1j + 2))
@@ -48,6 +53,10 @@ print(type(hash(1j)))
# float on lhs should delegate to complex
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))
+
# check printing of inf/nan
print(float('nan') * 1j)
print(float('inf') * (1 + 1j))
diff --git a/tests/float/float1.py b/tests/float/float1.py
index 93f6f014c..137dacc23 100644
--- a/tests/float/float1.py
+++ b/tests/float/float1.py
@@ -60,6 +60,11 @@ print(1.2 <= -3.4)
print(1.2 >= 3.4)
print(1.2 >= -3.4)
+# comparison of nan is special
+nan = float('nan')
+print(nan == 1.2)
+print(nan == nan)
+
try:
1.0 / 0
except ZeroDivisionError:
diff --git a/tests/float/float_compare.py b/tests/float/float_compare.py
new file mode 100644
index 000000000..105923ac7
--- /dev/null
+++ b/tests/float/float_compare.py
@@ -0,0 +1,22 @@
+# Extended float comparisons
+
+class Foo:
+ pass
+
+foo = Foo()
+
+print(foo == 1.0)
+print(1.0 == foo)
+print(1.0 == Foo)
+print(1.0 == [])
+print(1.0 == {})
+
+try:
+ print(foo < 1.0)
+except TypeError:
+ print("TypeError")
+
+try:
+ print(1.0 < foo)
+except TypeError:
+ print("TypeError")