Skip to content

Commit f6d637e

Browse files
committed
q_shared: better WTF constant for the Q_rsqrt trick
1 parent d535089 commit f6d637e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/engine/qcommon/q_shared.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ extern const quat_t quatIdentity;
349349
_mm_store_ss( &y, _mm_rsqrt_ss( _mm_load_ss( &number ) ) );
350350
#else
351351
float x = 0.5f * number;
352-
float y = Util::bit_cast<float>( 0x5f3759df - ( Util::bit_cast<uint32_t>( number ) >> 1 ) );
352+
// Original value: 0x5f3759df
353+
// Better value comes from: http://rrrola.wz.cz/inv_sqrt.html
354+
float y = Util::bit_cast<float>( 0x5f1ffff9 - ( Util::bit_cast<uint32_t>( number ) >> 1 ) );
353355
// initial iteration
354356
// relative error bound after the initial iteration: 1.8 * 10^-3
355357
y *= ( 1.5f - ( x * y * y ) );

0 commit comments

Comments
 (0)