summaryrefslogtreecommitdiff
path: root/py/mpz.c
AgeCommit message (Collapse)Author
2016-05-09py/mpz: Fix mpn_div so that it doesn't modify memory of denominator.Damien George
Previous to this patch bignum division and modulo would temporarily modify the RHS argument to the operation (eg x/y would modify y), but on return the RHS would be restored to its original value. This is not allowed because arguments to binary operations are const, and in particular might live in ROM. The modification was to normalise the arg (and then unnormalise before returning), and this patch makes it so the normalisation is done on the fly and the arg is now accessed as read-only. This change doesn't increase the order complexity of the operation, and actually reduces code size.
2016-05-08py/mpz: Do Python style division/modulo within bignum divmod routine.Damien George
This patch consolidates the Python logic for division/modulo to one place within the bignum code.
2016-05-08py/mpz: Fix bug with overflowing C-shift in division routine.Damien George
When DIG_SIZE=32, a uint32_t is used to store limbs, and no normalisation is needed because the MSB is already set, then there will be left and right shifts (in C) by 32 of a 32-bit variable, leading to undefined behaviour. This patch fixes this bug.
2016-02-03py/mpz: Add commented-out mpz_pow3_inpl function, to compute (x**y)%z.Damien George
This function computes (x**y)%z in an efficient way. For large arguments this operation is otherwise not computable by doing x**y and then %z. It's currently not used, but is added in case it's useful one day.
2016-02-03py/mpz: Complete implementation of mpz_{and,or,xor} for negative args.Doug Currie
For these 3 bitwise operations there are now fast functions for positive-only arguments, and general functions for arbitrary sign arguments (the fast functions are the existing implementation). By default the fast functions are not used (to save space) and instead the general functions are used for all operations. Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive arguments.
2016-01-08py/mpz: Fix conversion of float to mpz so it works on big endian archs.Damien George
2015-11-22py/mpz: Normalize (remove leading zeros) xor operation result.Paul Sokolovsky
2015-10-01py/mpz: Fix bignum anding of large negative with smaller positive int.Damien George
2015-10-01py/mpz: Force rhs of mpz_shl_inpl/mpz_shr_inpl to be unsigned.Damien George
Python semantics are that rhs of shift must be non-negative, so there's no need to handle negative values in the underlying mpz implementation.
2015-10-01py/mpz: Raise NotImplError instead of failing assertion.Damien George
2015-04-25py: Fix handling of negative numbers in struct.pack of q/Q.Damien George
2015-04-25py: Support conversion of bignum to bytes.Damien George
This gets int.to_bytes working for bignum, and also struct.pack with 'q' and 'Q' args on 32-bit machines. Addresses issue #1155.
2015-04-22py/mpz.c: Fix bug with shl not truncating zero digits correctly.Damien George
2015-04-09py: Adjust some spaces in code style/format, purely for consistency.Damien George
2015-03-12py: Make some mpz functions static and remove unused ones.Damien George
2015-03-02py: Clean up and comment out unused functions in mpz.Damien George
2015-01-27py: Fix comparison of minus-zero long int.Damien George
2015-01-24py: Fix issue in mpz_set_from_float() when mp_int_t is larger than floatDavid Steinberg
2015-01-24py: Move mp_float_t related defines to misc.hDavid Steinberg
2015-01-20py, unix: Allow to compile with -Wunused-parameter.Damien George
See issue #699.
2015-01-16py, unix: Allow to compile with -Wsign-compare.Damien George
See issue #699.
2015-01-09py: Fix handling of "0" mpz in some functions.Damien George
2015-01-02py: Raise exception if trying to convert inf/nan to int.Damien George
2015-01-02py: Fix float to int conversion for large exponents.David Steinberg
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-31py: Fix rshift and not of zero/one edge cases in mpz.Damien George
Addresses issue #1027.
2014-10-30mpz: Fix 64bit msvc buildstijn
msvc does not treat 1L a 64bit integer hence all occurences of shifting it left or right result in undefined behaviour since the maximum allowed shift count for 32bit ints is 31. Forcing the correct type explicitely, stored in MPZ_LONG_1, solves this.
2014-10-03py: Convert [u]int to mp_[u]int_t where appropriate.Damien George
Addressing issue #50.
2014-09-10py: Enable struct/binary-helper to parse q and Q sized ints.Damien George
Addresses issue #848.
2014-09-06py: Make mpz able to use 16 bits per digit; and 32 on 64-bit arch.Damien George
Previously, mpz was restricted to using at most 15 bits in each digit, where a digit was a uint16_t. With this patch, mpz can use all 16 bits in the uint16_t (improvement to mpn_div was required). This gives small inprovements in speed and RAM usage. It also yields savings in ROM code size because all of the digit masking operations become no-ops. Also, mpz can now use a uint32_t as the digit type, and hence use 32 bits per digit. This will give decent improvements in mpz speed on 64-bit machines. Test for big integer division added.
2014-09-05py: Convert (u)int to mp_(u)int_t in mpz, and remove unused function.Damien George
2014-08-30py: Save about 200 bytes of ROM by using smaller type for static table.Damien George
2014-08-07py: Fix bug in mpn_shl (multi-prec int shift left).Damien George
Before this patch, eg, 1 << 75 (or any large multiple of 15) was setting the MSB in the digits, which is outside the valid range of DIG_MASK.
2014-07-31py: Improve handling of long-int overflow.Damien George
This removes mpz_as_int, since that was a terrible function (it implemented saturating conversion). Use mpz_as_int_checked and mpz_as_uint_checked. These now work correctly (they previously had wrong overflow checking, eg print(chr(10000000000000)) on 32-bit machine would incorrectly convert this large number to a small int).
2014-07-24py: Make long ints hashable.Damien George
Addresses issue #765.
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-21py: Include mpconfig.h before all other includes.Paul Sokolovsky
It defines types used by all other headers. Fixes #691.
2014-06-01Rename bultins config variables to MICROPY_PY_BUILTINS_*.Damien George
This renames: MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT See issue #35 for discussion.
2014-05-29py: Implement bignum '&' with negatives on lhs and rhs.Damien George
Needs proper coverage testing. Doesn't implement -ve & -ve. Addresses issue #611.
2014-05-13py: Improve mpz_and function.Damien George
This should now have correct (and optimal) behaviour.
2014-05-12py: Fix bug in mpz_and function.Damien George
Addresses issue #610.
2014-05-08Windows MSVC portstijn
Extend the windows port so it compiles with the toolchain from Visual Studio 2013
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-04-08py: Add comment mpz function, and free memory used for string printing.Damien George
2014-04-07Add string formatting support for longlong and mpz.Dave Hylands
2014-04-04py: Handle small int power overflow correctly.Damien George
2014-04-03py: More robust int conversion and overflow checking.Damien George
2014-03-23objint_mpz: Quick&dirty implementation of bitwise operations.Paul Sokolovsky
Made solely to unbreak int-long.py test which in turn uncovered thinko with implementation of inplace ops. On mpz level, bitwise ops implemented only for same-sign numbers, and are not efficient (unconditional calling of mpn_cmp() is apparently superfluous).
2014-03-12py: Fix some bugs in mpz; add mpz_from_ll and mpz_set_from_ll.Damien George
A couple of bugs in mpn_shl, and overflow bug in mpz_set_from_int.
2014-03-08py: Wrap mpz float functions in MICROPY_ENABLE_FLOAT.Damien George