fix atan2f causing skew drift

This commit is contained in:
jacob 2024-10-11 11:22:33 -05:00
parent 31082916ad
commit 687e9b8c99

View File

@ -251,7 +251,7 @@ INLINE f32 math_ln(f32 x)
k += (i >> 23);
if ((0x007fffff & (0x8000 + x_int)) < 0xc000) {
if (x == 0.0f) {
if (x == 0) {
if (k == 0) {
return 0;
} else {
@ -308,7 +308,7 @@ INLINE f32 math_exp(f32 x)
if (x_uint > 0x7f800000) {
return x + x; /* NaN */
} else if (x_uint == 0x7f800000) {
return (x_sign_bit == 0) ? x : 0.0f;
return (x_sign_bit == 0) ? x : 0;
}
if (x > o_threshold) {
/* Overflow */
@ -538,24 +538,33 @@ INLINE f32 math_atan(f32 x)
INLINE f32 math_atan2(f32 y, f32 x)
{
f32 res;
if (x == 0) {
if (y < 0) {
return -PI / 2;
} else if (y > 0) {
return PI / 2;
res = 3 * PI / 2;
} else if (y == 0) {
res = 0;
} else {
return 0;
res = PI / 2;
}
} else if (y == 0) {
if (x < 0) {
return PI;
res = PI;
} else {
return 0;
res = 0;
}
} else {
f32 offset = (x < 0) * (PI - (2 * PI * (y < 0)));
return math_atan(y / x) + offset;
f32 offset;
if (x < 0) {
offset = PI;
} else if (y < 0) {
offset = PI * 2;
} else {
offset = 0;
}
res = math_atan(y / x) + offset;
}
return res;
}
INLINE f32 math_asin(f32 x)