婆罗门
精华
|
战斗力 鹅
|
回帖 0
注册时间 2016-3-16
|
本帖最后由 Lunamos 于 2023-11-4 19:47 编辑
随便一个都行吧,copilot直接预测你想写什么注释,用copilot chat生成完整注释,或者直接告诉chatgpt生成注释。
试试给q_rsqrt加注释
float q_rsqrt(float number)
{
long i; // An integer which will be used in a bit-level hack.
float x2, y; // Intermediate floating point variables for calculations.
const float threehalfs = 1.5F; // A constant used in the Newton-Raphson iteration.
x2 = number * 0.5F; // Half of the input number, used in the Newton-Raphson iteration.
y = number; // Start with the input number.
i = * ( long * ) &y; // Bitwise hack: treat the bits of the float as a long int.
i = 0x5f3759df - ( i >> 1 ); // The magic step: a mysterious constant from which we subtract half the bits of 'i'.
y = * ( float * ) &i; // Bitwise hack: treat the modified bit pattern as a float.
// The following line is a single iteration of Newton-Raphson method to refine the estimate:
y = y * ( threehalfs - ( x2 * y * y ) ); // Refine the approximation of the inverse square root.
// An optional second iteration can be used for improved accuracy:
// y = y * ( threehalfs - ( x2 * y * y ) );
return y; // Return the approximate inverse square root.
}
|
|