[英]What is accepted as the IEEE-754 correct result when computing this square root?
I have an Newton-Raphson Square Root Algorithm I am using which computes the single-precision square root of an input value. 我有一个Newton-Raphson平方根算法,用于计算输入值的单精度平方根。 However using a testbench I input I found that certain input values don't converge to an answer which is closest to the actual square root.
但是,使用我输入的测试平台,我发现某些输入值未收敛到最接近实际平方根的答案。 When I say actual square root, I mean the result you would get with more precision than 32-bit IEEE-754.
当我说实际的平方根时,我的意思是您得到的结果将比32位IEEE-754更精确。 As a result, I was wondering what is considered the correct value to be obtained when performing the square root in IEEE-754.
结果,我想知道在IEEE-754中执行平方根时,应该获得什么正确的值。 Some people on this forum have told me that the closest value is not necessarily the most correct, that is why I am asking.
这个论坛上的一些人告诉我,最接近的值不一定是最正确的,这就是我要问的原因。
When computing the square root of the single precision IEEE-754 32-bit value 0x3f7fffff, what is considered the correct result and why? 计算单精度IEEE-754 32位值0x3f7fffff的平方根时,什么被认为是正确的结果,为什么?
Furthermore, what is considered the correct result when compute the square root of 0x7F7FFFFF? 此外,计算0x7F7FFFFF的平方根时,什么是正确的结果?
0x3f7fffff
is 1.0 - u
, where u = 2**-24
. 0x3f7fffff
是1.0 - u
,其中u = 2**-24
。 The Taylor Series for sqrt(1 + x)
is: sqrt(1 + x)
的泰勒级数为:
sqrt(1 + x) = 1 + x/2 - x^2/8 + O(x^3)
If we plug -u
in for x
, we get: 如果将
-u
插入x
,则会得到:
sqrt(1 - u) = 1 - u/2 - u^2/8 - O(u^3)
The value 1 - u/2
is the exact halfway point between the two closest representable floating-point numbers, 1-u
and 1
; 值
1 - u/2
是两个最接近的可表示浮点数1-u
和1
之间的精确中间点; since the next term in the Taylor series is negative, the value of sqrt(1 - u)
is just a tiny bit smaller, and so the result rounds down to 1 - u
. 由于泰勒级数的下一项为负,因此
sqrt(1 - u)
值仅小一点,因此结果四舍五入为1 - u
。
0x7f7fffff
is just 2**128*(1-u)
, so the mathematically exact square root is 2**64*(1 - u/2 - u^2/8 - ...)
, which rounds down to 2**64 * (1-u)
, as described above. 0x7f7fffff
仅为2**128*(1-u)
,因此数学上精确的平方根为2**64*(1 - u/2 - u^2/8 - ...)
0x7f7fffff
2**64*(1 - u/2 - u^2/8 - ...)
,四舍五入为2**64 * (1-u)
,如上所述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.