summaryrefslogtreecommitdiff
path: root/py/objint.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-01-07 14:29:12 +0000
committerDamien George <damien.p.george@gmail.com>2016-01-07 14:29:12 +0000
commitd6b31e4578a9f7ed4f970774fe91eeb811b1d475 (patch)
tree9914e2aa40f688617b4f32073f4cca320eebe615 /py/objint.c
parent93b3726240ed50aa162d47519d38b1713f93298a (diff)
py: Change mp_obj_int_is_positive to more general mp_obj_int_sign.
This function returns the sign (-1, 0 or 1) of the integer object.
Diffstat (limited to 'py/objint.c')
-rw-r--r--py/objint.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/objint.c b/py/objint.c
index f3d699c45..db8eaa48d 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -259,8 +259,15 @@ char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size,
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
-bool mp_obj_int_is_positive(mp_obj_t self_in) {
- return mp_obj_get_int(self_in) >= 0;
+int mp_obj_int_sign(mp_obj_t self_in) {
+ mp_int_t val = mp_obj_get_int(self_in);
+ if (val < 0) {
+ return -1;
+ } else if (val > 0) {
+ return 1;
+ } else {
+ return 0;
+ }
}
// This must handle int and bool types, and must raise a