diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-04 11:13:51 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-04 11:13:51 +0000 |
commit | ecf5b771230ef747773aa54960ebc2a46902a0ed (patch) | |
tree | 904c8ff0678ca81906bb871aa9375954cc2c338c /py/intdivmod.c | |
parent | 6902eeda259a5ed8fe3a5ce5cb19ba9207549d33 (diff) | |
download | micropython-ecf5b771230ef747773aa54960ebc2a46902a0ed.tar.gz micropython-ecf5b771230ef747773aa54960ebc2a46902a0ed.zip |
py: This time, real proper overflow checking of small int power.
Previous overflow test was inadequate.
Diffstat (limited to 'py/intdivmod.c')
-rw-r--r-- | py/intdivmod.c | 24 |
1 files changed, 0 insertions, 24 deletions
diff --git a/py/intdivmod.c b/py/intdivmod.c deleted file mode 100644 index 4cb363b511..0000000000 --- a/py/intdivmod.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "mpconfig.h" - -machine_int_t python_modulo(machine_int_t dividend, machine_int_t divisor) { - machine_int_t lsign = (dividend >= 0) ? 1 :-1; - machine_int_t rsign = (divisor >= 0) ? 1 :-1; - dividend %= divisor; - if (lsign != rsign) { - dividend += divisor; - } - return dividend; -} - - -machine_int_t python_floor_divide(machine_int_t num, machine_int_t denom) { - machine_int_t lsign = num > 0 ? 1 : -1; - machine_int_t rsign = denom > 0 ? 1 : -1; - if (lsign == -1) {num *= -1;} - if (rsign == -1) {denom *= -1;} - if (lsign != rsign){ - return - ( num + denom - 1) / denom; - } else { - return num / denom; - } -} |