## pi

### Fastest way to get value of pi

Solutions welcome in any language. :-) I'm looking for the fastest way to obtain the value of pi, as a personal challenge. More specifically I'm using ways that don't involve using #defined constants like M_PI, or hard-coding the number in. The program below tests the various ways I know of. The inline assembly version is, in theory, th...

### How do I calculate PI in C#?

How can I calculate the value of PI using C#? I was thinking it would be through a recursive function, if so, what would it look like and are there any math equations to back it up? I'm not too fussy about performance, mainly how to go about it from a learning point of view. ...

### Gauss-Legendre Algorithm in python

Hello! I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use. I have read about the Gauss-Legendre Algorithm, and I have tried porting it to Python with no success. I am reading from Here, and I would app...

### Is java.lang.Math.PI equal to GCC's M_PI?

I am coding several reference algorithms in both Java and C/C++. Some of these algorithms use . I would like for the two implementations of each algorithm to produce identical results, without rounding differently. One way to do this that has worked consistently so far is to use a custom-defined pi constant which is exactly the same in b...

### Finding PI digits using Monte Carlo

I have tried many algorithms for finding π using Monte Carlo. One of the solutions (in Python) is this: def calc_PI(): n_points = 1000000 hits = 0 for i in range(1, n_points): x, y = uniform(0.0, 1.0), uniform(0.0, 1.0) if (x**2 + y**2) <= 1.0: hits += 1 print "Calc2: PI result", 4.0 * floa...

### Pi/Infinite Numbers

I'm curious about infinite numbers in computing, in particular pi. For a computer to render a circle it would have to understand pi. But how can it if it is infinite? Am I looking too much into this? Would it just use a rounded value? ...

### Is it possible to have an optional stylesheet in an xsl-stylesheet processing instruction?

I've applied a stylesheet to an xml document using <?xsl-stylesheet ...>, this works great when the XML is being viewed in my application. But if the xml is exported, I want the XML to still render as plain XML, is it possible to have the stylesheet as optional rather than it producing this error when style is not found: Error loadin...

### Calculating the value of pi-what is wrong with my code

Hi, I'm doing another C++ exercise. I have to calculate the value of pi from the infinite series: pi=4 - 4/3 + 4/5 – 4/7 + 4/9 -4/11+ . . . The program has to print the approximate value of pi after each of the first 1,000 terms of this series. Here is my code: #include <iostream> using namespace std; int main() { double pi=0.0;...

### How is π calculated within sas?

just curious! but I spotted that the value of π held by SAS is in fact incorrect. for instance: data _null_; x= constant('pi') * 1000000000000000000000000000; put x= 32.; run; gives a π value of (3.)141592653589792961327005696 however - π is of course (3.)1415926535897932384626433832795 ( http://www.joyofpi.com/pi.html ) - to 31 d...

### Computing π to "infinite" binary precision in C#

So far it looks like Fabrice Bellard's base 2 equation is the way to go Ironically this will require a BigReal type; do we have this for .Net? .Net 4.0 has BigInteger. Anyone have a Haskell version? ...

### C# Math vs. XNA MathHelper

Ever since I needed to work with PI (3.1415...) in C# I have used Math.PI to get the value. Usually I would just use values like Math.PI/2.0 or 2.0*Math.PI, but now I have just noticed that XNA provides a MathHelper class. The nice thing about this is I can call MathHelper.PiOver2 and MathHelper.TwoPi, thus making an extremely trivial ...

### Parallel, but slower

I'm using monte carlo method to calculate pi and do a basic experience with parallel programming and openmp the problem is that when i use 1 thread, x iterations, always runs faster than n thread, x iterations. Can anyone tell me why? For example the code runs like this "a.out 1 1000000", where 1 is threads and 1000000 the iterations ...

### Why define PI = 4*ATAN(1)

What is the motivation for defining PI as PI=4.D0*DATAN(1.D0) within a Fortran 77 code? I understand how it works, but, what is the reasoning? ...

### Fortran77 compiler treatment of PI=4.D0*DATAN(1.D0)

When using the following to compute PI in fortran77, will the compiler evaluate this value or will it be evaluated at run time? PI=4.D0*DATAN(1.D0) ...

### Trying to calculate Pi to N number of decimals with C#.

Note: I've already read this topic, but I don't understand it and it doesn't provide a solution I could use. I'm terrible with number problems. What's a simple way to generate Pi to what number of decimals a user wants? This isn't for homework, just trying to complete some of the projects listed here: Link ...

### Calculating pi using infinite series in C#

Hi! I tried to write the following program in C# to calculate pi using infinite recursion, but I keep getting confused about integer/double/decimal division. I really have no clue why this isn't working, so pardon me for my lack of understanding of strongly typed stuff, as I'm still learning C#. Thanks in advance! using System; using ...

### Cannot draw pixels, Pi number in a Synesthetic way

I want to print each digit of pi number as a colored pixel, so, I get an input, with the pi number, then parse it into a list, each node containing a digit (I know, I'll use an array later), but I never get this painted to screen... Can someone help me to see where I'm wrong? import java.awt.BorderLayout; import java.awt.Graphics; impor...

### How is PI calculated?

I want to make a function in C that can return PI to X places.. I'm just not sure how... Thanks Edit: I don't care how slow it is I really just want an algorithm that will return PI at X decimal... Iv been looking at http://bellard.org/pi/ but I don't understand how to get the nth of Pi from this. Thanks ...

### Required Working Precision for the BBP Algorithm?

Hello, I'm looking to compute the nth digit of Pi in a low-memory environment. As I don't have decimals available to me, this integer-only BBP algorithm in Python has been a great starting point. I only need to calculate one digit of Pi at a time. How can I determine the lowest I can set D, the "number of digits of working precision"? ...

### Pi help with Php (mass looping)

My primary question is: Is this alot of loops? while (\$decimals < 50000 and \$remainder != "0") { \$number = floor(\$remainder/\$currentdivider); //Always round down! 10/3 =3, 10/7 = 1 \$remainder = \$remainder%\$currentdivider; // 10%3 =1, 10%1 \$thisnumber = \$thisnumber . \$number; \$remainder = \$remainder . 0; //10 \$decimals += 1; } Or could...