fix atan2f causing skew drift
This commit is contained in:
parent
31082916ad
commit
687e9b8c99
29
src/math.h
29
src/math.h
@ -251,7 +251,7 @@ INLINE f32 math_ln(f32 x)
|
|||||||
k += (i >> 23);
|
k += (i >> 23);
|
||||||
|
|
||||||
if ((0x007fffff & (0x8000 + x_int)) < 0xc000) {
|
if ((0x007fffff & (0x8000 + x_int)) < 0xc000) {
|
||||||
if (x == 0.0f) {
|
if (x == 0) {
|
||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -308,7 +308,7 @@ INLINE f32 math_exp(f32 x)
|
|||||||
if (x_uint > 0x7f800000) {
|
if (x_uint > 0x7f800000) {
|
||||||
return x + x; /* NaN */
|
return x + x; /* NaN */
|
||||||
} else if (x_uint == 0x7f800000) {
|
} else if (x_uint == 0x7f800000) {
|
||||||
return (x_sign_bit == 0) ? x : 0.0f;
|
return (x_sign_bit == 0) ? x : 0;
|
||||||
}
|
}
|
||||||
if (x > o_threshold) {
|
if (x > o_threshold) {
|
||||||
/* Overflow */
|
/* Overflow */
|
||||||
@ -538,24 +538,33 @@ INLINE f32 math_atan(f32 x)
|
|||||||
|
|
||||||
INLINE f32 math_atan2(f32 y, f32 x)
|
INLINE f32 math_atan2(f32 y, f32 x)
|
||||||
{
|
{
|
||||||
|
f32 res;
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
if (y < 0) {
|
if (y < 0) {
|
||||||
return -PI / 2;
|
res = 3 * PI / 2;
|
||||||
} else if (y > 0) {
|
} else if (y == 0) {
|
||||||
return PI / 2;
|
res = 0;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
res = PI / 2;
|
||||||
}
|
}
|
||||||
} else if (y == 0) {
|
} else if (y == 0) {
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
return PI;
|
res = PI;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f32 offset = (x < 0) * (PI - (2 * PI * (y < 0)));
|
f32 offset;
|
||||||
return math_atan(y / x) + 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)
|
INLINE f32 math_asin(f32 x)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user