Commit Graph

72 Commits

Author SHA1 Message Date
Sergey B Kirpichev fb69943530 Use explicit kwargs in public API, where possible
Following functions kept:
```pycon
>>> import inspect
... with_args = []
... with_kwargs = []
... for n in dir(mpmath):
...     m = getattr(mpmath, n)
...     try:
...         s = inspect.signature(m)
...     except:
...         continue
...     if any(_.kind == inspect._ParameterKind.VAR_POSITIONAL for _ in s.parameters.values()):
...         for name in s.parameters:
...             if s.parameters[name].kind == inspect._ParameterKind.VAR_POSITIONAL and name == 'args':
...                 with_args.append(n)
...                 break
...     if any(_.kind == inspect._ParameterKind.VAR_KEYWORD for _ in s.parameters.values()):
...         with_kwargs.append(n)
... print(with_args)
... print(with_kwargs)
...
['arange', 'ellipe', 'ellippi', 'linspace', 'matrix', 'ones', 'timing', 'zeros']
['multiplicity', 'timing']
```

We need support for multiple signatures in the first case.  In the
second - it's impossible to implement these functions without kwargs.

Closes #1056
2026-08-04 06:40:53 +03:00
Sergey B Kirpichev 65dca57ca7 Use CoW pattern to manage constant_memo() cache
Closes #1135
2026-07-19 10:28:41 +03:00
Sergey B Kirpichev 6f1fbd275d Fix repr_dps() to produce a correct estimate
That should work at lest for 32-bit integers.  Though, I think that
the repr/str representation loses all sence for precisions much
less than that ;-)

Closes #1116
2026-07-01 05:36:13 +03:00
Sergey B Kirpichev 1d89343973 Add jacobi_symbol() to libintmath 2026-06-23 07:16:42 +03:00
Sergey B Kirpichev 0e1bd9496d Restrict libmp exports to public API
This is following namespace:
```
{'BACKEND', 'ComplexResult', 'MPZ', 'MPZ_ONE', 'NoConvergence',
 'catalan_fixed', 'dps_to_prec', 'euler_fixed', 'fhalf', 'finf',
 'fnan', 'fninf', 'fnone', 'fone', 'from_float', 'from_int', 'from_man_exp',
 'from_rational', 'from_str', 'fzero', 'giant_steps', 'ifac', 'ifib',
 'int_types', 'isqrt', 'mpc_abs', 'mpc_exp', 'mpc_pow', 'mpc_pow_int',
 'mpc_pow_mpf', 'mpc_sqrt', 'mpf_abs', 'mpf_add', 'mpf_atan', 'mpf_atan2',
 'mpf_bernoulli', 'mpf_ceil', 'mpf_cmp', 'mpf_cos', 'mpf_cosh_sinh', 'mpf_div',
 'mpf_e', 'mpf_eq', 'mpf_exp', 'mpf_floor', 'mpf_ge', 'mpf_gt', 'mpf_le',
 'mpf_log', 'mpf_lt', 'mpf_mod', 'mpf_mul', 'mpf_neg', 'mpf_pi', 'mpf_pow',
 'mpf_pow_int', 'mpf_shift', 'mpf_sign', 'mpf_sin', 'mpf_sqrt', 'mpf_sub',
 'mpf_tan', 'normalize', 'phi_fixed', 'prec_to_dps', 'repr_dps',
 'round_nearest', 'sqrtrem', 'to_float', 'to_int', 'to_man_exp', 'to_rational',
 'to_str'}
```

Closes #704
2026-05-25 08:31:19 +03:00
Sergey B Kirpichev 87cfbc42a8 Correct to_float() conversion for subnormals
Closes #1078
2026-05-18 07:46:12 +03:00
Sergey B Kirpichev 63304aee63 Add coverage test for _normalize (man == 1 and bc != 1 case) 2026-04-19 06:27:38 +03:00
Sergey B Kirpichev 893bb431aa Merge pull request #1057 from skirpichev/drop-deprecated1
Remove deprecated behavior
2026-03-07 04:18:42 +03:00
Sergey B Kirpichev c9c3946a9b Adapt test for a "wrong" tuple for mpf constructor 2026-03-07 03:39:34 +03:00
Sergey B Kirpichev 22bbe9ad4c Amend 5ac8dcda 2026-03-07 03:01:50 +03:00
Sergey B Kirpichev ca0f67d9ab Use signed=True per default in to_man_exp() 2026-03-04 07:28:50 +03:00
Sergey B Kirpichev 81204d1105 Drop deprecated to/from_pickable() functions 2026-03-04 07:28:50 +03:00
Sergey B Kirpichev 3ba4132a93 Drop deprecated mp.mpnumeric 2026-03-04 07:28:49 +03:00
Sergey B Kirpichev 485fe73586 Drop deprecated fp.is_special() 2026-03-04 07:28:49 +03:00
Sergey B Kirpichev 60de9789bf Keep forever deprecated aliases for mpc/mpf_log() 2026-03-04 07:28:49 +03:00
Sergey B Kirpichev cd25f9b536 Drop deprecated rational module 2026-03-04 07:28:49 +03:00
Sergey B Kirpichev 8f3e715b1e Drop deprecated math2 module 2026-03-04 07:28:49 +03:00
Sergey B Kirpichev 7cf16b7828 Revert "Add isspecial() method for mp/fp contexts, deprecate isnormal()"
This reverts commit e6aa3b46b1.

Subnormals are properly handled by fp.isnormal().  Deprecate
fp.is_special() method.

Fixes #946
2026-02-23 04:08:07 +03:00
Sergey B Kirpichev 8042d8eb95 Document support for free-threading builds
Closes #975
2025-09-01 05:24:36 +03:00
Sergey B Kirpichev 8870f1d258 Add aliases for mpf/mpc_log() as mpf/mpc_ln()
Closes #988
2025-08-06 06:02:12 +03:00
Sergey B Kirpichev b6af936582 Make mpc_hash() compatible with complex hash
Closes #985
2025-08-06 05:26:42 +03:00
Sergey B Kirpichev 9ad6a13925 Fix from_man_exp to correctly reject non-integral mantissa
This partially reverts 25506567
2025-06-09 05:21:57 +03:00
Sergey B Kirpichev 8b48864418 Fix mpf.__round__() to return int type per default (ndigits=None) 2025-06-03 11:24:13 +03:00
Sergey B Kirpichev 4582b13795 Support rounding property for the mp context 2025-06-01 13:28:51 +03:00
Sergey B Kirpichev e6aa3b46b1 Add isspecial() method for mp/fp contexts, deprecate isnormal()
Closes #946
2025-04-28 08:36:15 +03:00
Sergey B Kirpichev bd1584671c Speedup coverage tests (run less without gmpy2) 2025-01-30 04:48:20 +03:00
Sergey B Kirpichev 93c0647a8f Add special cases for infinities in mpc_*div()
Closes #805
2024-09-29 12:39:54 +03:00
Sergey B Kirpichev 51872ef8a4 Implement mpf.__floordiv__() and mpf.__divmod__()
Closes #333
2024-09-29 12:38:46 +03:00
Sergey B Kirpichev a545ecbd9e mpf.__round__() returns mpf
Probably this will look non-intuitive, but underlying floating-point
arithmetic is binary, not decimal.  Thus, round(x, n) sometimes will pick
up a decimal representation with more than n digits.  This is something
common for CPython < 2.7 and < 3.1:

    Python 2.6.6 (r266:84292, Aug 12 2014, 07:57:07)
    [GCC 4.4.5] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> round(0.42754287856598971, 2)
    0.42999999999999999

And with this patch as well:

    Python 3.12.5+ (heads/3.12:0181aa2e3e, Aug 29 2024, 14:55:08) [GCC 12.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from mpmath import *
    >>> round(mp.mpf(0.42754287856598971), 2)
    mpf('0.42999999999999999')
    >>> mp.pretty = True
    >>> round(mp.mpf(0.42754287856598971), 2)
    0.43

See also python/cpython#45921

Closes #455
2024-09-07 07:32:59 +03:00
Sergey B Kirpichev bb0fad9476 Improve test coverage for rational.py and calculus/approximation.py 2024-05-06 06:44:23 +03:00
Sergey B Kirpichev 2beeee2a9d Support inf/nan's in ctx.almosteq()
Closes #799
2024-05-02 10:22:51 +03:00
Sergey B Kirpichev b62a2a9523 Add DeprecationWarning for mpmath.math2 2024-04-16 12:18:03 +03:00
Sergey B Kirpichev 1d6d240e04 Restore to/from_pickable() helper functions 2024-04-16 12:18:01 +03:00
Sergey B Kirpichev 6111ee9d12 Restore minimal compatibility wrapper for mpmath.rational.mpq
See sympy/sympy#26269 and sympy/sympy#26273
2024-04-16 12:16:35 +03:00
Sergey B Kirpichev 610fbeda33 Add signed option to to_man_exp()
Returning unsigned mantissa value per default is deprecated.
2024-04-16 09:00:58 +03:00
Sergey B Kirpichev b5bd545a09 Don't unpack mpf tuples directly in ctx_mp*.py 2024-04-16 09:00:39 +03:00
Sergey B Kirpichev cc47ca13d4 Improve coverage 2024-04-05 11:50:03 +03:00
Sergey B Kirpichev 10ca54e9e1 Add base kwarg for the mpf constructor 2024-02-25 10:47:45 +03:00
Sergey B Kirpichev 5dd8c4eb35 Support mpc initialization from string
Closes #260
2023-12-21 05:16:25 +03:00
Sergey B Kirpichev 00e540c2b0 Support construction of mpf from Decimal objects 2023-10-19 09:01:28 +03:00
Sergey B Kirpichev 5c9f270717 Add mpf.as_integer_ratio() method
Closes #417.  I think we can't do better: e.g. if we provide
the mpf._mpfr_ property - then in expressions like mpq(1,2)+mpf(1.0) -
second operand (and the whole expression) will be promoted to mpfr.

Also this corrects to_rational() private function to return a pair of
integers with same type.
2023-10-18 15:35:00 +03:00
Sergey B Kirpichev f6bda7d30c Fix disagreement fp.pow vs mp.pow
Handle special values as in the ISO C99 and IEEE 754 standards
for the pow function.

Closes #523
Closes #512
2023-10-18 15:34:25 +03:00
Sergey B Kirpichev 19f96fa5ae Fix mpc() constructor to be compatible with complex()
Closes #730
2023-10-18 15:34:25 +03:00
Sergey B Kirpichev 90446b3dd4 Fix disagreement fp.mod vs mp.mod
Special values are handled as described in Section F.9.7.1 of the ISO
C99 standard, see
https://www.mpfr.org/mpfr-current/mpfr.html#index-mpfr_005ffmod
or
https://en.cppreference.com/w/c/numeric/math/fmod

Closes #490
2023-06-26 07:45:23 +03:00
Maximilian Gaukler 4bad21dd3e Support randmatrix() for mp.iv and mp contexts
To make this work correctly, rand() now supports arbitrary precision:

>>> x = mpmath.iv.rand() * mpmath.iv.convert(2**53)
>>> x - int(x)
mpi('0.0', '0.0')
>>> mpmath.iv.prec=1234
>>> x = mpmath.iv.rand() * mpmath.iv.convert(2**53)
>>> x - int(x)
mpi('0.05786680052076454587 ...
2023-06-10 22:08:10 +02:00
Sergey B Kirpichev db7373c54b Add legacy import of private mpnumeric class to the ctx_mp module
Address #704
2023-06-03 14:33:49 +03:00
Sergey B Kirpichev 4c5f0e47ac Merge branch 'master' into no-meta-in-_mpf 2023-05-21 06:50:02 +03:00
Sergey B Kirpichev f07b155ea0 100% test coverage for patch, simplify _mpf.__mod__() 2023-05-21 06:49:17 +03:00
Sergey B Kirpichev 0efdfeb7cd Drop ctx._mpq 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev ef8e49a2b5 ctx.mpq -> ctx._mpq 2023-05-19 07:03:11 +03:00