summaryrefslogtreecommitdiff
path: root/nuttx/libc/math/lib_atan2.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/libc/math/lib_atan2.c')
-rw-r--r--nuttx/libc/math/lib_atan2.c48
1 files changed, 17 insertions, 31 deletions
diff --git a/nuttx/libc/math/lib_atan2.c b/nuttx/libc/math/lib_atan2.c
index f78484d39..5f4a6bff0 100644
--- a/nuttx/libc/math/lib_atan2.c
+++ b/nuttx/libc/math/lib_atan2.c
@@ -41,46 +41,32 @@
#ifdef CONFIG_HAVE_DOUBLE
double atan2(double y, double x)
{
- if (y == 0.0)
+ if (x > 0)
{
- if (x >= 0.0)
- {
- return 0.0;
- }
- else
- {
- return M_PI;
- }
+ return atan(y / x);
}
- else if (y > 0.0)
+ else if (y >= 0 && x < 0)
{
- if (x == 0.0)
- {
- return M_PI_2;
- }
- else if (x > 0.0)
- {
- return atan(y / x);
- }
- else
- {
- return M_PI - atan(y / x);
- }
+ return atan(y / x) + M_PI;
}
- else
+ else if (y < 0)
{
- if (x == 0.0)
- {
- return M_PI + M_PI_2;
- }
- else if (x > 0.0)
+ if (x == 0)
{
- return 2 * M_PI - atan(y / x);
+ return -M_PI_2;
}
- else
+ else /* Can only be x < 0 */
{
- return M_PI + atan(y / x);
+ return atan(y / x) - M_PI;
}
}
+ else if (y > 0 && x == 0)
+ {
+ return M_PI_2;
+ }
+ else if (y == 0 && x == 0) /* Undefined but returns normally 0 */
+ {
+ return 0;
+ }
}
#endif