exp() precision between Mac OS and Windows

拥有回忆 提交于 2019-12-20 04:06:04

问题


I got a code here, and when I run them on Win and Mac OS, the precision of the results is different, anyone can help?

const double c = 1 - exp(-2.0);
double x = (139 + 0.5) / 2282.0;
x = ( 1 - exp(-2 * (1 - x))) / c;

The results are both 0.979645005277687, but the Hex are different:

Win: 3FEF59407B6B6FF1
Mac: 3FEF59407B6B6FF2

How Can I get the same result.


回答1:


How Can I get the same result.

Unless the math library on OS X uses the very same implementation/algorithm for calculating e ^ x, you won't and can't really get exactly the same results. Floating-point calculations aren't exact, deal with it.



来源:https://stackoverflow.com/questions/15216884/exp-precision-between-mac-os-and-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!