pi

Using BigDecimal to print Pi

痴心易碎 提交于 2020-05-15 09:55:07
问题 I'm tring to use BigDecimal to print Pi, but it turns out it's not accurate BigDecimal d = new BigDecimal(Math.PI); System.out.println(d); The above answer gives me "3.141592653589793115997963468544185161590576171875" but the digits after "3.141592653589793" is incorrect how this is happenning ? and can i use bigdecimal to print PI ? 回答1: From Javadoc for Math.PI: PI public static final double PI The double value that is closer than any other to pi, the ratio of the circumference of a circle

Need help fixing an algorithm that approximates pi

被刻印的时光 ゝ 提交于 2020-05-15 06:37:05
问题 I'm trying to write the C code for an algorithm that approximates pi . It's supposed to get the volume of a cube and the volume of a sphere inside that cube (the sphere's radius is 1/2 of the cube's side). Then I am supposed to divide the cube's volume by the sphere's and multiply by 6 to get pi. It's working but it's doing something weird in the part that is supposed to get the volumes. I figure it's something to do the with delta I chose for the approximations. With a cube of side 4 instead

Cannot import name '_gi'

你离开我真会死。 提交于 2020-04-30 06:30:18
问题 I'm trying to add a repository to ppa with the add-apt-repository commands but the _gi module from Python is not found. I did this command : sudo add-apt-repository ppa:s-mankowski/ppa-kf5 Here is the traceback : Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 11, in <module> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 67, in <module> from

Cannot import name '_gi'

天大地大妈咪最大 提交于 2020-04-30 06:30:12
问题 I'm trying to add a repository to ppa with the add-apt-repository commands but the _gi module from Python is not found. I did this command : sudo add-apt-repository ppa:s-mankowski/ppa-kf5 Here is the traceback : Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 11, in <module> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 67, in <module> from

how to use math.pi in java

不打扰是莪最后的温柔 提交于 2020-04-07 14:47:30
问题 I am having problems converting this formula V = 4/3 π r^3 . I used Math.PI and Math.pow , but I get this error: ';' expected Also, the diameter variable doesn't work. Is there an error there? import java.util.Scanner; import javax.swing.JOptionPane; public class NumericTypes { public static void main (String [] args) { double radius; double volume; double diameter; diameter = JOptionPane.showInputDialog("enter the diameter of a sphere."); radius = diameter / 2; volume = (4 / 3) Math.PI *

Java - Ramanujan Series for pi

瘦欲@ 提交于 2020-01-06 07:03:55
问题 For one of my programs in my Computer Science class I have to calculate the value of pi using the following formula, I'm having trouble with the math equation in java. Here's the math formula: Formula for 1/pi the formulas I used were: for (int i = 0; i < k; i++) { term = ((calculate(4*i)*(1103+(26390*i)))/(Math.pow(calculate(i), 4))*Math.pow(396, (4*i))); sum += term; } sum *= ((2*Math.sqrt(2))/9801); sum = Math.pow(sum, -1); The for loop should calculate the sigma sign and everything to the

Java - Ramanujan Series for pi

做~自己de王妃 提交于 2020-01-06 07:03:20
问题 For one of my programs in my Computer Science class I have to calculate the value of pi using the following formula, I'm having trouble with the math equation in java. Here's the math formula: Formula for 1/pi the formulas I used were: for (int i = 0; i < k; i++) { term = ((calculate(4*i)*(1103+(26390*i)))/(Math.pow(calculate(i), 4))*Math.pow(396, (4*i))); sum += term; } sum *= ((2*Math.sqrt(2))/9801); sum = Math.pow(sum, -1); The for loop should calculate the sigma sign and everything to the

Get mouse position relative to pie chart (equation)

让人想犯罪 __ 提交于 2020-01-03 09:12:06
问题 I have created a canvas pie chart from an array of data, I am now trying to locate the mouse position relative to the pie chart to detect which section of data is being hovered. I am almost there but I am stuck on an equation. My logic is functioning fine so I think this is more of a Maths question but will see what others think of my approach. here is my pie chart and the variables I am using: The listed variables on the image are the variables that I have to use (mouseX, mouseY, distance

How can pi be calculated to a set number of digits in PHP?

本秂侑毒 提交于 2019-12-30 06:54:48
问题 How can I calculate the value of pi in PHP up to X decimal numbers. 4 decimal points 3.141 64 decimal points 3.141592653589793238462643383279502884197169399375105820974944592 回答1: Found the source for the broken link @Konamiman posted. Compared the results to: http://www.angio.net/pi/digits/50.txt and they are the same. // Source: http://mgccl.com/2007/01/22/php-calculate-pi-revisited function bcfact($n) { return ($n == 0 || $n== 1) ? 1 : bcmul($n,bcfact($n-1)); } function bcpi($precision) {

How to parallelize monte carlo estimation of pi using pthreads?

时光毁灭记忆、已成空白 提交于 2019-12-23 19:26:55
问题 #include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> int main(int argc, char **argv) { unsigned long long in = 1; unsigned long long total = 2; double tol , change, new, secs , old = 0.0; struct timeval start , end; int threads ; /* ignored */ if ( argc < 2) { exit (-1); } threads = atoi ( argv[1]); tol = atof ( argv[2]); if (( threads < 1) || ( tol < 0.0)) { exit (-1); } tol = tol *tol; srand48(clock()); gettimeofday (&start , NULL); do { double x, y