本文的理论基础来自是电脑杂志1996年第10期,作者郭继展发表的一篇文章,作者提出一个公式:

{\color{Blue} \pi =16\arctan \left ( \frac{1}{5} \right )-4\arctan \left ( \frac{1}{239} \right )}

在展开成两个级数之和,然后整理得到:

PI=16x(1/5-1/(5^3/3)+1/(5^5/5)-1/(5^7/7)+...)-4x(1/239-1/(239^3/3)+1/(239^5/5)-1/(239^7/7)+...)

=4x(4x5/25-239/57121)/1-4x(4x5/25^2-239/57121^2)/3+4x(4x5/25^3-239/57121^3)/5-

Module PI_Calc_Mod

Implicit None

Integer , public , parameter :: PI_KIND = KIND(1)

Private :: GenPI , Rot

contains

Subroutine CalcPI( nBit , myPI )

Integer , Intent( IN ) :: nBit

integer(Kind=PI_KIND) :: myPI(nBit),bitA(nBit),bitB(nBit),BitAs(nBit),BitBs(nBit),BitPIA(nBit),BitPIB(nBit)

integer :: i

myPI(:)=0

bitA(:)=0

bitB(:)=0

BitAs(:)=0

BitBs(:)=0

BitPIA(:)=0

BitPIB(:)=0

BitAs(2)=3

BitAs(3)=2

BitBs(2)=4

call Rot( nBit , BitBs , bitB , BitBs , 239 )

call GenPI( nBit , myPI , BitBs , BitAs )

Do i = 1 , nBit

call Rot( nBit , BitAs , bitA , BitAs , 25 )

call Rot( nBit , BitAs , bitA , BitPIA , 2*i+1 )

call Rot( nBit , BitBs , bitB , BitBs , 57121 )

call Rot( nBit , BitBs , bitB , BitPIB , 2*i+1 )

if( mod(i,2) == 1 ) then

call GenPI( nBit , myPI , BitPIA , BitPIB )

else

call GenPI( nBit , myPI , BitPIB , BitPIA )

end if

End Do

End Subroutine CalcPI

Subroutine Rot( nBit , nA , nB , nC , nM )

Integer , Intent( IN ) :: nBit , nM

Integer(Kind=PI_KIND) , Intent( INOUT ) :: nA(nBit) , nB(nBit) , nC(nBit)

integer :: i , j

Do i = 2 , nBit

j = mod( nB(i-1) , nM ) * 10 + nA( i )

nC(i) = j / nM

nB(i) = mod( j , nM )

End Do

End Subroutine Rot

Subroutine GenPI( nBit , nPI , npA , npB )

Integer , Intent( IN ) :: nBit

Integer(Kind=PI_KIND) , Intent( INOUT ) :: nPI(nBit) , npA(nBit) , npB(nBit)

integer :: i

nPI(2:nBit)=nPI(2:nBit)+npB(2:nBit)

Do i = nBit , 2 , -1

if( nPI(i) >= npA(i) ) then

nPI(i) = nPI(i) - npA(i)

else

nPI(i) = nPI(i) + 10 - npA(i)

nPI(i-1) = nPI(i-1) - 1

end if

nPI(i-1) = nPI(i-1) + nPI(i) / 10

nPI(i) = mod( nPI(i) , 10 )

End Do

End Subroutine GenPI

End Module PI_Calc_Mod

Program www_fcode_cn

use PI_Calc_Mod

Implicit None

Integer , parameter :: N = 100

integer(Kind=PI_KIND) :: myPI(N)

call CalcPI( N , myPI )

write(*,'(50i1)') myPI

End Program www_fcode_cn

php 圆周率指定位数,计算圆周率 PI 任意位数相关推荐

  1. python计算圆周率_Python实现计算圆周率π的值到任意位的方法示例

    本文实例讲述了Python实现计算圆周率π的值到任意位的方法.分享给大家供大家参考,具体如下: 一.需求分析 输入想要计算到小数点后的位数,计算圆周率π的值. 二.算法:马青公式 π/4=4arcta ...

  2. python计算圆周率近似值_python计算圆周率pi的方法

    本文实例讲述了python计算圆周率pi的方法.分享给大家供大家参考.具体如下: from sys import stdout scale = 10000 maxarr = 2800 arrinit ...

  3. java中怎么引用圆周率_Java简单计算圆周率完整示例

    本文实例讲述了java简单计算圆周率.分享给大家供大家参考,具体如下: 这两天在网上看到一个题,已知pi可以用函数4 * (1 – 1/3 + 1/5 – 1/7 + -) 计算,计算出小数点后五位( ...

  4. python 圆周率,用python计算圆周率π

    用python计算圆周率π 一.要求 1.要起义能计算到圆周率后面越多位越好. 2.用进度条显示计算的进度,能给出越多种进度条越好. 3.要求给出圆周率π的具体公式或者算法说明. 二.算法 1.马青公 ...

  5. java 计算圆周率_java程序计算圆周率

    昨晚波士堂看到王兴背诵圆周率,感到有兴趣了,于是下个txt,圆周率100万位开始背诵,太辛苦,代码实现出来继续背. package com.xjtu.pi; /** * π的随机数算法 * 描述: * ...

  6. c++语言计算圆周率,求C++计算圆周率小数点后10000位的程序,感谢。不知道怎么实现大数...

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 6407655904 2909945681 5065265305 3718294127 0336931378 5178609040 7086671149 ...

  7. Python计算开方、立方、圆周率,精确到小数点后任意位

    Python计算的位数 在电脑上做了一个实验,看看python能计算到多少位,一下是结果. x = math.sqrt((3)) print ("%.53f"%(x)) print ...

  8. python计算圆周率100万位要多久_python圆周率计算小程序(非常慢)

    源码: 1 from math import fabs #导入数学模块 2 3 from time import perf_counter #导入时间模块 4 5 from numba import ...

  9. 如何用python计算圆周率_如何用python计算圆周率?

    如何用python计算圆周率? python计算圆周率的方法: 圆周率没有精确的计算公式,所以只能用近似的方式计算它的近似值. 我们运用蒙特卡罗方法,思路很简单,在下面图形中随机抛置大量的点, 计算落 ...

最新文章

  1. write up: web 前女友(SKCTF)
  2. 【10】48. Rotate Image
  3. mysql语句 查询前5个_MySQL 查询语句--------------进阶5:分组查询
  4. 菜单固定随滚动条滑动
  5. 第六:Pytest中的setup/teardown
  6. 百度搜索大数据:“摆摊技巧”搜索热度暴涨655%;中国电信:将逐步关闭3G网络业务;IntelliJ IDEA新版发布|极客头条...
  7. 数据挖掘实战—基于水色图像的水质评价
  8. 安装项目管理工具 SVN+Redmine
  9. 软件工程课程周学习进度报告——第六周
  10. 【大数据部落】r语言多均线股票价格量化策略回测
  11. 【老生谈算法】matlab实现模拟退火算法——模拟退火算法
  12. C4D插件X-Particles粒子特效(五)
  13. 计算机如何删除用户密码,怎么清除电脑开机密码
  14. matlab中二阶偏导数,MATLAB中带有两个变量的函数的一阶和二阶偏导数
  15. JAVA:实现Blowfish区块加密算法(附完整源码)
  16. WEB前端大作业-速拍摄影服务响应式网页模板(HTML JS CSS))
  17. git版本回退的最佳操作
  18. 百度地图电子围栏判断 地图定位
  19. docker中--privileged的使用
  20. wxWidgets编程指南

热门文章

  1. ps巧用蒙版抠出头发边缘
  2. 从列表中切片最佳英雄组合,我的选择是亚索和李青——补充python基础语法有关数字类型和列表的知识
  3. python数据分析的就业前景_【招聘数据分析】Python就业前景如何
  4. 如何使文章内容自动生成目录
  5. 高净值人群需求拉动高端医疗保险发展,2020年保费收入超百亿[图]
  6. python写节日贺卡_Python什么方法可以通过邮箱发送贺卡或明信片
  7. CAD为什么设置了绘图界限LIMITS看不出来?
  8. python删除列索引_29. Python 删除 更改 索引数据
  9. 外观和样式(04):【参】颜色空间
  10. 资产风险的分类及风险测度理论与方法