mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Fix warning N2
Fix warning N2 Signed-off-by: Bensuperpc <bensuperpc@gmail.com>
This commit is contained in:
parent
13a8698643
commit
e8fd299668
@ -27,16 +27,17 @@ inline T Fast_InvSqrt(T x) {
|
|||||||
"T must be floating point type");
|
"T must be floating point type");
|
||||||
static_assert(iterations == 1 or iterations == 2,
|
static_assert(iterations == 1 or iterations == 2,
|
||||||
"itarations must equal 1 or 2");
|
"itarations must equal 1 or 2");
|
||||||
typedef typename std::conditional<sizeof(T) == 8, std::int64_t,
|
using Tint = typename std::conditional<sizeof(T) == 8, std::int64_t,
|
||||||
std::int32_t>::type Tint;
|
std::int32_t>::type;
|
||||||
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 ? 0x5fe6eb50c7b537a9 : 0x5f3759df) - (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) {
|
||||||
y = y * (1.5 - (x2 * y * y));
|
y = y * (1.5 - (x2 * y * y));
|
||||||
|
}
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user