aboutsummaryrefslogtreecommitdiff
path: root/py/objfloat.c
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 /py/objfloat.c
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 'py/objfloat.c')
-rw-r--r--py/objfloat.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 2ea9947fe..4db1bb89e 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;