aboutsummaryrefslogtreecommitdiff
path: root/py/objint_mpz.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_mpz.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_mpz.c')
-rw-r--r--py/objint_mpz.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 385bbc5e3..249994877 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -113,12 +113,25 @@ void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, mp_uint_t len,
mpz_as_bytes(&self->mpz, big_endian, len, buf);
}
-bool mp_obj_int_is_positive(mp_obj_t self_in) {
+int mp_obj_int_sign(mp_obj_t self_in) {
if (MP_OBJ_IS_SMALL_INT(self_in)) {
- return MP_OBJ_SMALL_INT_VALUE(self_in) >= 0;
+ mp_int_t val = MP_OBJ_SMALL_INT_VALUE(self_in);
+ if (val < 0) {
+ return -1;
+ } else if (val > 0) {
+ return 1;
+ } else {
+ return 0;
+ }
}
mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
- return !self->mpz.neg;
+ if (self->mpz.len == 0) {
+ return 0;
+ } else if (self->mpz.neg == 0) {
+ return 1;
+ } else {
+ return -1;
+ }
}
// This must handle int and bool types, and must raise a