pi

让golang在Raspberry Pi上飞一会

落花浮王杯 提交于 2019-12-02 15:09:16
最近在玩2样东西,一样是go语言(golang),一样是Raspberry Pi(树莓派)。那么能在Raspberry上运行go语言程序吗? Golang的文档上说是支持多平台的,其中也包括了ARM,看来有戏了,兴冲冲打开 http://code.google.com/p/go/downloads/list ( golang编译器的下载页面 ) ,却发现没有arm平台的二进制大包下载。所以arm平台下的需要下载源码自己编译。 Raspberry上编译前准备及配置 一。俗话说巧妇难为无米之炊,要编译源码先得下源码,下载后这里解压到 /home/pi/go 目录下。 二。确认需要的工具系统已经具备了:mercurial 、gcc 和 libc6-dev 。如果不确定有没有只需输入下列命令: sudo apt-get install -y mercurial gcc libc6-dev 以上命令实现安装3个必需的工具。 三。配置环境变量。因为第一点的时候我把下载下来的源码解压到/home/pi/go 目录下了,所以将 GOROOT 变量值设置为该路径: export GOROOT=/home/pi/go export GOARCH=arm 但其实不设置的话也是可以的,它默认是等一下命令行执行位置的父目录。 四。也是配置环境变量。 GOARM 变量可以不设置,默认值为:“6″

Approximation to constant “pi” does not get any better after 50 iterations

半腔热情 提交于 2019-12-02 10:52:51
In R I have written this function ifun <- function(m) { o = c() for (k in 1:m) { o[k] = prod(1:k) / prod(2 * (1:k) + 1) } o_sum = 2 * (1 + sum(o)) # Final result print(o_sum) } This function approximates constant pi , however, after m > 50 the approximation gets stuck, i.e. the approximation is the same value and don't get better. How can I fix this? Thanks. Let's go inside: o <- numeric(100) for (k in 1:length(o)) { o[k] = prod(1:k) / prod(2 * (1:k) + 1) } o # [1] 3.333333e-01 1.333333e-01 5.714286e-02 2.539683e-02 1.154401e-02 # [6] 5.328005e-03 2.486402e-03 1.170072e-03 5.542445e-04 2

creating math constants of variable precision using Boost mpfr_float, such as pi or e

蓝咒 提交于 2019-12-02 08:59:58
I am using Boost.Multiprecision for wrappers around the mpfr backend, and I am having some trouble creating pi (and e or any other math constant) to my desired precision. I feel like what I want to do should be possible, because of the use of Boost.Math for constants on a tutorial page for Boost.Multiprecision . In the tutorial, they use fixed-precision numbers of types such as cpp_dec_float_50 -- I want to do it with variable_precision mpfr_float . Check out the following code: #include <boost/multiprecision/mpfr.hpp> #include <boost/math/constants/constants.hpp> #include <iostream> ... int

can't print more decimal of pi [duplicate]

喜你入骨 提交于 2019-12-02 03:53:57
This question already has an answer here: How do I print a double value with full precision using cout? 11 answers I have tried to use long double type in my program to print out more digits of pi. But it only shows 5 digits decimal. Here is my code. int main(int argc, char** argv) { long double pi_18 = acos(static_cast<long double>(-1)); cout << "pi to 18:" << pi_18 << endl; return 0; } and this is my output: pi to 18: 3.14159 How can I fix this problem? Like so: #include <iomanip> #include <iostream> std::cout << std::setw(15) << pi_18 << std::endl; The width modifier only affects the next

segmentation fault in pi calculation (python)

梦想的初衷 提交于 2019-12-02 00:07:07
问题 def pi(times): seq = [] counter = 0 for x in range(times): counter += 2 seq.append("((%f**2)/(%f*%f))*"%(float(counter), float(counter-1), float(counter+1))) seq.append("1.0") seq = "".join(seq) seq = eval(seq) return seq*2 Anywhere past 85000 terms I get a segmentation fault and python quits. How can I avoid this? Why is it crashing? Can't it just please use more memory or something? 回答1: You appear to have found a bug in eval where it can't handle insanely long expressions: >>> eval("1.0*"

How can I get the result with decimal number in division? C++, Pi

佐手、 提交于 2019-12-01 14:37:51
My school give me an assignment to calculate pi. The result should be : Question 4 Accuracy set at : 1000 term pi 1 4 100 3.13159 200 3.13659 300 3.13826 400 ... ... ... The result in my program : term pi 1 4 100 3 200 3 300 3 400 ... ... ... I guess that when I do (4 / denominator), the result will lose the decimal number although I have changed some declarations of data type from int to double. (Some websites tell me to do this.) Maybe I do it wrongly. How can I deal with this problem? The following is my program. #include <iostream> using namespace std; class Four { private: int

How can I get the result with decimal number in division? C++, Pi

ぐ巨炮叔叔 提交于 2019-12-01 12:42:32
问题 My school give me an assignment to calculate pi. The result should be : Question 4 Accuracy set at : 1000 term pi 1 4 100 3.13159 200 3.13659 300 3.13826 400 ... ... ... The result in my program : term pi 1 4 100 3 200 3 300 3 400 ... ... ... I guess that when I do (4 / denominator), the result will lose the decimal number although I have changed some declarations of data type from int to double. (Some websites tell me to do this.) Maybe I do it wrongly. How can I deal with this problem? The

Calculate the function sin()

和自甴很熟 提交于 2019-12-01 04:08:19
问题 For my studies, I have to code an algorithm to calculate sin() with this function: However, in my algorithm, I have to keep the value of X between 0 and Pi/2. So, I wrote my algorithm but all the results are wrong. Here is my code: double sinX(double x){ double resultat = 0; int i; if(x < 0 || x > M_PI_2) x = fmod(x,M_PI_2); for(i = 1;i<=30;i++){ resultat += -1 * ((x*x)/(2*i*(2*i+1)))*(pow(-1,i-1))*((pow(x,2*i-1))/(factorielle(2*i-1))); } return resultat; } I didn't find the reason. Can you

Can a Monte Carlo pi calculation be used for a world record?

ぐ巨炮叔叔 提交于 2019-12-01 00:38:04
I have this random function to calculate pi Monte Carlo style : max=10000000; format long; in = 0; tic for k=1:max x = rand(); y = rand(); if sqrt(x^2 + y^2) < 1 in = in + 1; end end toc calc_pi = 4*in/max epsilon = abs(pi - calc_pi) calcPi(100000000); If I could iterate this 10e100 times, could this algorithm compete with the world record ? If so, how can I find the number of iteration that will give the Nth digit? This is a nice exercise for calculating pi, but it is probably a very inefficient one. Some remarks: My statistics are rusty before I had my coffee, but I guess the error scales

Baking-Pi Challenge - Understanding & Improving

心不动则不痛 提交于 2019-12-01 00:26:50
I spent some time yesterday writing the solution for this challenge published on Reddit , and was able to get through it without cheating, but I was left with a couple of questions. Reference material here . This is my code. (ns baking-pi.core (:import java.math.MathContext)) (defn modpow [n e m] (.modPow (biginteger n) (biginteger e) (biginteger m))) (defn div [top bot] (with-precision 34 :rounding HALF_EVEN (/ (bigdec top) (bigdec bot)))) (defn pow [n e] (.pow (bigdec n) (bigdec e) MathContext/DECIMAL128)) (defn round ([n] (.round (bigdec n) MathContext/DECIMAL128)) ([n & args] (->> [n args]