Math errors in python

Richard Hanson me at privacy.net
Wed Sep 22 05:12:23 CEST 2004


Peter Otten wrote:

> Paul Rubin wrote:
> 
> > I haven't tried 2.4 yet.  After
> 
> The auther is currently working on an installer, but just dropping it into
> 2.3's site-packages should work, too.

I just dropped decimal.py from 2.4's Lib dir into 2.3.4's Lib dir.
Seems to work. Any gotchas with this route?

By the way, I got decimal.py revision 1.24 from CVS several days ago
and noted a speedup of over an order of magnitude -- almost
twenty-five times faster with this simple snippet calculating a square
root to 500 decimal places. :-) 

[On Win98SE:]

|    from time import clock
|    from decimal import *
|    
|    a = Decimal('18974018374087403187404701740918.7481704084710473048017483047104')
|    t = clock()
|    b = a.sqrt(Context(prec=500))
|    
|    print "Time: ", clock()-t
|    print "b =", b

With decimal.py from 2.4a3.2 dropped into 2.3.4's Lib dir:

|    IDLE 1.0.3      
|    >>> ================================ RESTART ================================
|    >>> 
|    Time:  7.40197958397
|    b = 4355917627100793.0054682072286...[elided]...67722472416430409564807807874919604463
|    >>> 

With decimal.py from CVS (revision 1.24) in 2.3.4's Lib dir:

|    IDLE 1.0.3      
|    >>> ================================ RESTART ================================
|    >>> 
|    Time:  0.300008380965
|    b = 4355917627100793.0054682072286...[elided]...67722472416430409564807807874919604463
|    >>> 

For a check, I did:

|    >>> setcontext(Context(prec=500))
|    >>> b * b
|    Decimal("18974018374087403187404701740918.748170408471047304801748304710400...[lotsa zeroes]...00")

Pretty damn impressive! -- Try it, you'll like it!

Good job to the crew for Decimal and the latest optimizations!


now-I-just-need-atan[2]()-ly y'rs,
Richard Hanson

-- 
sick<PERI0D>old<P0INT>fart<PIE-DEC0-SYMB0L>newsguy<MARK>com



More information about the Python-list mailing list