home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0639.ZIP / CCE_0639 / GPP / GXXINC.ZOO / xhypgeom.h < prev    next >
C/C++ Source or Header  |  1991-07-09  |  2KB  |  79 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23. #ifndef _HyperGeometric_h
  24. #ifdef __GNUG__
  25. #pragma once
  26. #pragma interface
  27. #endif
  28. #define _HyperGeometric_h 
  29.  
  30. #include <xrandom.h>
  31.  
  32. class HyperGeometric: public Random {
  33. protected:
  34.     double pMean;
  35.     double pVariance;
  36.     double pP;
  37.     void setState();
  38.  
  39. public:
  40.     HyperGeometric(double mean, double variance, RNG *gen);
  41.  
  42.     double mean();
  43.     double mean(double x);
  44.     double variance();
  45.     double variance(double x);
  46.  
  47.     virtual double operator()();
  48. };
  49.  
  50. #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
  51.  
  52. inline void HyperGeometric::setState() {
  53.   double z = pVariance / (pMean * pMean);
  54.   pP = 0.5 * (1.0 - sqrt((z - 1.0) / ( z + 1.0 )));
  55. }
  56.  
  57. inline HyperGeometric::HyperGeometric(double mean, double variance, RNG *gen)
  58. : (gen) {
  59.   pMean = mean; pVariance = variance;
  60.   setState();
  61. }
  62.  
  63. inline double HyperGeometric::mean() { return pMean; };
  64.  
  65. inline double HyperGeometric::mean(double x) {
  66.   double t = pMean; pMean = x;
  67.   setState(); return t;
  68. }
  69.  
  70. inline double HyperGeometric::variance() { return pVariance; }
  71.  
  72. inline double HyperGeometric::variance(double x) {
  73.   double t = pVariance; pVariance = x;
  74.   setState(); return t;
  75. }
  76.  
  77. #endif
  78. #endif
  79.