Skip to content

Commit

Permalink
More precision
Browse files Browse the repository at this point in the history
  • Loading branch information
sum2012 committed Nov 23, 2020
1 parent 16e54c6 commit 61a97f1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Core/MIPS/MIPSVFPUUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once
#include <cmath>
#include <math.h>

#include "Common/CommonTypes.h"
#include "Core/MIPS/MIPS.h"
Expand Down Expand Up @@ -47,29 +48,31 @@ inline int Xpose(int v) {

// Messing around with the modulo functions? try https://www.desmos.com/calculator.

const u32 test = 309;

inline float vfpu_sin(float angle) {
return (float)sin((double)angle * M_PI_2);
return (float)(round(pow(10, test)*(float)sin((double)angle * M_PI_2)) / pow(10, test));
}

inline float vfpu_cos(float angle) {
return (float)cos((double)angle * M_PI_2);
return (float)(round(pow(10, test) * (float)cos((double)angle * M_PI_2)) / pow(10, test));
}

inline float vfpu_asin(float angle) {
return asinf(angle) / M_PI_2;
return (float)round(pow(10, test) * asinf(angle) / M_PI_2) / pow(10, test);
}

inline void vfpu_sincos(float angle_f, float &sine, float &cosine) {
double angle = (double)angle_f * M_PI_2;
double angle = (double)(round(pow(10, test) * (double)angle_f * M_PI_2) / pow(10, test));
#if defined(__linux__)
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)(round(pow(10, test) * (float)sin(angle)) / pow(10, test));
cosine = (float)(round(pow(10, test) * (float)cos(angle)) / pow(10, test));
#endif
}

Expand Down

0 comments on commit 61a97f1

Please sign in to comment.