我尝试使用以下代码片段在 64 位系统上计算阶乘:
long double FactorialLD(long n)
{
long double result = 1;
if (n <= 0)
return 1;
for (long i = 2; i <= n; i++)
result *= i;
return result;
}
30!
返回265252859812191058647452510846976
。但是,使用桌面计算器或https://www.calculatorsoup.com/calculators/discretemathematics/factorials.php返回265252859812191058636308480000000
。为什么会有这么大的差异,是什么原因造成的?
CPU:英特尔x86_64
操作系统:Ubuntu 24.10
编译器:g++ 14.2.0