为什么我们需要IEEE 754余数? [英] Why do we need IEEE 754 remainder?

查看:116
本文介绍了为什么我们需要IEEE 754余数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读了该主题(尤其是最后的评论).

I just read this topic (especially the last comments).

然后我在想,为什么我们真正需要这个是剩下的.但是,似乎没有多少人在Google上"对它感兴趣……

Then I was wondering, why we actually need this was of giving the remainder. But it seems, that not many people "on google" were interested in that before...

推荐答案

如果您正在寻找自己想要的原因,那就是所谓的范围缩小"

If you're looking for reasons why you would want it, one is for what is known as "range reduction"

假设您要使用sind函数来计算参数的正弦值(以度为单位).做到这一点的一种天真的方法是

Let's say you want sind function for computing the sine of an argument in degrees. A naive way to do this would be

sind(x) = sin(x*pi/180) 

但是,这里的pi不是真正的无理数pi,而是最接近pi的浮点数.这会导致诸如sind(180) == 1.2246467991473532e-16之类的问题,以及诸如(还有很多) ).

However pi here is not the true irrational number pi, but instead the floating point number closest to pi. This leads to things like sind(180) == 1.2246467991473532e-16, and SO questions like this and this (and many, many more).

但是正弦是周期函数,所以如果我们计算

But sine is a periodic function, so if we compute

remainder(x,90.0)

我们得到一个在间隔[-45,45]上的值.请注意,0、90、180、270等正好变为0,并且乘以pi/180仍为0.因此,使用带正负号的sincos,我们可以在这些值处获得准确的结果(以及如果您进行了一些基本的错误分析,则可以证明它还可以减少其他值的错误.

we get a value on the interval [-45,45]. Note that 0, 90, 180, 270, etc. become exactly 0, and multiplying by pi/180 is still 0. Therefore taking the appropriately signed sin or cos, we can get the exact result at these values (and if you do some basic error analysis, you can demonstrate that it also reduces the error at other values).

两个跟进点:

  1. 如何确定要使用哪个sincos?嗯,这就是 remquo 的目的.
  2. 不幸的是,由于中间舍入的变化,这仍然不能准确给出sind(30.0) == 0.5.有多种方法可以解决此问题,例如请参阅 Julia库所做的.
  3. >
  1. How do you determine which sin or cos to use? Well, that's what remquo is for.
  2. Unfortunately, this still won't give sind(30.0) == 0.5 exactly, due to the vagaries of intermediate rounding. There are ways to fix this, e.g. see what the Julia library does.

这篇关于为什么我们需要IEEE 754余数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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