$OpenBSD: patch-src_c_numbers_atan_d,v 1.1 2016/12/28 19:38:56 juanfra Exp $
backport commit 5199c6acd1694211a47dd558220d13fd82265ce0 to fix maxima tests.
--- src/c/numbers/atan.d.orig	Mon Dec 19 12:25:00 2016
+++ src/c/numbers/atan.d	Wed Dec 28 09:12:06 2016
@@ -22,21 +22,23 @@
 static double
 ecl_atan2_double(double y, double x)
 {
-  if (signbit(x)) {
+  if (x == 0) {
     if (signbit(y)) {
-      return -ECL_PI_D + atan(-y / -x);
+      return -ECL_PI2_D;
     } else if (y == 0) {
-      return ECL_PI_D;
+      /* Signals floating-point-invalid-operation. If not trapped,
+         produces NaN. */
+      return x / y;
     } else {
-      return ECL_PI_D - atan(y / -x);
+      return ECL_PI2_D;
     }
-  } else if (x == 0) {
+  } else if (signbit(x)) {
     if (signbit(y)) {
-      return -ECL_PI2_D;
+      return -ECL_PI_D + atan(-y / -x);
     } else if (y == 0) {
-      return x / y;  /* Produces a NaN */
+      return ECL_PI_D;
     } else {
-      return ECL_PI2_D;
+      return ECL_PI_D - atan(y / -x);
     }
   } else {
     if (signbit(y)) {
@@ -53,21 +55,24 @@ ecl_atan2_double(double y, double x)
 static long double
 ecl_atan2_long_double(long double y, long double x)
 {
-  if (signbit(x)) {
+  if (x == 0) {
     if (signbit(y)) {
-      return -ECL_PI_L + atanl(-y / -x);
+      return -ECL_PI2_L;
     } else if (y == 0) {
-      return ECL_PI_L;
+      /* Signals floating-point-invalid-operation. If not trapped,
+         produces NaN. */
+      return x / y;
     } else {
-      return ECL_PI_L - atanl(y / -x);
+      return ECL_PI2_L;
     }
-  } else if (x == 0) {
+  }
+  else if (signbit(x)) {
     if (signbit(y)) {
-      return -ECL_PI2_L;
+      return -ECL_PI_L + atanl(-y / -x);
     } else if (y == 0) {
-      return x / y;  /* Produces a NaN */
+      return ECL_PI_L;
     } else {
-      return ECL_PI2_L;
+      return ECL_PI_L - atanl(y / -x);
     }
   } else {
     if (signbit(y)) {
