diff --git a/src/math.h b/src/math.h index 9802cef8..626b9a6a 100644 --- a/src/math.h +++ b/src/math.h @@ -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)