[Tutor] greater precision?

John Collins john at netcore.com.au
Mon Oct 29 10:49:50 CET 2012


Hi,
OS: XP
Py: 2.7.2

I am running some old scripts, not written by me, that produce
substantial calculated values data as decimals, 12 significant
figures. AFAIK, the keys calls are;

from math import pi, asin, atan2, cos, sin, sqrt

from math import pi, asin, atan2, cos, sin, sqrt
from crosspoint import crosspoint

which are from the 1st and 2nd scripts, that are run to generate,
then manipulate, the numbers (actually, polygon descriptions!).
However, the 2nd script 'calls' a script called crosspoint.py,
trimmed of most comments this is;

# Python code to find the crossing point of two lines.
# This function is optimised for big-integer or FP arithmetic: it
# multiplies up to find two big numbers, and then divides them.

def crosspoint(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2):
     "Give the intersection point of the (possibly extrapolated) lines\n"\
     "segments (xa1,ya1)-(xa2,ya2) and (xb1,yb1)-(xb2,yb2)."
     dxa = xa2-xa1
     dya = ya2-ya1
     dxb = xb2-xb1
     dyb = yb2-yb1
     if dya * dxb == dxa * dyb:
         return None
     if dxa == 0:
         return (xa1, (xa1 - xb1) * dyb / dxb + yb1)
     if dxb == 0:
         return (xb1, (xb1 - xa1) * dya / dxa + ya1)
     if dya == 0:
         return ((ya1 - yb1) * dxb / dyb + xb1, ya1)
     if dyb == 0:
         return ((yb1 - ya1) * dxa / dya + xa1, yb1)

     det = dya * dxb - dyb * dxa
     xtop = dxb * dxa * (yb1-ya1) + dya * dxb * xa1 - dyb * dxa * xb1
     ytop = dya * dyb * (xa1-xb1) + dxb * dya * yb1 - dxa * dyb * ya1

     return (xtop / det, ytop / det)


I am not sure what == means, nor if any 'special' maths functions are
called from crosspoint.py (to me, it appears not?), so, as I understand 
it, the

from math import

line *is* the 'math engine' if you will, and is the source of the 12
sig fig limit, yes?

One other odd thing that occurs, is when the scripts are run, a weird,
small, non ASCII file called crosspoint.pyc is created? Is this the
interpreter 'compiling' crosspoint.py ( either before, during, or
after?) the 2nd script calls it?

Sorry to bother, but if I can squeeze out *at least* 15 sig figs, (30
or more would be better!) I'd be a happy camper!
XNumbers addon for Excel allows over 200 sig figs by switching to base
256 IIRC. It is this with which I'd like to examine the output of these
pyto scripts at finer resolution, if that can be done in python???

Best Regards,
John Collins.


More information about the Tutor mailing list