xref: /386bsd/usr/include/nonstd/gnu/g++/Normal.h (revision a2142627)
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 _Normal_h
24 #ifdef __GNUG__
25 #pragma once
26 #pragma interface
27 #endif
28 #define _Normal_h
29 
30 #include <Random.h>
31 
32 class Normal: public Random {
33     char haveCachedNormal;
34     double cachedNormal;
35 
36 protected:
37     double pMean;
38     double pVariance;
39     double pStdDev;
40 
41 public:
42     Normal(double xmean, double xvariance, RNG *gen);
43     double mean();
44     double mean(double x);
45     double variance();
46     double variance(double x);
47     virtual double operator()();
48 };
49 
50 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
51 
Normal(double xmean,double xvariance,RNG * gen)52 inline Normal::Normal(double xmean, double xvariance, RNG *gen)
53 : (gen) {
54   pMean = xmean;
55   pVariance = xvariance;
56   pStdDev = sqrt(pVariance);
57   haveCachedNormal = 0;
58 }
59 
mean()60 inline double Normal::mean() { return pMean; };
mean(double x)61 inline double Normal::mean(double x) {
62   double t=pMean; pMean = x;
63   return t;
64 }
65 
variance()66 inline double Normal::variance() { return pVariance; }
variance(double x)67 inline double Normal::variance(double x) {
68   double t=pVariance; pVariance = x;
69   pStdDev = sqrt(pVariance);
70   return t;
71 };
72 
73 #endif
74 #endif
75