Mac OS和Windows之间的exp()精度 [英] exp() precision between Mac OS and Windows

查看:69
本文介绍了Mac OS和Windows之间的exp()精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个代码,当我在Win和Mac OS上运行它们时,结果的精度有所不同,有人可以帮忙吗?

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;

结果均为0.979645005277687,但十六进制不同:

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

Win: 3FEF59407B6B6FF1
Mac: 3FEF59407B6B6FF2

如何获得相同的结果.

推荐答案

如何获得相同的结果.

How Can I get the same result.

除非OS X上的数学库使用完全相同的实现/算法来计算e ^ x,否则您将也不会真正获得完全相同的结果.浮点计算不准确,请处理.

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.

这篇关于Mac OS和Windows之间的exp()精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆