Core: Strip off lower bits of sin/cos results.

This commit is contained in:
Unknown W. Brackets 2021-04-24 16:01:19 -07:00
parent cb8745bca8
commit 8f41c78ed7

View File

@ -975,7 +975,9 @@ float vfpu_sin_mod2(float a) {
// This is the value with modulus applied.
val.i = (val.i & 0x80000000) | (k << 23) | (mantissa & ~(1 << 23));
return (float)sin((double)val.f * M_PI_2);
val.f = (float)sin((double)val.f * M_PI_2);
val.i &= 0xFFFFFFFC;
return val.f;
}
float vfpu_cos_mod2(float a) {
@ -1016,6 +1018,7 @@ float vfpu_cos_mod2(float a) {
// This is the value with modulus applied.
val.i = (val.i & 0x80000000) | (k << 23) | (mantissa & ~(1 << 23));
val.f = (float)cos((double)val.f * M_PI_2);
val.i &= 0xFFFFFFFC;
return negate ? -val.f : val.f;
}
@ -1069,13 +1072,29 @@ void vfpu_sincos_mod2(float a, float &s, float &c) {
// This is the value with modulus applied.
val.i = (val.i & 0x80000000) | (k << 23) | (mantissa & ~(1 << 23));
float2int i_sine, i_cosine;
if (negate) {
s = (float)sin((double)-val.f * M_PI_2);
c = -(float)cos((double)val.f * M_PI_2);
i_sine.f = (float)sin((double)-val.f * M_PI_2);
i_cosine.f = -(float)cos((double)val.f * M_PI_2);
} else {
s = (float)sin((double)val.f * M_PI_2);
c = (float)cos((double)val.f * M_PI_2);
double angle = (double)val.f * M_PI_2;
#if defined(__linux__)
double d_sine;
double d_cosine;
sincos(angle, &d_sine, &d_cosine);
i_sine.f = (float)d_sine;
i_cosine.f = (float)d_cosine;
#else
i_sine.f = (float)sin(angle);
i_cosine.f = (float)cos(angle);
#endif
}
i_sine.i &= 0xFFFFFFFC;
i_cosine.i &= 0xFFFFFFFC;
s = i_sine.f;
c = i_cosine.f;
return ;
}
float (*vfpu_sin)(float);