/// <summary> /// Calculates a fast approximation of the square root of the specified number. /// </summary> /// <param name="value">A number.</param> /// <returns>Approximated square root of the number.</returns> public static float FastSqrt(float value) { Int32Single u = new Int32Single(); u.f = value; u.i = (1 << 29) + (u.i >> 1) - (1 << 22) - 0x4C000; return(u.f); }
/// <summary> /// Calculates a fast approximation of the reciprocal of the square root of the specified number. /// </summary> /// <param name="value">A number.</param> /// <returns>Approximated reciprocal of the square root of the number.</returns> public static float FastInvSqrt(float value) { Int32Single u = new Int32Single(); u.f = value; u.i = 0x5F3759DF - (u.i >> 1); return((1.5f - value * 0.5f * u.f * u.f) * u.f); }