Questions tagged [pi]

π (pi) is a mathematical constant whose value is the ratio of any Euclidean plane circle's circumference to its diameter; this is the same value as the ratio of a circle's area to the square of its radius. It is approximately equal to 3.14159265 in decimal notation. For Raspberry Pi, please tag with "raspberry-pi".

π (pi) is a mathematical constant whose value is the ratio of any Euclidean plane circle's circumference to its diameter; this is the same value as the ratio of a circle's area to the square of its radius. It is approximately equal to 3.14159265 in decimal notation.

For questions related to Raspberry Pi, please use the tag instead.

811 questions
10
votes
1 answer

Are there number limitations in python?

I have made a Python 3 program to calculate pi for a school project, but it always stops at 16 decimal places. Is there a limit to the length of numbers in python? If so is there a language that I could use that will let me continue? accuracy =…
Joe Allen
  • 377
  • 1
  • 4
  • 14
10
votes
2 answers

Calculating Pi in JavaScript using Gregory-Leibniz Series

I have to calculate value of Pi using Gregory-Leibniz series: pi = 4 * ((1/1 - 1/3) + (1/5 - 1/7) + (1/9 - 1/11) + ...) I want to write a function in JavaScript that would take the number of digits that needs to be displayed as an argument. But…
Joanna
  • 289
  • 1
  • 6
  • 16
10
votes
3 answers

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…
SuperSized
  • 789
  • 1
  • 8
  • 11
9
votes
3 answers

generating pi to nth digit java

I wanted to know how I can generate pi to the nth digit. I have a couple of basic ideas. Use Math.PI and increase the precision (if that's possible) Use Euler's formula to generate pi but even here, I would need to increase the precision (I…
Jeel Shah
  • 3,274
  • 17
  • 47
  • 68
8
votes
5 answers

Javascript: PI (π) Calculator

Is there a way to calculate pi in Javascript? I know there you can use Math.PI to find pie like this: var pie = Math.PI; alert(pie); // output "3.141592653589793" but this is not accurate. What I want is to be able to calculate it, to have as many…
Cai Haoyang
  • 192
  • 1
  • 3
  • 16
8
votes
1 answer

pi deprecated on OS X 10.8

Is there a replacement for pi const on OS X 10.8? When I use it I get the following warning: 'pi' is deprecated: first deprecated on Mac OS X 10.8 It works but I want to get rid of that warning.
Bruno Ferreira
  • 942
  • 9
  • 22
8
votes
10 answers

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?
Ben Shelock
  • 20,154
  • 26
  • 92
  • 125
7
votes
3 answers

Bailey–Borwein–Plouffe formula implementation in C++?

EDIT: The requirement was vague and instead of calculating the n-th digit of pi they just wanted pi to the n-th digit not going beyond floats limitation so the brute force way worked for the requirements. I need to calculate PI the the n-th digit…
krizzo
  • 1,823
  • 5
  • 30
  • 52
7
votes
1 answer

Why do M_PI_2, M_PI_4, M_1_PI, and M_2_PI exist?

I do understand why we have this in standard headers: #define M_PI 3.14159265358979323846 // pi However, I don't see much benefit in having these: #define M_PI_2 1.57079632679489661923 // pi/2 #define M_PI_4 …
Reunanen
  • 7,921
  • 2
  • 35
  • 57
7
votes
3 answers

Function to find the nth digit of Pi

I have always wanted to find an algorithm that did this. I do not care how slow it is, just as long as it can return the nth digit of Pi: ex: size_t piAt(long long int n) { } Preferably, not using an infinite series. If anyone has a function or…
jmasterx
  • 52,639
  • 96
  • 311
  • 557
7
votes
5 answers

Monte Carlo Method of finding pi using C

I have written a function that takes in a long long value n and uses that as the number of iterations to go through. The function should give a good estimate of pi, however, all the values for large n tends towards 3.000, and not 3.1415,so I am not…
Pengibaby
  • 373
  • 2
  • 11
7
votes
3 answers

Cython's calculations are incorrect

I implemented the Madhava–Leibniz series to calculate pi in Python, and then in Cython to improve the speed. The Python version: from __future__ import division pi = 0 l = 1 x = True while True: if x: pi += 4/l else: pi -=…
None
  • 3,875
  • 7
  • 43
  • 67
7
votes
3 answers

Using basic arithmetics for calculating Pi with arbitary precision

I am looking for a formula/algorithm to calculate PI~3.14 in a given precision. The formula/algorithm must have only very basic arithmetic as +: Addition -: Subtraction *: Multiplication /: Divison because I want to implement these operations in…
Isaac
  • 2,332
  • 6
  • 33
  • 59
7
votes
1 answer

Why doesn't my program approximate pi?

For yesterday's Pi Day, Matt Harper published a video in which he approximated Pi by rolling two 120-sided dice 500 times (see the video here). Basically, for each pair of random numbers, you have to check whether they are coprime or not. Then, the…
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
7
votes
2 answers

Can't accurately calculate pi on Python

I am new member here and I'm gonna drive straight into this as I've spent my whole Sunday trying to get my head around it. I'm new to Python, having previously learned coding on C++ to a basic-intermediate level (it was a 10-week university…
Stuart Aitken
  • 949
  • 1
  • 13
  • 30
1 2
3
53 54