正弦,余弦,棕褐色和舍入误差 [英] sin, cos, tan and rounding error

查看:134
本文介绍了正弦,余弦,棕褐色和舍入误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些三角计算在C / C ++和正在​​运行与舍入误差的问题。例如,在我的Linux系统:

I'm doing some trigonometry calculations in C/C++ and am running into problems with rounding errors. For example, on my Linux system:

#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[]) {
    printf("%e\n", sin(M_PI));
    return 0;
}

此程序给出了下面的输出:

This program gives the following output:

1.224647e-16

在正确的答案当然是0。

when the correct answer is of course 0.

多少舍入误差可以用三角函数的时候我期望?我怎样才能最好地处理这个错误?我熟悉敬陪末座技术的单位比较浮点数,从布鲁斯·道森的比较浮点数,但是这似乎并没有在这里工作,因为0和1.22E-16相当多的ULPS分开。

How much rounding error can I expect when using trig functions? How can I best handle that error? I'm familiar with the Units in Last Place technique for comparing floating point numbers, from Bruce Dawson's Comparing Floating Point Numbers, but that doesn't seem to work here, since 0 and 1.22e-16 are quite a few ULPs apart.

推荐答案

这是IEEE双店尾数52位,而隐领先
一形成了一个53位的数字。在结果的底位错误
因此构成的数字的比例的1/2 ^ 53。你的输出
相同的顺序1.0,以便出来到几乎正好一个的
在10 ^ 16部分(因为53 *日志(2)/日志(10)== 15.9)。

An IEEE double stores 52 bits of mantissa, with the "implicit leading one" forming a 53 bit number. An error in the bottom bit of a result therefore makes up about 1/2^53 of the scale of the numbers. Your output is of the same order as 1.0, so that comes out to just about exactly one part in 10^16 (because 53*log(2)/log(10) == 15.9).

所以,是的。这大约是precision你可以期望的极限。我
不知道你正在使用的ULP技术,但我怀疑你
应用它错了。

So yes. This is about the limit of the precision you can expect. I'm not sure what the ULP technique you're using is, but I suspect you're applying it wrong.

这篇关于正弦,余弦,棕褐色和舍入误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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