请考虑以下最小示例:
h2o.init()
如果#include <stdlib.h>
#include "CGAL\Exact_predicates_exact_constructions_kernel.h"
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::FT NumberType;
int main()
{
int numberOfIterations = 4000;
NumberType sum = 0;
for (int i = 0; i < numberOfIterations; i++)
{
sum += 1;
}
std::cout << "Sum = " << sum << std::endl;
getchar();
return 0;
}
参数采用较小的值,那么一切似乎都可以正常工作。
但是,当将其设置为大于几千的值时,程序将输出numberOfIterations
的正确值,但是在删除记忆(我想)。
我阅读了CGAL documentation on Number Types,但我不清楚发生这种情况的原因。我应该怎么做才能以正确的方式对精确数字进行运算?
这是一个更复杂的示例(如下面的评论所要求),与我的原始问题严格相关:
sum