在 C++ 中实现mySqrt函数时,我使用了 exp() 函数,如下所示:
int mySqrt(int x) {
// For x = 2147395600
cout << exp(0.5*log(x)) << " "; // It prints 46340
return exp(0.5*log(x)); // But returns 46339
}
Run Code Online (Sandbox Code Playgroud)
我试图用谷歌搜索这种行为的原因,但找不到任何东西。我什至尝试使用double但仍然是相同的输出。
对此有什么解释吗?