chiark / gitweb /
max/min macros are already defined(!) by stdlib.h(!) in visual studio; thanks to...
[nlopt.git] / luksan / plis.c
index 8e4c0e6886b1da4bc1e86d5dac2fd133ba1d5a6e..925895399d23d4f33e95237aeb684af8df9afea0 100644 (file)
@@ -4,8 +4,8 @@
 #include <string.h>
 #include "luksan.h"
 
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#define min(a,b) ((a) < (b) ? (a) : (b))
+#define MAX2(a,b) ((a) > (b) ? (a) : (b))
+#define MIN2(a,b) ((a) < (b) ? (a) : (b))
 
 /* *********************************************************************** */
 /* SUBROUTINE PLIS               ALL SYSTEMS                   01/09/22 */
@@ -287,9 +287,9 @@ L11130:
     }
 /* Computing MIN */
     i__1 = stat_1->nit - kit;
-    k = min(i__1,*mf);
+    k = MIN2(i__1,*mf);
     if (k <= 0) {
-       irest = max(irest,1);
+       irest = MAX2(irest,1);
        goto L12620;
     }
 
@@ -297,7 +297,7 @@ L11130:
 
     b = luksan_mxudot__(nf, &xo[1], &go[1], &ix[1], &kbf);
     if (b <= 0.) {
-       irest = max(irest,1);
+       irest = MAX2(irest,1);
        goto L12620;
     }
     uo[1] = 1. / b;
@@ -314,7 +314,7 @@ L11130:
     snorm = sqrt(luksan_mxudot__(nf, &s[1], &s[1], &ix[1], &kbf));
 /* Computing MIN */
     i__1 = k + 1;
-    k = min(i__1,*mf);
+    k = MIN2(i__1,*mf);
     luksan_mxdrsu__(nf, &k, &xo[1], &go[1], &uo[1]);
 L12620:
     iterd = 0;
@@ -347,14 +347,14 @@ L12620:
 /*     TEST ON DESCENT DIRECTION */
 
        if (snorm <= 0.) {
-           irest = max(irest,1);
+           irest = MAX2(irest,1);
        } else if (p + told * gnorm * snorm <= 0.) {
            irest = 0;
        } else {
 
 /*     UNIFORM DESCENT CRITERION */
 
-           irest = max(irest,1);
+           irest = MAX2(irest,1);
        }
        if (irest == 0) {
 
@@ -364,7 +364,7 @@ L12620:
            rmin = alf1 * gnorm / snorm;
 /* Computing MIN */
            d__1 = alf2 * gnorm / snorm, d__2 = *xmax / snorm;
-           rmax = min(d__1,d__2);
+           rmax = MIN2(d__1,d__2);
        }
     }
     if (*iterm != 0) {
@@ -400,7 +400,7 @@ L11174:
        p = po;
        luksan_mxvcop__(nf, &xo[1], &x[1]);
        luksan_mxvcop__(nf, &go[1], &gf[1]);
-       irest = max(irest,1);
+       irest = MAX2(irest,1);
        ld = kd;
        goto L11130;
     }
@@ -446,13 +446,13 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
        and we'll assume that the main limiting factor is the memory.
        We'll assume that at least MEMAVAIL memory, or 4*n memory, whichever
        is bigger, is available. */
-     mf = max(MEMAVAIL/n, 4);
+     mf = MAX2(MEMAVAIL/n, 4);
      if (stop->maxeval && stop->maxeval <= mf)
-         mf = max(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+         mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
 
  retry_alloc:
-     work = (double*) malloc(sizeof(double) * (n * 4 + max(n,n*mf)*2 + 
-                                              max(n,mf)*2));
+     work = (double*) malloc(sizeof(double) * (n * 4 + MAX2(n,n*mf)*2 + 
+                                              MAX2(n,mf)*2));
      if (!work) { 
          if (mf > 0) {
               mf = 0; /* allocate minimal memory */
@@ -463,8 +463,8 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
      }
 
      xl = work; xu = xl + n; gf = xu + n; s = gf + n; 
-     xo = s + n; go = xo + max(n,n*mf);
-     uo = go + max(n,n*mf); vo = uo + max(n,mf);
+     xo = s + n; go = xo + MAX2(n,n*mf);
+     uo = go + MAX2(n,n*mf); vo = uo + MAX2(n,mf);
 
      for (i = 0; i < n; ++i) {
          int lbu = lb[i] <= -0.99 * HUGE_VAL; /* lb unbounded */
@@ -478,7 +478,7 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
        original Fortran code, but it is used upon
        input to plis if mf > 0 ... perhaps ALLOCATE initializes
        arrays to zero by default? */
-     memset(xo, 0, sizeof(double) * max(n,n*mf));
+     memset(xo, 0, sizeof(double) * MAX2(n,n*mf));
 
      plis_(&n, &nb, x, ix, xl, xu, 
           gf, s, xo, go, uo, vo,