mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Fix fist warning
Fix fist warning Signed-off-by: Bensuperpc <bensuperpc@gmail.com>
This commit is contained in:
parent
42958bcedb
commit
13a8698643
@ -10,17 +10,14 @@
|
|||||||
#include <iostream> /// for IO operations
|
#include <iostream> /// for IO operations
|
||||||
#include <type_traits> /// for `static_assert`
|
#include <type_traits> /// for `static_assert`
|
||||||
|
|
||||||
#define MagicNBR_32 0x5f3759df
|
|
||||||
#define MagicNBR_64 0x5fe6eb50c7b537a9
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the function that calculates the fast inverse square root.
|
* @brief This is the function that calculates the fast inverse square root.
|
||||||
* The following code is the fast inverse square root implementation from Quake
|
* The following code is the fast inverse square root implementation from
|
||||||
* III Arena (Adapted for C++)
|
* Quake III Arena (Adapted for C++) More information can be found at
|
||||||
* More information can be found at [Wikipedia](https://en.wikipedia.org/wiki/Fast_inverse_square_root)
|
* [Wikipedia](https://en.wikipedia.org/wiki/Fast_inverse_square_root)
|
||||||
* @tparam T floating type
|
* @tparam T floating type
|
||||||
* @tparam iterations inverse square root, the greater the number of iterations,
|
* @tparam iterations inverse square root, the greater the number of
|
||||||
* the more exact the result will be (1 or 2).
|
* iterations, the more exact the result will be (1 or 2).
|
||||||
* @param x value to calculate
|
* @param x value to calculate
|
||||||
* @return T return inverse square root
|
* @return T return inverse square root
|
||||||
*/
|
*/
|
||||||
@ -35,7 +32,7 @@ inline T Fast_InvSqrt(T x) {
|
|||||||
T y = x;
|
T y = x;
|
||||||
T x2 = y * 0.5;
|
T x2 = y * 0.5;
|
||||||
Tint i = *(Tint *)&y;
|
Tint i = *(Tint *)&y;
|
||||||
i = (sizeof(T) == 8 ? MagicNBR_64 : MagicNBR_32) - (i >> 1);
|
i = (sizeof(T) == 8 ? 0x5fe6eb50c7b537a9 : 0x5f3759df) - (i >> 1);
|
||||||
y = *(T *)&i;
|
y = *(T *)&i;
|
||||||
y = y * (1.5 - (x2 * y * y));
|
y = y * (1.5 - (x2 * y * y));
|
||||||
if (iterations == 2)
|
if (iterations == 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user