38 Commits

Author SHA1 Message Date
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 8a965fe43b Speedup removal trailing zeros in _normalize/from_man_exp()
| Benchmark      | ref     | patch                   |
|----------------|:-------:|:-----------------------:|
| 2              | 404 ns  | 398 ns: 1.01x faster    |
| 2**3           | 403 ns  | 398 ns: 1.01x faster    |
| 2**10          | 1.96 us | 1.91 us: 1.03x faster   |
| 2**100         | 6.21 us | 2.52 us: 2.47x faster   |
| 2**10000       | 1.04 ms | 5.90 us: 175.48x faster |
| Geometric mean | (ref)   | 2.78x faster            |

Benchmark hidden because not significant (1): 2**10000 + 1

$ cat bench.py
import pyperf
from mpmath.libmp import from_int
runner = pyperf.Runner()
for s in ['2', '2**3', '2**10', '2**100',
          '2**10000', '2**10000 + 1']:
    i = eval(s)
    runner.bench_func(s, from_int, i)

Closes #1073

Co-authored-by: Fredrik Johansson <fredrik.johansson@gmail.com>
2026-04-19 06:27:32 +03:00
Sergey B Kirpichev 81204d1105 Drop deprecated to/from_pickable() functions 2026-03-04 07:28:50 +03:00
Sergey B Kirpichev 754c073e7d Drop deprecated bitcount() function 2026-03-04 07:28:49 +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 15238878b8 Remove remnants of fnzero 2024-09-16 07:01:09 +03:00
Sergey B Kirpichev 4669219ed1 Add mpc.__format__()
Closes #846
2024-09-09 05:39:14 +03:00
Javier Garcia cead3b2bf9 Implement mpf.__format__ (#819)
Implemented the `__format__` method for the `_mpf` type.

Currently, `f`, `F`, `g`, `G`, `e`, and `E` formats are implemented, following the same specifications as specified for regular floats [here](https://docs.python.org/3/library/string.html#formatspec).  Only nearest rounding is implemented.

A partial fix for #337.
2024-07-24 19:37:04 +03:00
Sergey B Kirpichev fdb8bc09f4 Add mpc_mpf_sub() 2024-06-05 10:40:32 +03:00
Sergey B Kirpichev ef62c29e1f Drop unused helper mpc_mul_imag_mpf() 2024-04-27 05:58:38 +03:00
Sergey B Kirpichev 1d6d240e04 Restore to/from_pickable() helper functions 2024-04-16 12:18:01 +03:00
Sergey B Kirpichev c0d694d66b Drop libmp.math_float_inf 2024-04-05 11:50:03 +03:00
Sergey B Kirpichev 2a52f5a59a Drop libmp.HASH_BITS 2024-04-05 11:50:02 +03:00
Sergey B Kirpichev ab17cd8856 Drop libmp.HASH_MODULUS 2024-04-05 11:50:02 +03:00
Sergey B Kirpichev 25d326c95a Use asserts in normalize(), drop MPMATH_STRICT
For production code this could be removed by -O optimization.
2024-02-24 06:28:44 +03:00
Sergey B Kirpichev 89d106ab23 Remove sage backend
Closes #705
Closes #574
2023-10-19 05:32:39 +03:00
Sergey B Kirpichev 59d433236a Add giant_steps() to libmp (SymPy import this function) 2023-09-25 05:43:43 +03:00
Sergey B Kirpichev 48eef31f0b Drop to_pickable()/from_pickable() helpers
Without gmpy2:
    >>> import mpmath, pickle
    >>> pi = mpmath.pi
    >>> mpmath.mp.dps=100
    >>> a = mpmath.mpf(pi)
    >>> len(pickle.dumps(a))  # vs 147
    105

Fixes #440
2023-09-05 06:15:33 +03:00
Sergey B Kirpichev 560f81e5db Support base kwarg for from_str()
base=2**n and base=10 are supported so far.  float(), float.fromhex()
and MPFR's style (see mpfr_strtofr() function) string formats are
accepted.  to/from_bstr() undocumented helper functions were removed.

Partially taken from #414.

Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
2023-06-03 14:33:48 +03:00
Sergey B Kirpichev 721e2571eb Drop private mpq class, use Rational's provided by backend 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev a482c223f2 Drop normalize1(), as for non-python backends 2023-05-19 05:57:11 +03:00
Sergey B Kirpichev fb7ff23c52 Drop workaround for old gmpy2<2.1.0a1 (mpz was a factory function) 2023-04-30 08:53:44 +03:00
fredrik 474b987c19 remove old (unused) gamma function code 2019-02-03 14:37:33 +01:00
Jonathan Warner d2f54a3efb Improved numpy support
numpy numeric types now work with convert.
Also added support for Fraction and Decimal types.
Added a test and tested on Python 2.7 and 3.5.
Response to issue fredrik-johansson#382
2018-10-18 01:51:53 -06:00
Fredrik Johansson b597356632 some basic code for Stirling numbers 2012-12-30 22:54:54 +01:00
Case Van Horsen d3ca406a6f Changes to support the new hashing algorithm in Python 3.2 2011-01-16 21:41:24 +00:00
Fredrik Johansson b8651c00f1 switch to using explicit relative imports (Python 2.4 compatibility henceforth abandoned) 2011-01-08 22:15:29 +00:00
Fredrik Johansson 96be7c17be implement the von Mangoldt function 2010-10-30 20:43:38 +00:00
Fredrik Johansson 16ae718cc7 preliminary gamma/loggamma/rgamma/factorial for real and complex intervals (needs more work and tests) 2010-06-09 15:30:29 +00:00
Fredrik Johansson 9b4ad11e7b add complex interval cos/sin; compute z^n for complex interval z using binary exponentiation 2010-06-02 14:51:12 +00:00
Fredrik Johansson 24ef677de7 Upgrade interval arithmetic.
* Move everything interval to a separate context (e.g. iv.exp must be used instead of mp.exp)
* Support both real and complex intervals (iv.mpf, iv.mpc)
* Fix interval cos/sin, and remove the old mpf_cos_sin code it depended on. The new interval cos/sin is a bit slower at low precision now, but this can be fixed.
* Implement interval atan2, and exp/log/power for complex intervals
* Move interval<->string code to libmpi
* Some other interface changes

More tests are still needed, and interface/utility functions needs more work.
2010-04-14 15:12:10 +00:00
Fredrik Johansson fddf6fa89e improve utility functions
* optimize and improve documentation for floor, ceil, isinf, isnan, isint
* implement nint, frac, isnormal
* fix and document semantics for isinf, isnan, etc
* extend documentation for mag and nint_distance
* add more tests; move tests for utility functions from test_mpmath.py to test_basic_ops.py
2010-03-23 15:20:12 +00:00
Fredrik Johansson 74bb5db556 New gamma function implementation (using Stirling's series and Taylor series instead of Spouge's approximation); including direct support for loggamma and rgamma (reciprocal gamma function). Including also a large set of extra stress tests for gamma. 2010-02-11 22:07:04 +00:00
Fredrik Johansson 19c1c44d04 provide cos_sin and cospi_sinpi for faster simultaneous computation; use these in various places 2010-02-05 22:15:31 +00:00
Fredrik Johansson 6df47e5c63 export bin_to_radix in libmp since it's used in one of the demo scripts 2010-01-17 20:39:28 +00:00
Fredrik Johansson b61e326f76 Contributed by Juan Arias de Reyna <arias@us.es>: a new module rszeta for rapid evaluation of the Riemann zeta and Z functions at large heights using the Riemann-Siegel expansion 2010-01-17 17:25:23 +00:00
Fredrik Johansson 3710518085 some internal renaming 2010-01-12 20:21:08 +00:00
Fredrik Johansson 2413d1a18b moving modules to subdirectories: mpmath/libmp, mpmath/calculus, mpmath/functions 2010-01-12 18:19:42 +00:00