Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 10, 2020
1 parent 737eb2c commit cbdd9da
Showing 1 changed file with 21 additions and 57 deletions.
78 changes: 21 additions & 57 deletions Core/MIPS/MIPSVFPUUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,78 +35,42 @@ inline int Xpose(int v) {
#endif

// The VFPU uses weird angles where 4.0 represents a full circle. This makes it possible to return
// exact 1.0/-1.0 values at certain angles.

// Some games depend on exact values, but sinf() and cosf() aren't always precise.
// exact 1.0/-1.0 values at certain angles. We get close enough for #2921 and #12900 by computing
// things in double precision, multiplying the input by pi/2.
//
// A better solution would be to tailor some sine approximation for the 0..90 degrees range, compute
// modulo manually and mirror that around the circle. Also correctly special casing for inf/nan inputs
// and just trying to match it as closely as possible to the real PSP.
//
// Stepping down to [0, 2pi) helps, but we also check common exact-result values.
// TODO: cos(1) and sin(2) should be -0.0, but doing that gives wrong results (possibly from floorf.)

// Messing around with the modulo functions? try https://www.desmos.com/calculator.
inline float vfpu_sin(float angle_f) {
double angle = angle_f;
/*
angle -= floor(angle * 0.25) * 4.;
if (angle == 0.0f || angle == 2.0) {
return 0.0f;
} else if (angle == 1.0f) {
return 1.0f;
} else if (angle == 3.0f) {
return -1.0f;
}
*/
angle *= M_PI_2;
return (float)sin(angle);

inline float vfpu_sin(float angle) {
return (float)sin((double)angle * M_PI_2);
}

inline float vfpu_cos(float angle_f) {
double angle = angle_f;
/*
angle -= floor(angle * 0.25) * 4.;
if (angle == 1.0 || angle == 3.0) {
return 0.0f;
} else if (angle == 0.0) {
return 1.0f;
} else if (angle == 2.0) {
return -1.0f;
}
*/
angle *= (float)M_PI_2;
return (float)cos(angle);
inline float vfpu_cos(float angle) {
return (float)cos((double)angle * M_PI_2);
}

inline float vfpu_asin(float angle) {
return asinf(angle) / M_PI_2;
}

inline void vfpu_sincos(float angle_f, float &sine, float &cosine) {
double angle = (double)angle_f;
/*
angle -= floor(angle * 0.25) * 4.;
if (angle == 0.0f) {
sine = 0.0f;
cosine = 1.0f;
} else if (angle == 1.0f) {
sine = 1.0f;
cosine = 0.0f;
} else if (angle == 2.0f) {
sine = 0.0f;
cosine = -1.0f;
} else if (angle == 3.0f) {
sine = -1.0f;
cosine = 0.0f;
} else {
*/
angle *= M_PI_2;
double angle = (double)angle_f * M_PI_2;
#if defined(__linux__)
double d_sine;
double d_cosine;
sincos(angle, &d_sine, &d_cosine);
sine = (float)d_sine;
cosine = (float)d_cosine;
double d_sine;
double d_cosine;
sincos(angle, &d_sine, &d_cosine);
sine = (float)d_sine;
cosine = (float)d_cosine;
#else
sine = (float)sin(angle);
cosine = (float)cos(angle);
sine = (float)sin(angle);
cosine = (float)cos(angle);
#endif
// }
}

inline float vfpu_clamp(float v, float min, float max) {
Expand Down

0 comments on commit cbdd9da

Please sign in to comment.