快速计算浮点数平方根的 C 代码实现 - 牛顿-拉弗森迭代法
float calc( float number ) {
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y;
i = 0x5f3759df - ( i >> 1 );
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) );
y = y * ( threehalfs - ( x2 * y * y ) );
return y;
}
这个函数实现的是快速计算浮点数的平方根。它使用了一种名为'牛顿-拉弗森迭代法'的算法,通过迭代逼近平方根的值,从而快速计算出给定浮点数的平方根。
原文地址: https://www.cveoy.top/t/topic/lfph 著作权归作者所有。请勿转载和采集!