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
-3
votes
2 answers

How do I fix this bug with arctanx function in c++

I've recently been given a problem by my teacher about some mathematical equation / formula called the arctanx formula. The question is: According to the Arctanx(x) = x - ((x ^ 3) / 3) + ((x ^ 5) / 5) - ((x ^ 7) / 7) + ...and π = 6 * arctanx(1 /…
andy zhang
  • 21
  • 6
-3
votes
1 answer

Generate Pi to user-defined digit using printf in Java?

Is it possible to let the user enter any int value and have the output show Pi to that decimal point without something like BigDecimal? I'm trying to do this in a project and the only things I'm allowed to use are the "printf" function and…
garybenoak
  • 1
  • 1
  • 2
-3
votes
2 answers

Using java to approximate pi with the first 8 terms of the sequence

I'm just starting out with programming and need to do an assignment for class where I approximate pi using the first 8 terms in the sequence. I need to do this by creating a variable 'nextTerm' with initial value 1, variable 'denominator' with…
Puck
  • 1
  • 1
-3
votes
1 answer

Java - 100 decimal places in variable

I have a problem when it comes to calculating pi with more than 15 decimal places(i used double). My result looks quite good except my variable is limited to 15 decimal places: 3.140592653839794 Anybody could tell me what i have to do if i want more…
Creative crypter
  • 1,348
  • 6
  • 30
  • 67
-3
votes
2 answers

Is there a more efficient way to calculate pi?

I started learning java yesterday. Since I know other programming languages, it's easier for me to learn Java. It's pretty cool, actually. I still prefer Python :) Anyhoo, I wrote this program to calculate pi based on the algorithm (pi = 4/1 - 4/3 +…
-3
votes
4 answers

I am attempting to print only a selected amount of Pi, it returns with an error of "Decimal has no attribute: __getitem__

def pi(): prompt=">>> " print "\nWARNING: Pi may take some time to be calculated and may not always be correct beyond 100 digits." print "\nShow Pi to what digit?" n=raw_input(prompt) from decimal import Decimal, localcontext …
Patrick Cook
  • 458
  • 12
  • 27
-4
votes
1 answer

calculating pi with 4-4/3+4/5-

I have written a code to calculate this to 100th sentence for pi but it shows "3" this the formula #include using namespace std; int main() { int n = 1; double a, P = 0; for (n; n <= 100; n++) { a = 4 / (2 * n - 1); …
m reza
  • 9
  • 1
-4
votes
1 answer

Simplify 2 Java variables into one

I've got these 2 Java variables: spiEuler = spiEuler + (1 / Math.pow(2 * k + 1, 2)); piEuler = Math.sqrt(spiEuler * 8); ...and I'd like to combine them into one. Unfortunately, piCombined = Math.sqrt((xPi + (1 / Math.pow(2 * k + 1, 2))) *…
Fabian Stern
  • 85
  • 1
  • 5
-4
votes
1 answer

Calculate pi without losing performance in C++ or Python

I am looking for an algorithm to calculate pi and keep calculating without having to calculate everything over again. I'm trying to look for a number in pi. I made an algorithm in Python which does exactly that, but it slows down with the time…
fabian0010
  • 13
  • 4
-4
votes
3 answers

PI number to 10000 digits

I'm trying to write a program showing 10000 digits of PI number, easy, huh? Well, there's a catch, the file is limited to 5000 Bytes. I tried doing things like changing "11" to a to make the code shorter, but it was about 9000 and that's too much…
honzix
  • 23
  • 3
-4
votes
1 answer

Assistance needed with calculating value of pi using java

Question That Needs To Be Solved: http://i62.tinypic.com/23rtieb.png I have this problem I need to solve using Java. However I tried but was not able to. Here is what I have done so far. public class Cirlce { public static void main(String[]…
Arjun Dhiman
  • 164
  • 8
-5
votes
2 answers

How do I show all decimal points?

I'm currently trying to do: double keyTimes = 789789347928325 * Math.Pi Console.WriteLine(keyTimes); And it gives me: 2.4811964133351E+15 I need it to give me the full number of digits for a project, how can I achieve this? I want something like:…
Yen
  • 19
  • 4
-5
votes
1 answer

Computing pi with a series

I want to compute pi using the Spinot's Algorithm of Rabinowitz. It is an infinite sum which consists of two factorials and one power: The thing is I wrote simple programs for computation of factorials and powers, but I need to combine them in a…
Shukrullo
  • 11
  • 3
-7
votes
2 answers

PI decimal using Math.Round

I'm looking for an answer to the following: Desired behaviour Round the mathematical constant pi to 2 or 4 decimals. Current code I have tried the following: Double piRounded; piRounded = Math.Round.PI(4); piRounded = Math.Round.PI(2); Current…
-7
votes
1 answer

What is the most efficient way to calculate PI in C?

I'm have to write a C program, what it does is takes a integer as input. And gives output to the input(th) number of PI after decimal. Like if input is 100, output will be 9(100th digit of pi, after decimal is 9). What will be the best algorithm…
1 2 3
53
54