简体   繁体   English

计算平方根时,IEEE-754正确的结果是什么?

[英]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 . 0x3f7fffff1.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-u1之间的精确中间点; 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.

相关问题 在C ++中编写符合IEEE-754标准的双/浮点分区的最快方法是什么? - What is the fastest way to write a IEEE-754 compliant double/float division in C++? 添加 IEEE-754 格式的正数和负数 - Adding positive and negative numbers in IEEE-754 format 为什么IEEE-754浮点数不能在平台之间交换? - Why is IEEE-754 Floating Point not exchangable between platforms? IEEE-754的浮点数,双精度数和四进制数是否保证精确表示-2,-1,-0、0、1、2? - Does IEEE-754 float, double and quad guarantee exact representation of -2, -1, -0, 0, 1, 2? 如何输出IEEE-754格式的整数作为浮点数 - How to output IEEE-754 format integer as a float IEEE-754 浮点指数 Alignment 问题 - IEEE-754 Floating Point Exponent Alignment Issue 符合IEEE-754标准的半圆到偶数 - IEEE-754 compliant round-half-to-even IEEE-754浮点计算,相等和缩小 - IEEE-754 floating point computations, equality and narrowing 返回浮点类型是否完全符合 IEEE-754 的函数? - Function that returns whether the floating-point type is fully compliant to IEEE-754? 如何将float转换为double(都存储在IEEE-754表示中)而不会丢失精度? - How to convert float to double(both stored in IEEE-754 representation) without losing precision?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM