Printing Precision

2 views
Skip to first unread message

William Purcell

unread,
Feb 19, 2009, 11:57:37 PM2/19/09
to sy...@googlegroups.com
I have seen issues 1019 and 1052 on how to handle printing of sig.
digits but haven't seen a solution. I am running the attached script
and getting things like
pH =
[ 950000.000000000]
[-400000.000000000]
[ 600000.000000000]

I preprocessing this script with another python script and inserting
the values returned from latex() into a latex document, and some of
the equations are running off the page. How do I set the global
printing precision to make things look nicer?

Thanks,
Bill

one.py

Ondrej Certik

unread,
Feb 20, 2009, 1:55:19 AM2/20/09
to sy...@googlegroups.com
Hi William,

This is a very annoying behaviour introduced with some merge of
mpmath, but I think the fix should be fairly easy, as described here:

http://code.google.com/p/sympy/issues/detail?id=1052#c22

I still hope Fredrik will find time to fix it, as he understands this
part the best, but if not, I'll try to look at it before a release and
fix it myself. Any help with this is appreciated.

Ondrej

William Purcell

unread,
Feb 20, 2009, 10:32:33 AM2/20/09
to sy...@googlegroups.com
A hack I'm going to use for now is changing the return in
str.StrPrinter._print_Real to the following

class StrPrinter....
...
...
def _print_Real(self, expr):
prec = expr._prec
if prec < 5:
dps = 0
else:
dps = prec_to_dps(expr._prec)
return mlib.to_str(expr._mpf_, dps, strip_zeros=True)#<-- i
changed False to True
...
...

Should this not be the default? I am trying to think of an instance
where someone might want to keep all the zeros for a simple floating
point like 1.0 at 15 dps?

-Bill

William Purcell

unread,
Feb 20, 2009, 10:59:59 AM2/20/09
to sy...@googlegroups.com
From re-reading issue 1052, it looks like this question has been answered.

Ondrej Certik

unread,
Feb 20, 2009, 2:25:26 PM2/20/09
to sy...@googlegroups.com

If you want, as an exercise, try to run all sympy tests with your
patch to see if something gets broken. If not, try to send it as a
regular patch using git, see here for a tutorial:

http://docs.sympy.org/sympy-patches-tutorial.html#quick-start

Thanks,
Ondrej

William Purcell

unread,
Feb 20, 2009, 2:37:59 PM2/20/09
to sy...@googlegroups.com
> If you want, as an exercise, try to run all sympy tests with your
> patch to see if something gets broken.

I ran the test_evalf test. (see Issue 1052). I will try running the other tests.
Is there a 'top-level' script to do this?


> If not, try to send it as a
> regular patch using git, see here for a tutorial:
> http://docs.sympy.org/sympy-patches-tutorial.html#quick-start

I will look into this.

Ondrej Certik

unread,
Feb 20, 2009, 2:45:32 PM2/20/09
to sy...@googlegroups.com
On Fri, Feb 20, 2009 at 11:37 AM, William Purcell
<william...@gmail.com> wrote:
>> If you want, as an exercise, try to run all sympy tests with your
>> patch to see if something gets broken.
>
> I ran the test_evalf test. (see Issue 1052). I will try running the other
> tests.
> Is there a 'top-level' script to do this?

Yes, just execute

bin/test sympy

Ondrej

Reply all
Reply to author
Forward
0 new messages