Commit Graph

76 Commits

Author SHA1 Message Date
Damien George 953074315e py: Enable struct/binary-helper to parse q and Q sized ints.
Addresses issue #848.
2014-09-10 22:10:33 +01:00
Damien George 9a21d2e070 py: Make mpz able to use 16 bits per digit; and 32 on 64-bit arch.
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-06 17:15:34 +01:00
Damien George afb1cf75dd py: Convert (u)int to mp_(u)int_t in mpz, and remove unused function. 2014-09-05 20:37:06 +01:00
Damien George 1c70cbf151 py: Save about 200 bytes of ROM by using smaller type for static table. 2014-08-30 00:38:16 +01:00
Damien George 5d9b816449 py: Fix bug in mpn_shl (multi-prec int shift left).
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-08-07 14:27:48 +00:00
Damien George c9aa58e638 py: Improve handling of long-int overflow.
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-31 13:41:43 +00:00
Damien George ffe911d228 py: Make long ints hashable.
Addresses issue #765.
2014-07-24 14:21:37 +01:00
Damien George 40f3c02682 Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50.
2014-07-03 13:25:24 +01:00
Paul Sokolovsky 59c675a64c py: Include mpconfig.h before all other includes.
It defines types used by all other headers.

Fixes #691.
2014-06-21 22:43:22 +03:00
Damien George fb510b3bf9 Rename bultins config variables to MICROPY_PY_BUILTINS_*.
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-06-01 13:32:54 +01:00
Damien George f55cf10101 py: Implement bignum '&' with negatives on lhs and rhs.
Needs proper coverage testing.  Doesn't implement -ve & -ve.
Addresses issue #611.
2014-05-29 15:01:49 +01:00
Damien George 51fab28e94 py: Improve mpz_and function.
This should now have correct (and optimal) behaviour.
2014-05-13 22:58:00 +01:00
Damien George 561e425903 py: Fix bug in mpz_and function.
Addresses issue #610.
2014-05-12 23:27:29 +01:00
stijn 01d6be4d51 Windows MSVC port
Extend the windows port so it compiles with the toolchain from Visual Studio 2013
2014-05-08 10:06:43 +02:00
Damien George 04b9147e15 Add license header to (almost) all files.
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-05-03 23:27:38 +01:00
Damien George eec91057b8 py: Add comment mpz function, and free memory used for string printing. 2014-04-08 23:11:00 +01:00
Dave Hylands c4029e5079 Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
Damien George 5bf565e353 py: Handle small int power overflow correctly. 2014-04-04 00:16:32 +01:00
Damien George 8270e3853d py: More robust int conversion and overflow checking. 2014-04-03 11:00:54 +00:00
Paul Sokolovsky 57207b8818 objint_mpz: Quick&dirty implementation of bitwise operations.
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-23 01:59:11 +02:00
Damien George bb4a43f35c py: Fix some bugs in mpz; add mpz_from_ll and mpz_set_from_ll.
A couple of bugs in mpn_shl, and overflow bug in mpz_set_from_int.
2014-03-12 15:36:06 +00:00
Damien George 5260810d70 py: Wrap mpz float functions in MICROPY_ENABLE_FLOAT. 2014-03-08 15:04:54 +00:00
Damien George 06201ff3d6 py: Implement bit-shift and not operations for mpz.
Implement not, shl and shr in mpz library.  Add function to create mpzs
on the stack, used for memory efficiency when rhs is a small int.
Factor out code to parse base-prefix of number into a dedicated function.
2014-03-01 19:50:50 +00:00
Damien George c5ac2ac590 py: Start to implement shl/shr for mpz. Fix return void. 2014-02-26 16:56:30 +00:00
Damien George aca141269e py: Fix mpn_sub, was increasing wrong source pointer.
Also change int -> machine_int_t where appropriate.
2014-02-24 21:32:52 +00:00
Damien George 438c88dd2f Add arbitrary precision integer support.
Some functionality is still missing (eg and, or, bit shift), and some
things are buggy (eg subtract).
2014-02-22 19:25:23 +00:00