4 ms·
This reminds me of https://imgur.com/gallery/dZe8k https://imgur.com/gallery/dZe8k :)
by micvbang 5y ago
This reminds me of https://imgur.com/gallery/dZe8k https://imgur.com/gallery/dZe8k :)
- mike_hock 5y ago/** Half the number ** ********************* ** Multiplies the number by one half (0.5) */ float x2 = x * 0.5F; /** Copy the number ** ********************* ** Stores a copy of the number in a new variable */ float y = x; /** Pointer cast ** ****************** ** Take the address of the number, ** cast the pointer to a pointer pointing to long, ** and dereference that pointer, ** then store the result in a new variable. */ long i = * ( long * ) &y; /** Subtract and shift ** ************************ ** Shift the number one bit position to the right, ** then subtract the result from the constant 0x5f3759df */ i = 0x5f3759df - ( i >> 1 ); /** Pointer cast ** ****************** ** Take the address of the number, ** cast the pointer to a pointer pointing to float, ** and dereference that pointer, ** then store the result in an existing variable. */ y = * ( float * ) &i; /** Multiply twice, subtract and multiply again ** ************************************************* ** Multiplies the number by itself, ** then multiplies the result by the other number, ** then subtracts that from the constant three halfs (1.5), ** then multiplies that by the number. ** The original number. ** The first number. ** You know what I mean. */ y = y * ( 1.5F - ( x2 * y * y ) ); /** Multiply twice, subtract and multiply again ** ************************************************* ** Multiplies the number by itself, ** then multiplies the result by the other number, ** then subtracts that from the constant three halfs (1.5), ** then multiplies that by the number. ** The original number. ** The first number. ** You know what I mean. ** This can be removed. */ // y = y * ( 1.5F - ( x2 * y * y ) ); /** Return from function ** ************************** ** Returns the number */ return y;