pi

Python large iterations number fail

风流意气都作罢 提交于 2019-12-10 01:56:49
问题 I wrote simple monte-carlo π calculation program in Python, using multiprocessing module. It works just fine, but when I pass 1E+10 iterations for each worker, some problem occur, and the result is wrong. I cant understand what is the problem, because everything is fine on 1E+9 iterations! import sys from multiprocessing import Pool from random import random def calculate_pi(iters): """ Worker function """ points = 0 # points inside circle for i in iters: x = random() y = random() if x ** 2 +

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

为君一笑 提交于 2019-12-09 17:09:12
问题 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 and I wanted to try using the BBP formula but am having difficulties. The equation I typed up doesn't seem to be giving me PI correctly. (1 / pow(16,n))((4 / (8 * n + 1)) - (2 / (8 * n + 4)) - (1 / (8 * n + 5)) - (1 / (8 * n + 6))) I was successful

How to display more than 20 decimal points in javascript?

[亡魂溺海] 提交于 2019-12-08 08:52:13
问题 I am making a webpage that displays the digits of pi. I was able to get my pi variable to display 20 digits of pi using the toFixed method but I am wondering if I can display more. Is the number of decimal places limited by the memory size of my variable? Is there a way to display more than 20 digits? EDIT: I should have clarified that I was using the Chudnovsky Algorithmn to calculate the value of pi. I assuming that because of the memory limitations of the var variable that it can only

Swift - Rotate gesture and rotation increments of 90 degrees

老子叫甜甜 提交于 2019-12-08 08:37:12
问题 I have a rotateView setup with a UIRotationGestureRecognizer . Works as intended, however I would like to only rotate in notches/increments of 90 degrees. The default behavior allows you to be very granular and precise with the rotation. I want it to be the opposite, of only 4 possible positions. The code I have below is as close I could get, however the problem I am facing is the rotation only happens once, and only to one direction (rotates to the right, even if I 2-fingers rotate to the

Swift - Rotate gesture and rotation increments of 90 degrees

只谈情不闲聊 提交于 2019-12-07 23:58:36
I have a rotateView setup with a UIRotationGestureRecognizer . Works as intended, however I would like to only rotate in notches/increments of 90 degrees. The default behavior allows you to be very granular and precise with the rotation. I want it to be the opposite, of only 4 possible positions. The code I have below is as close I could get, however the problem I am facing is the rotation only happens once, and only to one direction (rotates to the right, even if I 2-fingers rotate to the left). My code func rotatedView(recognizer:UIRotationGestureRecognizer){ let pi = CGFloat(M_PI)

Calculate Pi in Python with Polygons

断了今生、忘了曾经 提交于 2019-12-07 14:34:22
问题 I've got a problem in calculating Pi exactly. I'm using a method where I got a circle with radius=1 and inside of it I put polygons with 8, 16, 32, 64, ... corners, doubling them after each step. But the problem is that only the first 15 decimal digits of the result are correct. Here's the program: import math import time from decimal import * n_Ecken = 8 while n_Ecken >=8: time.sleep(0.5) n_Ecken = n_Ecken * 2 def berechneAlpha(): kreis = 360 alphaInsideFunc = Decimal(kreis) / Decimal(n

Using basic arithmetics for calculating Pi with arbitary precision

狂风中的少年 提交于 2019-12-07 05:21:37
问题 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 C++ and want to keep the implementation as simple as possible (no bignum library is allowed). I have found that this formula for calculating Pi is pretty simple: Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ... = sum( (-1)^(k+1)/(2*k-1) , k=1..inf ) (note that (-1)^

How to display more than 20 decimal points in javascript?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 16:22:23
I am making a webpage that displays the digits of pi. I was able to get my pi variable to display 20 digits of pi using the toFixed method but I am wondering if I can display more. Is the number of decimal places limited by the memory size of my variable? Is there a way to display more than 20 digits? EDIT: I should have clarified that I was using the Chudnovsky Algorithmn to calculate the value of pi. I assuming that because of the memory limitations of the var variable that it can only display up to a certain amount of digits which is limited to 20? Source You can't. Try storing the bits in

Pi calculation in python [closed]

你。 提交于 2019-12-06 13:43:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . n=iterations for some reason this code will need a lot more iterations for more accurate result from other codes, Can anyone explain why this is happening? thanks. n,s,x=1000,1,0 for i in range(0,n,2): x+=s*(1/(1+i))*4 s=-s print(x) 回答1: As I mentioned in a comment, the only way to speed this is to transform the

How to write PI calculation program in Java using multi-thread?

余生长醉 提交于 2019-12-06 09:57:07
问题 I need to create a program that can calculate approximation to the constant PI, using Java multi-thread. I'm intent to use Gregory-Leibniz Series to calculate the result for PI / 4, and then multiply by 4 to get the PI approximation. But I have some concern about the program: How can I seperate the calculation process so that I can implement a multi-thread processing for the program? Because the formula is for the total sum, I don't know how to split them into parts and then in the end I will