Skip to content

Commit

Permalink
Fix math headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ribbanya committed Jan 27, 2024
1 parent 88e1e8e commit 3c85df6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
18 changes: 18 additions & 0 deletions src/MSL/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ static inline f32 fabs_inline(f32 x)
}
}

inline float sqrtf_accurate(float x)
{
volatile float y;
if (x > 0.0f) {
double guess = __frsqrte((double) x); // returns an approximation to
guess =
0.5 * guess * (3.0 - guess * guess * x); // now have 12 sig bits
guess =
0.5 * guess * (3.0 - guess * guess * x); // now have 24 sig bits
guess =
0.5 * guess * (3.0 - guess * guess * x); // now have 32 sig bits
guess = 0.5 * guess * (3.0 - guess * guess * x); // extra iteration
y = (float) (x * guess);
return y;
}
return x;
}

double frexp(double x, int* exponent);
double fabsf__Ff(double);
float tanf(float x);
Expand Down
10 changes: 7 additions & 3 deletions src/MSL/trigf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

#include <platform.h>

f32 tanf(f32);
f32 cosf(f32);
f32 sinf(f32);
float acosf(float);
float asinf(float);
float atan2f(float y, float x);
float atanf(float);
float cosf(float);
float sinf(float);
float tanf(float);

#endif
2 changes: 1 addition & 1 deletion src/melee/it/items/itluigifireball.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "it/it_2725.h"
#include "it/itCommonItems.h"
#include "it/item.h"
#include "lb/lbvector.h"

#include <common_structs.h>
#include <math.h>
#include <dolphin/mtx/vec.h>
#include <baselib/gobj.h>

Expand Down
1 change: 1 addition & 0 deletions src/melee/lb/lbcollision.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <dolphin/mtx/mtxvec.h>
#include <dolphin/mtx/types.h>
#include <baselib/baselib_shared_data_003.h>
#include <baselib/cobj.h>
#include <baselib/debug.h>
#include <baselib/jobj.h>
#include <baselib/mtx.h>
Expand Down
20 changes: 0 additions & 20 deletions src/melee/lb/lbvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,4 @@ Vec3* lbVector_WorldToScreen(HSD_CObj* cobj, const Vec3* pos3d,
void lbVector_CreateEulerMatrix(Mtx m, Vec3* angles);
float lbVector_8000E838(Vec3* a, Vec3* b, Vec3* c, Vec3* d);

/// @todo Doesn't belong here.
/// Exactly the same as the one from math.h, but with one extra iteration
static inline float sqrtf_accurate(float x)
{
volatile float y;
if (x > 0.0f) {
double guess = __frsqrte((double) x); // returns an approximation to
guess =
0.5 * guess * (3.0 - guess * guess * x); // now have 12 sig bits
guess =
0.5 * guess * (3.0 - guess * guess * x); // now have 24 sig bits
guess =
0.5 * guess * (3.0 - guess * guess * x); // now have 32 sig bits
guess = 0.5 * guess * (3.0 - guess * guess * x); // extra iteration
y = (float) (x * guess);
return y;
}
return x;
}

#endif
1 change: 0 additions & 1 deletion src/sysdolphin/baselib/cobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "class.h"
#include "debug.h"
#include "displayfunc.h"
#include "fobj.h"
#include "initialize.h"
#include "mtx.h"
#include "video.h"
Expand Down
2 changes: 2 additions & 0 deletions src/sysdolphin/baselib/jobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "spline.h"

#include <__mem.h>
#include <math.h>
#include <trigf.h>
#include <dolphin/mtx/mtxvec.h>
#include <dolphin/mtx/vec.h>
#include <dolphin/os.h>
Expand Down

0 comments on commit 3c85df6

Please sign in to comment.