summaryrefslogtreecommitdiff
path: root/tests/float/builtin_float_abs.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-09-27 15:21:25 +1000
committerDamien George <damien.p.george@gmail.com>2018-09-27 15:21:25 +1000
commitb3eadf3f3d0cfd4c56a519ae289288ee829229a5 (patch)
tree20e3c574c23d6a7676b2bca15b8aa03ee52fe5f4 /tests/float/builtin_float_abs.py
parent8960a2823800c4b699d319e63b7472b3628d7344 (diff)
py/objfloat: Fix abs(-0.0) so it returns 0.0.
Nan and inf (signed and unsigned) are also handled correctly by using signbit (they were also handled correctly with "val<0", but that didn't handle -0.0 correctly). A test case is added for this behaviour.
Diffstat (limited to 'tests/float/builtin_float_abs.py')
-rw-r--r--tests/float/builtin_float_abs.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/float/builtin_float_abs.py b/tests/float/builtin_float_abs.py
new file mode 100644
index 000000000..c0935c6ee
--- /dev/null
+++ b/tests/float/builtin_float_abs.py
@@ -0,0 +1,13 @@
+# test builtin abs function with float args
+
+for val in (
+ '1.0',
+ '-1.0',
+ '0.0',
+ '-0.0',
+ 'nan',
+ '-nan',
+ 'inf',
+ '-inf',
+ ):
+ print(val, abs(float(val)))