在浮点数组上使用mpf_set_ui会停止输出(GMP c++)
Using mpf_set_ui on a float array stops output (GMP c++)
对于一个学校项目,我必须进行几次涉及大数字的计算,这就是我选择使用GMP的原因。在我的主程序中遇到奇怪的错误后,我开始在另一个程序中进行实验。以下代码显示了出现的问题:
mpf_set_default_prec(512);
mpf_t t[5];
mpf_init(t[5]);
cout << "This does appear." << endl;
mpf_set_ui(t[4],9);
cout << mpf_get_d(t[4]) << endl;
cout << "This does not, neither is the number 9 printed." << endl;
mpf_clear(t[5]);
因此,所有输出都在mpf_set_ui之后停止。如果我在没有数组的情况下尝试此操作,那么t[5]和t[4]就变成了t,一切都如预期的那样工作。我做错了什么?GMP中是否允许使用阵列?
您可能应该按照以下更改代码
mpf_t t[5];
for(int i = 0; i < 5; ++i) {
mpf_init(t[i]);
}
mpf_set_ui(t[4],9);
cout << mpf_get_d(t[4]) << endl;
for(int i = 0; i < 5; ++i) {
mpf_clear(t[i]);
}
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 输出没有重复元素的动态数组(收缩数组)C++
- 如何根据单词在文本中出现的概率输出单词