summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/objfloat.c3
-rw-r--r--tests/float/builtin_float_abs.py13
2 files changed, 14 insertions, 2 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 2ea9947fe2..4db1bb89e9 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -161,8 +161,7 @@ STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-val);
case MP_UNARY_OP_ABS: {
- // TODO check for NaN etc
- if (val < 0) {
+ if (signbit(val)) {
return mp_obj_new_float(-val);
} else {
return o_in;
diff --git a/tests/float/builtin_float_abs.py b/tests/float/builtin_float_abs.py
new file mode 100644
index 0000000000..c0935c6eec
--- /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)))