summaryrefslogtreecommitdiff
path: root/py/mpz.c
AgeCommit message (Collapse)Author
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-07-25py: Implement raising a big-int to a negative power.Damien George
Before this patch raising a big-int to a negative power would just return 0. Now it returns a floating-point number with the correct value.
2017-07-25py/mpz: Make mpz_is_zero() an inline function.Damien George
It's more efficient as an inline function, and saves code size.
2017-04-25py/mpz: In mpn_sub, use existing function to remove trailing zeros.Damien George
2017-04-25py/mpz: Strip trailing zeros from mpz value when set from bytes.Damien George
2017-02-16py/mpz: Change type of "base" args from mp_uint_t to unsigned int.Damien George
2017-02-16py/mpz: Remove obsolete declaration of mpz_as_str_size.Damien George
2017-02-16py/mpz: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-02py: Added optimised support for 3-argument calls to builtin.pow()Nicko van Someren
Updated modbuiltin.c to add conditional support for 3-arg calls to pow() using MICROPY_PY_BUILTINS_POW3 config parameter. Added support in objint_mpz.c for for optimised implementation.
2017-01-21py/mpz: Implement mpz_set_from_bytes() as a foundation for int.from_bytes().Paul Sokolovsky
2016-12-28py/mpz: Fix assertion in mpz_set_from_str which checks value of base.Damien George
2016-12-14py/mpz: Remove unreachable code in mpn_or_neg functions.Damien George
2016-10-31py: fix null pointer dereference in mpz.c, fix missing va_end in warning.cPavol Rusnak
2016-10-11py: Factor duplicated function to calculate size of formatted int.Damien George
2016-10-11py/mpz: Use assert to verify mpz does not have a fixed digit buffer.Damien George
2016-10-11py/mpz: In divmod, replace check for rhs!=0 with assert.Damien George
The check for division by zero is made by the caller of this function.
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).