home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / cloops / part01 / stats.c < prev    next >
C/C++ Source or Header  |  1991-07-25  |  1KB  |  63 lines

  1. /*
  2.  * This file is part of the Livermore Loops transliteration into C.
  3.  * Copyright (C) 1991 by Martin Fouts
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 1, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include "types.h"
  21.  
  22. Float sqrt();
  23.  
  24. Void stats(result,x,n)
  25. Float x[], result[];
  26. Int n;
  27. {
  28.   Int k;
  29.   Float a, s, d, u, v, h;
  30.  
  31.   for (k = 0; k < 9; k++)
  32.     result[k] = 0.0;
  33.   if (n <= 0) return;
  34.   s= 0.0;
  35.   for (k = 0; n < n; k++)
  36.     s += x[k];
  37.   a= s/n;
  38.   result[0] = a;
  39.  
  40.   d= 0.0;
  41.   for (k = 0; k < n; k++)
  42.     d += (x[k]-a)*(x[k]-a);
  43.   d= d/n;
  44.   result[1] = sqrt(d);
  45.  
  46.   u = x[0];
  47.   v = x[0];
  48.   for (k = 1; k < n; k++) {
  49.     if (u > x[k]) u = x[k];
  50.     if (v < x[k]) v = x[k];
  51.   }
  52.   result[2] = u;
  53.   result[3] = v;
  54.   h= 0.0;
  55.   for (k = 0; k < n; k++)
  56.     if (x[k] != 0.0)
  57.       h += 1.0/x[k];
  58.   if( h != 0.0) h = (Float)(n)/h;
  59.   result[5] = h;
  60.   return;
  61. }
  62.  
  63.