C++ 大整数 Big Integer

Under ubuntu 14.04 64bit machine

 

1. undefined reference to `__gmpz_init'

加入 -L/gmp_install/lib -lgmp

对于 c++ 需要再加上 -lgmpxx [3]

 

2. 初始化时, 提示 too large number

参考 [2]

 

3. mpz_int 转到 int

搜索了很久, 没有找到合适的转换办法, 靠 mpz_get_ui() 转换编译器报错

受 [3] 启发, 将 mpz_int 换成 mpz_class, 使用 get_ui() 转换成功

看来, c++ 并不是 c 的超集, 将 .c 文件转到 .cpp 有时候是行不通的

 

 

Reference

[1] http://www.boost.org/doc/libs/1_53_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/gmp_int.html

[2] http://stackoverflow.com/questions/15196953/c-boost-large-number-storage

[3] http://zh.wikipedia.org/wiki/GNU%E5%A4%9A%E9%87%8D%E7%B2%BE%E5%BA%A6%E8%BF%90%E7%AE%97%E5%BA%93

[4] http://stackoverflow.com/questions/15483254/cast-mpz-class-to-int

posted @ 2014-05-07 22:02  周卓  阅读(1010)  评论(0编辑  收藏  举报