Ickiverar 发表于 2026-1-13 21:57:22

可以运行了。

建议把所有数字输出到文件里,不然算完只能看几十位数……

Yi_Zhi_OIer 发表于 2026-1-13 21:59:03

Ickiverar 发表于 2026-1-13 21:57
可以运行了。

建议把所有数字输出到文件里,不然算完只能看几十位数……


Yi_Zhi_OIer 发表于 2026-1-14 07:26:15

更新完了
现在加入要计算100为,输出pi100.txt
pi_calc.exe 100 pi100.txt

Yi_Zhi_OIer 发表于 2026-1-14 15:38:39

Ickiverar 发表于 2026-1-13 21:57
可以运行了。

建议把所有数字输出到文件里,不然算完只能看几十位数……


更新完了

Ickiverar 发表于 2026-1-15 22:06:17

没法计算2G以上的位数
E:\Prog\Test\x64\Release> .\Test.exe 5000000000 r:\1g.txt
Calculating Pi to 2147483647 digits (151431731 terms)...

gxqcn 发表于 2026-1-16 15:50:23

看到高精度库偏爱于计算常数来对标速度,今天我特意在开发中的 HugeCalc 里新增了导出 \(\sqrt2\)、\(e\)、\(\pi\) 指定精度的接口
只是导出接口、及修改相关调用demo程序(实则为测试APP)而已,最核心的大数乘法,尚未完成,所以无法与楼主的算法进行对比

Ickiverar 发表于 2026-1-17 17:33:21

Calculating Pi to 2147483647 digits (151431731 terms)...
BS Phase: 138709s
Sqrt Phase: 1e-07s

我感觉已经寄了,这时间不对吧

做题人生 发表于 2026-1-18 13:16:18

有兴趣学习。建议编辑主贴,把最新版本的 cpp 文件(跳过exe文件以节省网络资源),本网站可能不支持 cpp 附件,可选用 zip, rar, bzip2等压缩格式。期待,谢谢!

Ickiverar 发表于 2026-1-18 23:29:00

PS E:\Prog\Test\x64\Release> .\Test.exe 5000000000 r:\1g.txt
Calculating Pi to 2147483647 digits (151431731 terms)...
BS Phase: 138709s
Sqrt Phase: 1e-07s
Div Phase: 125403s
Result length: 5
31415

算了好几天,就输出个3.1415

做题人生 发表于 2026-1-19 10:20:52

你可能应该把类似的如下的函数定义从头文件中抽取出来,放在独立的 cpp 文件中。 如果有人使用你的库,在多个他自己的 cpp 中包含了你的库的 头文件,就会发生链接错误:同一个函数有多个定义。

// NTT multiplication using 3-moduli CRT with precomputed constants
int precn_mul_ntt(precn_t a, precn_t b, precn_t res) {
    uint64_t as = a->rsiz;
    uint64_t bs = b->rsiz;

    if (as == 0 || bs == 0) {
      precn_set(res, 0);
      return 0;
    }

    size_t n = 1;
    while (n < as + bs) n <<= 1;


如果你极端希望你的库是 head only 的,你也可以假假地把它模板化:

// NTT multiplication using 3-moduli CRT with precomputed constants
// the workhorse that does the actual work. Templatized for head-only
//
namespace _detail{
template <bool>
   int precn_mul_ntt(precn_t a, precn_t b, precn_t res) {
       uint64_t as = a->rsiz;
       uint64_t bs = b->rsiz;
       ...
   }
}
inline int precn_mul_ntt(precn_t a, precn_t b, precn_t res) {
      return _detail::precn_mul_ntt_<true>(a,b,res);
}


Basically the body of a template function or inline function in the header file is unlikely to break the one-definition rule.
页: 1 2 [3] 4
查看完整版本: 自己的高精度库,C++,请求指教