Setting longer default decimal precision

2013-11-18 Thread Kay Y. Jheallee

Using 1/3 as an example,

>>> 1./3
0.
>>> print "%.50f" % (1./3)
0.1482961625624739099293947219848633
>>> print "%.50f" % (10./3)
3.33348136306995002087205648422241210938
>>> print "%.50f" % (100./3)
33.33570180911920033395290374755859375000

which seems to mean real (at least default) decimal precision
is limited to "double", 16 digit precision (with rounding error).
Is there a way to increase the real precision, preferably as
the default?
For instance, UBasic uses a "Words for fractionals", f, 
"Point(f)" system, where Point(f) sets the decimal display 
precision, .1^int(ln(65536^73)/ln(10)), with the last few digits 
usually garbage.
Using "90*(pi/180)*180/pi" as an example to highlight the 
rounding error (4 = UBasic's f default value):


 Point(2)=.1^09: 89.99306
 Point(3)=.1^14: 89.99944
 Point(4)=.1^19: 89.9998772
 Point(5)=.1^24: 89.9217
 Point(7)=.1^33: 89.99823
Point(10)=.1^48: 89.7686
Point(11)=.1^52: 
89.9632


If not in the core program, is there a higher decimal precision 
module that can be added?


--
Kill Hector dead, because Desi sent Milli.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Setting longer default decimal precision

2013-11-20 Thread Kay Y. Jheallee

On 13.Nov.20.Wed 14:02, Steven D'Aprano wrote:> Hi Kay,
>
> You emailed me off-list, but your email address is bouncing or 
invalid,

> so I have no way to email you back.

So THAT's where it went!  Sorry about that...yes, it WAS meant 
for the group :/!


> [you wrote]
> Okay,but after I import "math" and "decimal",
>
> py> decimal.getcontext().prec=75
> py> print decimal.Decimal(math.atan(1))
> 0.78539816339744827899949086713604629039764404296875
>
> though I set precision to 75, it only did the trig function to
> 50 places AND it is only right to 16 places,
>
> 0.785398163397448309615660845819875721049292349843776...
> (actual).
> [end quote]
>
>
> Here, you calculate the atan of 1 using floating point maths,
> that is, to the precision of C doubles (about 17 decimal
> places). After the calculation is performed using float, you
> then convert it to a Decimal,
> but it is too late, you can't retroactively regain precision.
>
> In a perfect world, this would work:
>
> math.atan(Decimal(1))
>
> but alas, all the functions in the math module convert their
> arguments to float first, so even though your Decimal(1)
> could perform calculations to 75 decimal places, the
> math.atan function downgrades it to a regular float.

Then that is useless! :(

> You could try this third-party module:
>
> http://code.google.com/p/mpmath/‎

Ah, that looks like just the puppy I'm looking for. :)
Okay then, I just installed the PortableApps version of Python,
but when I downloaded "mpmath-0.17.win32" the installer aborted 
with "No Python installation found in the registry".

So I'm trying to install "setuptools 1.4" (and do it that way) at

   https://pypi.python.org/pypi/setuptools/1.4

but where is the "Download" link ("Downloads" just shifts down to 
the page section)?  I'm just looking for the ".zip" file version 
(if one exists), not ".tar.gz".

Thx!

--
Kill Hector dead, because Desi sent Milli.
--
https://mail.python.org/mailman/listinfo/python-list