File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 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;
342342 // https://en.wikipedia.org/wiki/Fast_inverse_square_root#/media/File:2nd-iter.png
343343 inline float Q_rsqrt ( float number )
344344 {
345- float x = 0 .5f * number;
346- float y;
347-
348345 // compute approximate inverse square root
349346#if defined(DAEMON_USE_ARCH_INTRINSICS_i686_sse)
347+ float y;
350348 // SSE rsqrt relative error bound: 3.7 * 10^-4
351349 _mm_store_ss ( &y, _mm_rsqrt_ss ( _mm_load_ss ( &number ) ) );
352350#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
355354 // 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
356360#endif
357- y *= ( 1 .5f - ( x * y * y ) ); // second iteration for higher precision
358361 return y;
359362 }
360363
You can’t perform that action at this time.
0 commit comments