在C中寻找Pi的算法 [英] algorithm for finding Pi in C

查看:76
本文介绍了在C中寻找Pi的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


见: - http://mathforum.org/library/drmath/view/54456.html

解决方案

aa ***** @ gmail.com 写道:


大家好,


请参阅: - http://mathforum.org/library/drmath/view/54456.html



这对我有用:


#include< float.h>

/ *

** pi ==(atan(1.0 / 3)+ atan(1.0 / 2))* 4

* /

静态双fs_pi(无效);


静态双fs_pi(无效)

{

无符号n;

加倍a,b;

静态双p;

static int initialized;


if(!initialized){

initialized = 1;

n = 1;

a = 3;

do {

a / = 9;

b = a / n;

n + = 2;

a / = 9;

b - = a / n;

n + = 2;

p + = b;

} while(b DBL_EPSILON / 4);

n = 1;

a = 2;

做{

a / = 4;

b = a / n;

n + = 2;

a / = 4;

b - = a / n;

n + = 2;

p + = b;

}而(b DBL_EPSILON / 2);

p * = 4;

}

返回p;

}


-

pete


aa ***** @ gmail.com 说:


大家好,


见: - http://mathforum.org/library/drmath /view/54456.html



大概你想要Pi?简单。它大约是3.


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


5月24日下午2:44 *,Richard Heathfield< r ... @ see.sig.invalidwrote:
< blockquote class =post_quotes>
aark ... @ gmail.com说:


大家好,


见:-http://mathforum.org/library/drmath/view/54456.html



大概你想要Pi ?简单。它大概是3.



所以我们不需要任意无限制 仅限时间和

内存空间精确度?


在所有情况下,3.14都不是更好的答案吗?这就是最普遍的极客b&b。请记住数学课。


并且通常不是#define const?


>

-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - 1999年7月29日dmr


Hi all,

see:- http://mathforum.org/library/drmath/view/54456.html

解决方案

aa*****@gmail.com wrote:

Hi all,

see:- http://mathforum.org/library/drmath/view/54456.html

This works for me:

#include <float.h>
/*
** pi == (atan(1.0 / 3) + atan(1.0 / 2)) * 4
*/
static double fs_pi(void);

static double fs_pi(void)
{
unsigned n;
double a, b;
static double p;
static int initialized;

if (!initialized) {
initialized = 1;
n = 1;
a = 3;
do {
a /= 9;
b = a / n;
n += 2;
a /= 9;
b -= a / n;
n += 2;
p += b;
} while (b DBL_EPSILON / 4);
n = 1;
a = 2;
do {
a /= 4;
b = a / n;
n += 2;
a /= 4;
b -= a / n;
n += 2;
p += b;
} while (b DBL_EPSILON / 2);
p *= 4;
}
return p;
}

--
pete


aa*****@gmail.com said:

Hi all,

see:- http://mathforum.org/library/drmath/view/54456.html

Presumably you want Pi? Easy. It''s about 3.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


On May 24, 2:44*pm, Richard Heathfield <r...@see.sig.invalidwrote:

aark...@gmail.com said:

Hi all,

see:-http://mathforum.org/library/drmath/view/54456.html


Presumably you want Pi? Easy. It''s about 3.

So we doan'' need no arbitrary "unlimited" "limited only by time and
memory space" precision?

Wouldn''t 3.14 be a better answer in all cases? That''s what most
"normal geeks" remember from math class.

And isn''t usually a #define const?

>
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于在C中寻找Pi的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆