Various fast SQRT

xiaoxiao2021-03-06  99

float mysqrt (float x) {union {int intPart; float floatPart;} convertor; union {int intPart; float floatPart;} convertor2; convertor.floatPart = x; convertor2.floatPart = x; convertor.intPart = 0x1FBCF800 (convertor. INTPART >> 1); convertor2.intpart = 0x5f3759df - (convertor2.intpart >> 1); return 0.5f * (Convertor.FloatPart (x * convertor2.floatpart);} float infsqrt_lomont (float x) {float xhalf = 0.5F * x; int = * (int *) & x; i = 0x5f375a86 - (i >> 1); x = * (float *) & i; x = x * (1.5F-xhalf * x * x); // x = x * (1.5F-xhalf * x * x); // added precision returnix x;} // INVSQRT_LOMontFloat INVSQRT (float x) {float xhalf = 0.5F * x; int = * (int *) & x; i = 0x5f3759df - (i >> 1); x = * (float *) & i; x = x * (1.5F - xhalf * x * x); returnix}

转载请注明原文地址:https://www.9cbs.com/read-102998.html

New Post(0)