home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snipps97.zip / MATHSTAT.H < prev    next >
C/C++ Source or Header  |  1997-07-04  |  4KB  |  107 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  MATHSTAT.H - Header file for statistical analysis in C and C++
  5. **
  6. **  Public domain by Bob Stout
  7. */
  8.  
  9. #include <stddef.h>
  10. #include <math.h>
  11. #include "sniptype.h"
  12.  
  13. #if !(__cplusplus)
  14.  
  15. /*
  16. **  Structure to hold statistical analysis data
  17. **
  18. **  total   = Total of all data added
  19. **  total2  = Total of squares of all data added
  20. **  product = Product of all data added
  21. **  recip   = Total of the reciprocals of all data added
  22. **  count   = Number of data elements under analysis
  23. **  min1    = Minimum datum to date
  24. **  min2    = Next to lowest datum to date
  25. **  oldmin  = Previous value of min1
  26. **  max1    = Maximum datum to date
  27. **  max2    = Next to highest datum to date
  28. **  oldmax  = Previous value of max1
  29. **
  30. **  Notes: min2, oldmin, max2, and oldmax are used when deleting data.
  31. **         If the datum to be deleted is either the highest or lowest to
  32. **         date, it must be replaced with either the previous min/max
  33. **         value (oldmin/oldmax) or the penultimate min/max value (min2/max2).
  34. **         Replacement with the penultimate value is indicated when the
  35. **         previous min/max value was either DBL_MAX or DBL_MIN,
  36. **         respectively, indicating the initialized condition.
  37. **
  38. **         The C++ Stat class works identically to the functions used with
  39. **         the Stat_T structure in C. All members of Stat_T are present as
  40. **         private data objects in the Stat class. All functions associated
  41. **         with Stat_T are duplicated as member functions of class Stat.
  42. **
  43. **         Note that the data are not saved, therefore it is impossible to
  44. **         provide functions such as one to return the median of a data set.
  45. */
  46.  
  47. typedef struct {
  48.       size_t count;
  49.       double total;
  50.       double total2;
  51.       double product;
  52.       double recip;
  53.       double min1, min2, oldmin;
  54.       double max1, max2, oldmax;
  55. } Stat_T;
  56.  
  57. void        stat_init(Stat_T *ptr);
  58. size_t      stat_count(Stat_T *ptr);
  59. size_t      stat_add(double datum, Stat_T *ptr);
  60. size_t      stat_delete(double datum, Stat_T *ptr);
  61. Boolean_T   stat_olympic(Stat_T *ptr);
  62. double      stat_min(Stat_T *ptr);
  63. double      stat_max(Stat_T *ptr);
  64. double      stat_minerror(Stat_T *ptr);
  65. double      stat_maxerror(Stat_T *ptr);
  66. double      stat_mean(Stat_T *ptr);
  67. double      stat_gmean(Stat_T *ptr);
  68. double      stat_hmean(Stat_T *ptr);
  69. double      stat_stddevP(Stat_T *ptr);
  70. double      stat_stddevS(Stat_T *ptr);
  71. double      stat_var(Stat_T *ptr);
  72. double      stat_varcoeffP(Stat_T *ptr);
  73. double      stat_varcoeffS(Stat_T *ptr);
  74.  
  75. #else /* is C++ */
  76.  
  77. class Stat {
  78.       private:
  79.             double            total;
  80.             double            total2;
  81.             double            product;
  82.             double            recip;
  83.             size_t            count;
  84.             double            min1, min2, oldmin;
  85.             double            max1, max2, oldmax;
  86.       public:
  87.             inline            Stat();
  88.             inline size_t     Count();
  89.             size_t            Add(double datum);
  90.             size_t            Delete(double datum);
  91.             Boolean_T         Olympic();
  92.             inline double     Min();
  93.             inline double     Max();
  94.             double            Minerror();
  95.             double            Maxerror();
  96.             double            Mean();
  97.             double            Gmean();
  98.             double            Hmean();
  99.             double            StddevP();
  100.             double            StddevS();
  101.             inline double     Var();
  102.             double            VarcoeffP();
  103.             double            VarcoeffS();
  104. };
  105.  
  106. #endif
  107.