1.算法来自李永乐老师的课程:
https://www.bilibili.com/video/BV1Bs41177UK/
2.运行环境为linux64位服务器
3.编译命令:gcc main.c -lm -g
4.运行结果(入参为大于等于2的正整数,在17开始就不精确了)
[root@localhost cacu_π]# ./a.out 16
L2n:0.000032, perimeter of 196608.000000 Regular Polygon is 6.283185, value of circular constant:3.14159264532121573765
[root@localhost cacu_π]# ./a.out 17
L2n:0.000016, perimeter of 393216.000000 Regular Polygon is 6.283187, value of circular constant:3.14159366984942689527
5.代码如下
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*First 100 digits of PI:3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679*/
/*
exponent_two_multi_cnt_of_hexagon: Number of sides of polygon = 6 * pow(2, exponent_two_multi_cnt_of_hexagon)
*/