File tree 1 file changed +9
-6
lines changed
1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -342,19 +342,22 @@ extern const quat_t quatIdentity;
342
342
// https://en.wikipedia.org/wiki/Fast_inverse_square_root#/media/File:2nd-iter.png
343
343
inline float Q_rsqrt ( float number )
344
344
{
345
- float x = 0 .5f * number;
346
- float y;
347
-
348
345
// compute approximate inverse square root
349
346
#if defined(DAEMON_USE_ARCH_INTRINSICS_i686_sse)
347
+ float y;
350
348
// SSE rsqrt relative error bound: 3.7 * 10^-4
351
349
_mm_store_ss ( &y, _mm_rsqrt_ss ( _mm_load_ss ( &number ) ) );
352
350
#else
353
- y = Util::bit_cast<float >( 0x5f3759df - ( Util::bit_cast<uint32_t >( number ) >> 1 ) );
354
- y *= ( 1 .5f - ( x * y * y ) ); // initial iteration
351
+ float x = 0 .5f * number;
352
+ float y = Util::bit_cast<float >( 0x5f3759df - ( Util::bit_cast<uint32_t >( number ) >> 1 ) );
353
+ // initial iteration
355
354
// relative error bound after the initial iteration: 1.8 * 10^-3
355
+ y *= ( 1 .5f - ( x * y * y ) );
356
+ #if 0
357
+ // second iteration for higher precision
358
+ y *= ( 1.5f - ( x * y * y ) );
359
+ #endif
356
360
#endif
357
- y *= ( 1 .5f - ( x * y * y ) ); // second iteration for higher precision
358
361
return y;
359
362
}
360
363
You can’t perform that action at this time.
0 commit comments