【发布时间】:2010-10-24 02:01:48
【问题描述】:
我们应该使用这种公式来计算 e^x:
e^x = 1 + (x ^ 1 / 1!) + (x ^ 2 / 2!) ......
到目前为止我有这个代码:
while (result >= 1.0E-20 )
{
power = power * input;
factorial = factorial * counter;
result = power / factorial;
eValue += result;
counter++;
iterations++;
}
我现在的问题是,由于阶乘是 long long 类型,我不能真正存储大于 20 的数字!所以发生的事情是程序在到达那个点时输出有趣的数字..
正确解的 X 值最多为 709,因此 e^709 应输出:8.21840746155e+307
程序是用 C++ 编写的。
【问题讨论】:
-
为什么不把阶乘变成双倍呢?
标签: c++ math exponential