NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
arithmetic.hpp
Go to the documentation of this file.
1
#pragma once
2
#include <types.h>
3
/// @file
4
5
namespace
nw4r {
6
namespace
math
{
7
8
/// @brief Computes the inverse square root of the given value.
9
float
FrSqrt
(
float
x);
10
11
/// @brief Computes the square root of the given value.
12
inline
float
FSqrt
(
float
x) {
13
return
(x <= 0) ? 0.0f : x *
FrSqrt
(x);
14
}
15
16
/// @brief Computes 1 / n efficiently with fres + 1 Newton iteration
17
inline
float
FInv
(
register
float
n) {
18
register
float
x0, tmp1, tmp2;
19
asm
{
20
// Approximate with fres, then use Newton iteration (https://cr.yp.to/2005-590/powerpc-cwg.pdf 3.3.6.3)
21
// https://en.wikipedia.org/wiki/Division_algorithm#Newton%E2%80%93Raphson_division
22
// Want to calculate x_1 = 2 * x_0 - n * x_0 ^ 2
23
24
fres x0, n
25
26
ps_add tmp1, x0, x0
// tmp1 = 2 * x_0
27
ps_mul tmp2, x0, x0
// tmp2 = x_0 ^ 2
28
ps_nmsub x0, n, tmp2, tmp1
// x_1 = -(n * tmp2 - tmp1) = tmp1 - n * tmp2
29
}
30
31
return
x0;
32
}
33
34
}
// namespace math
35
}
// namespace nw4r
nw4r::math
Math library.
Definition
aabb.hpp:6
nw4r::math::FSqrt
float FSqrt(float x)
Computes the square root of the given value.
Definition
arithmetic.hpp:12
nw4r::math::FInv
float FInv(register float n)
Computes 1 / n efficiently with fres + 1 Newton iteration.
Definition
arithmetic.hpp:17
nw4r::math::FrSqrt
float FrSqrt(float x)
Computes the inverse square root of the given value.
include
lib
nw4r
math
arithmetic.hpp
Made with ❤️ by
CLF78
and
RootCubed
. Logos by
Chasical
and
B1
. Website generated by
Doxygen
1.13.2