Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

dnrm2.c

Go to the documentation of this file.
00001 /* DNRM2.F -- translated by f2c (version 19941215).
00002    You must link the resulting object file with the libraries:
00003         -lf2c -lm   (in that order)
00004 */
00005 
00006 #include "f2c.h"
00007 #include "cblasimpexp.h"
00008 doublereal __IMPEXP__ dnrm2_(n, dx, incx)
00009 integer *n;
00010 doublereal *dx;
00011 integer *incx;
00012 {
00013     /* Initialized data */
00014 
00015     static doublereal zero = 0.;
00016     static doublereal one = 1.;
00017     static doublereal cutlo = 8.232e-11;
00018     static doublereal cuthi = 1.304e19;
00019 
00020     /* Format strings */
00021     static char fmt_30[] = "";
00022     static char fmt_50[] = "";
00023     static char fmt_70[] = "";
00024     static char fmt_110[] = "";
00025 
00026     /* System generated locals */
00027     integer i__1;
00028     doublereal ret_val, d__1;
00029 
00030     /* Builtin functions */
00031     double sqrt();
00032 
00033     /* Local variables */
00034     static doublereal xmax;
00035     static integer next, i, j, ix;
00036     static doublereal hitest, sum;
00037 
00038     /* Assigned format variables */
00039     char *next_fmt;
00040 
00041     /* Parameter adjustments */
00042     --dx;
00043 
00044     /* Function Body */
00045 
00046 /*     euclidean norm of the n-vector stored in dx() with storage */
00047 /*     increment incx . */
00048 /*     if    n .le. 0 return with result = 0. */
00049 /*     if n .ge. 1 then incx must be .ge. 1 */
00050 
00051 /*           c.l.lawson, 1978 jan 08 */
00052 /*     modified to correct failure to update ix, 1/25/92. */
00053 /*     modified 3/93 to return if incx .le. 0. */
00054 
00055 /*     four phase method     using two built-in constants that are */
00056 /*     hopefully applicable to all machines. */
00057 /*         cutlo = maximum of  dsqrt(u/eps)  over all known machines. */
00058 /*         cuthi = minimum of  dsqrt(v)      over all known machines. */
00059 /*     where */
00060 /*         eps = smallest no. such that eps + 1. .gt. 1. */
00061 /*         u   = smallest positive no.   (underflow limit) */
00062 /*         v   = largest  no.            (overflow  limit) */
00063 
00064 /*     brief outline of algorithm.. */
00065 
00066 /*     phase 1    scans zero components. */
00067 /*     move to phase 2 when a component is nonzero and .le. cutlo */
00068 /*     move to phase 3 when a component is .gt. cutlo */
00069 /*     move to phase 4 when a component is .ge. cuthi/m */
00070 /*     where m = n for x() real and m = 2*n for complex. */
00071 
00072 /*     values for cutlo and cuthi.. */
00073 /*     from the environmental parameters listed in the imsl converter */
00074 /*     document the limiting values are as follows.. */
00075 /*     cutlo, s.p.   u/eps = 2**(-102) for  honeywell.  close seconds are 
00076 */
00077 /*                   univac and dec at 2**(-103) */
00078 /*                   thus cutlo = 2**(-51) = 4.44089e-16 */
00079 /*     cuthi, s.p.   v = 2**127 for univac, honeywell, and dec. */
00080 /*                   thus cuthi = 2**(63.5) = 1.30438e19 */
00081 /*     cutlo, d.p.   u/eps = 2**(-67) for honeywell and dec. */
00082 /*                   thus cutlo = 2**(-33.5) = 8.23181d-11 */
00083 /*     cuthi, d.p.   same as s.p.  cuthi = 1.30438d19 */
00084 /*     data cutlo, cuthi / 8.232d-11,  1.304d19 / */
00085 /*     data cutlo, cuthi / 4.441e-16,  1.304e19 / */
00086 
00087     if (*n > 0 && *incx > 0) {
00088         goto L10;
00089     }
00090     ret_val = zero;
00091     goto L300;
00092 
00093 L10:
00094     next = 0;
00095     next_fmt = fmt_30;
00096     sum = zero;
00097     i = 1;
00098     ix = 1;
00099 /*                                                 begin main loop */
00100 L20:
00101     switch ((int)next) {
00102         case 0: goto L30;
00103         case 1: goto L50;
00104         case 2: goto L70;
00105         case 3: goto L110;
00106     }
00107 L30:
00108     if ((d__1 = dx[i], abs(d__1)) > cutlo) {
00109         goto L85;
00110     }
00111     next = 1;
00112     next_fmt = fmt_50;
00113     xmax = zero;
00114 
00115 /*                        phase 1.  sum is zero */
00116 
00117 L50:
00118     if (dx[i] == zero) {
00119         goto L200;
00120     }
00121     if ((d__1 = dx[i], abs(d__1)) > cutlo) {
00122         goto L85;
00123     }
00124 
00125 /*                                prepare for phase 2. */
00126     next = 2;
00127     next_fmt = fmt_70;
00128     goto L105;
00129 
00130 /*                                prepare for phase 4. */
00131 
00132 L100:
00133     ix = j;
00134     next = 3;
00135     next_fmt = fmt_110;
00136     sum = sum / dx[i] / dx[i];
00137 L105:
00138     xmax = (d__1 = dx[i], abs(d__1));
00139     goto L115;
00140 
00141 /*                   phase 2.  sum is small. */
00142 /*                             scale to avoid destructive underflow. */
00143 
00144 L70:
00145     if ((d__1 = dx[i], abs(d__1)) > cutlo) {
00146         goto L75;
00147     }
00148 
00149 /*                     common code for phases 2 and 4. */
00150 /*                     in phase 4 sum is large.  scale to avoid overflow. 
00151 */
00152 
00153 L110:
00154     if ((d__1 = dx[i], abs(d__1)) <= xmax) {
00155         goto L115;
00156     }
00157 /* Computing 2nd power */
00158     d__1 = xmax / dx[i];
00159     sum = one + sum * (d__1 * d__1);
00160     xmax = (d__1 = dx[i], abs(d__1));
00161     goto L200;
00162 
00163 L115:
00164 /* Computing 2nd power */
00165     d__1 = dx[i] / xmax;
00166     sum += d__1 * d__1;
00167     goto L200;
00168 
00169 
00170 /*                  prepare for phase 3. */
00171 
00172 L75:
00173     sum = sum * xmax * xmax;
00174 
00175 
00176 /*     for real or d.p. set hitest = cuthi/n */
00177 /*     for complex      set hitest = cuthi/(2*n) */
00178 
00179 L85:
00180     hitest = cuthi / (real) (*n);
00181 
00182 /*                   phase 3.  sum is mid-range.  no scaling. */
00183 
00184     i__1 = *n;
00185     for (j = ix; j <= i__1; ++j) {
00186         if ((d__1 = dx[i], abs(d__1)) >= hitest) {
00187             goto L100;
00188         }
00189 /* Computing 2nd power */
00190         d__1 = dx[i];
00191         sum += d__1 * d__1;
00192         i += *incx;
00193 /* L95: */
00194     }
00195     ret_val = sqrt(sum);
00196     goto L300;
00197 
00198 L200:
00199     ++ix;
00200     i += *incx;
00201     if (ix <= *n) {
00202         goto L20;
00203     }
00204 
00205 /*              end of main loop. */
00206 
00207 /*              compute square root and adjust for scaling. */
00208 
00209     ret_val = xmax * sqrt(sum);
00210 L300:
00211     return ret_val;
00212 } /* dnrm2_ */
00213 

Generated on Wed Sep 5 12:54:20 2007 for DSACSS Operational Code by  doxygen 1.3.9.1