JensGrabner / mpmath-2

Automatically exported from code.google.com/p/mpmath
Other
3 stars 0 forks source link

mpi for huge numbers #74

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
>>> sin(10**100)
mpf('-0.37237612366127668826218')
>>> sin(mpi(10**100))
[-1.0, 1.0]
>>> mp.dps = 1000
>>> sin(10**100)
mpf('-0.372376123[...]')
>>> sin(mpi(10**100))
[-0.3723761236[...], -0.37237612366[...]]

Is the error really so huge and sin(10**100) completely wrong? It does not
seem so.

Original issue reported on code.google.com by Vinzent.Steinberg@gmail.com on 4 Oct 2008 at 1:21

GoogleCodeExporter commented 9 years ago
This happens because mpi() rounds integers to the nearest pair of floating point
numbers whereas a direct function application attempts not to perform any 
rounding.
Note that this works:

>>> mp.dps = 1000
>>> a = mpi(10**100)
>>> mp.dps = 15
>>> sin(a)
[-0.37237612366127670338, -0.37237612366127664787]

Original comment by fredrik....@gmail.com on 4 Oct 2008 at 1:27

GoogleCodeExporter commented 9 years ago
So this is not an issue and should be closed?

Original comment by Vinzent.Steinberg@gmail.com on 4 Oct 2008 at 1:29

GoogleCodeExporter commented 9 years ago
Do you think it should be done differently?

I've thought about having the constructors mpf, mpc and mpi not perform any 
rounding
(unless necessary, when given e.g. strings). It would simplify some things.

Original comment by fredrik....@gmail.com on 4 Oct 2008 at 1:37

GoogleCodeExporter commented 9 years ago
It's currently not straightforward to track errors using mpi for 
sin(mpi(10**100))),
but this is not a real life example however. 

What's the point in performing such rounding (when not necessary)?

Original comment by Vinzent.Steinberg@gmail.com on 4 Oct 2008 at 2:01

GoogleCodeExporter commented 9 years ago
The point is that if one creates an instance at a given precision, it will 
correspond
uniquely to its repr at that precision.

The same can be accomplished with the + operator, though.

Original comment by fredrik....@gmail.com on 4 Oct 2008 at 2:09