[Tutor] greater precision?

Steven D'Aprano steve at pearwood.info
Mon Oct 29 11:23:02 CET 2012


On 29/10/12 20:46, John Collins wrote:
> 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;

"Decimal" has a specific meaning in Python different to how you
appear to be using it. It looks to me like you are working with
floats rather than decimals.

If the difference means nothing to you, don't worry too much about
it at this stage.


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

That line appears duplicated. You can delete one of those lines.


> from crosspoint import crosspoint

"crosspoint" appears to be a custom Python program that we know
nothing about, apart from what you tell us.

[...]

> I am not sure what == means,

In Python, "=" is used for assignment:

x = 1

means "let x be a name for the value 1".

"==" is used for equality testing:

x == 2

returns False, because x does not equal 2; but

x == 1

returns True, because x does currently equal 1.



> nor if any 'special' maths functions are
> called from crosspoint.py (to me, it appears not?),

Nor to me.


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

Almost. The "from math import blah..." line extracts a bunch of maths
functions from the math library and makes them available to your
program.

The number of significant figures is more fundamental that that; your
operating system understands about floating point numbers (so-called
"C doubles") with 53 *binary* significant figures, or about 17 *decimal*
figures. So I'm not sure why you think there are only 12.


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

Yes.


> Sorry to bother, but if I can squeeze out *at least* 15 sig figs,

You need to show us how the output is generated in the first place.


> (30 or more would be better!)

Not a chance without some major changes to your program.

I can't say how major without seeing more of your program.


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

Well, yes, but only with some significant changes



-- 
Steven


More information about the Tutor mailing list