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
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
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
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.
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 ...