473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Compute pi to base 12 using Python?

I need to figure out how to compute pi to base 12, to as many digits as
possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't understand
it well enough. Could someone show me how to do what I need?

Thanks,

Dick Moores
rd*@rcblue.com

Jul 18 '05
52 5798
>>PS. Redirecting with > from a script whose interpreter was started by
windows extension association
doesn't work on some version of windows. To be safe, invoke the
interpreter explicitly, e.g.,
python myscript.py [whatever args here] > pi3003.txt
Thanks very much for this.
What kind of args could I use here?

Any that your script allows or understands.
an example:
python c:/Python22/Lib/PySourceColor.py -i- -s -l < c:/MyFile.py >
c:/tmp/myfile.html

A few things that might help you write a well behaved script:
if sys.stdin.isatty():
"direct"
else:
"redirected"
This snippet can determine if you have redirected IO.

I just found this and it looks informative.
http://www.jpsdomain.org/windows/redirection.html

hth,
M.E.Farmer

Jul 19 '05 #51
me********@aol.com <me********@aol.com> wrote:
Nick Craig-Wood wrote:
me********@aol.com <me********@aol.com> wrote:
I'm using GMPY (see code).

[snip]

If you are using gmpy you might as well do it like this.....

gmpy.pi() uses the Brent-Salamin Arithmetic-Geometric Mean formula
for
pi IIRC. This converges quadratically, and it will calculate you a
million places without breaking a sweat.


It would be nice if that were documented. What do I have to do, go get
the documentation for the original GMP to find out what else is in GMPY
that they didn't include in the doc file?


"pydoc gmpy" works for me. Not sure how you use pydoc on windows, but
you can do this...
import gmpy
help(gmpy)

Help on module gmpy:

NAME
gmpy

FILE
/usr/lib/python2.3/site-packages/gmpy.so
[snip]
Help on built-in function pi:

pi(...)
pi(n): returns pi with n bits of precision in an mpf object
[snip]

The original gmp documentation is sensible also, since gmpy is really
just a thin wrapper to it. There is also the gmp source code too.

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jul 19 '05 #52

Nick Craig-Wood wrote:
me********@aol.com <me********@aol.com> wrote:
Nick Craig-Wood wrote:
me********@aol.com <me********@aol.com> wrote:
> I'm using GMPY (see code).
[snip]

If you are using gmpy you might as well do it like this.....

gmpy.pi() uses the Brent-Salamin Arithmetic-Geometric Mean formula for
pi IIRC. This converges quadratically, and it will calculate you a million places without breaking a sweat.
It would be nice if that were documented. What do I have to do, go get
the documentation for the original GMP to find out what else is in GMPY that they didn't include in the doc file?


"pydoc gmpy" works for me. Not sure how you use pydoc on windows,

but you can do this...
import gmpy
help(gmpy) Help on module gmpy:

NAME
gmpy

FILE
/usr/lib/python2.3/site-packages/gmpy.so
[snip]
Help on built-in function pi:

pi(...)
pi(n): returns pi with n bits of precision in an mpf object
[snip]
Thanks, didn't know you could do that. And I'm glad you didn't reply
until today, because I learned how to do it the hard way:
import gmpy
f = dir(gmpy)
def print_docs(f): for q in f:
if q[:2]=='__':
pass
else:
d = 'gmpy.' + q + '.__doc__'
e = eval(compile(d,'<string>','eval')
print e
print print_docs(f)

That's 3 new functions I learned, dir(), compile() and eval().
And now that I know help(), I'll probably never need them, but
hopefully will remember them.

Even better, I realize the inadequecy of the doc strings of a
program I wrote. Now that I know how to use them interactively,
I can make them more useful.

The original gmp documentation is sensible also, since gmpy is really
just a thin wrapper to it.
I already looked. Utterly useless.
There is also the gmp source code too.
That helped, as there's a list of the function names in the source
code, but help() makes it unnecessary.

You still have to wonder, though, with as easy as this is, how the
gmpy documention ended up incomplete. I'm always reminded of something
I read in the National Lampoon:

"You know what a fuck-up you are at work, how would anything get
done if everyone was like you? Well, the sad fact is everyone _is_
just like you...including the air traffic controller who's supposed
to be tracking your flight but has just looked away because he
dropped a cigarette ash and burned a hole in his trousers..."

So I suppose I shouldn't complain, after all, I got something
positive out of it.

--
Nick Craig-Wood <ni**@craig-wood.com> --

http://www.craig-wood.com/nick

Jul 19 '05 #53

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: The_Incubator | last post by:
As the subject suggests, I am interested in using Python as a scripting language for a game that is primarily implemented in C++, and I am also interested in using generators in those scripts... ...
8
by: Sridhar R | last post by:
Hi, I am a little experienced python programmer (2 months). I am somewhat experienced in C/C++. I am planning (now in design stage) to write an IDE in python. The IDE will not be a simple...
2
by: Richard Shea | last post by:
Hi - I wondered if anyone had done this before and could provide some suggestions ? I'm interested in supplying extra functionality to a Win32 Console (cmd.exe) - full description below for those...
8
by: Joakim Persson | last post by:
Hello all. I am involved in a project where we have a desire to improve our software testing tools, and I'm in charge of looking for solutions regarding the logging of our software (originating...
3
by: jonas | last post by:
Guys was wondering has any done this I need to get a heads up as i need to grab data from a databasemake some changes and then put it back in place I'm guessing the MySqlDB Module be it seems...
29
by: 63q2o4i02 | last post by:
Hi, I'm interested in using python to start writing a CAD program for electrical design. I just got done reading Steven Rubin's book, I've used "real" EDA tools, and I have an MSEE, so I know what...
11
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
9
by: dominiquevalentine | last post by:
Hello, I'm a teen trying to do my part in improving the world, and me and my pal came up with some concepts to improve the transportation system. I have googled up and down for examples of using...
14
by: Nathan Pinno | last post by:
How do I factor a number? I mean how do I translate x! into proper Python code, so that it will always do the correct math? Thanks in advance, Nathan P.
53
by: Vicent Giner | last post by:
Hello. I am new to Python. It seems a very interesting language to me. Its simplicity is very attractive. However, it is usually said that Python is not a compiled but interpreted programming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.