NEURON
RNG.h
Go to the documentation of this file.
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 the GNU C++ Library. This library is free
7 software; you can redistribute it and/or modify it under the terms of
8 the GNU Library General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version. This library is distributed in the hope
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #ifndef _RNG_h
19 #define _RNG_h 1
20 #ifdef __GNUG__
21 //#pragma interface
22 #endif
23 
24 
25 /*
26  * int32_t and uint32_t have been defined by the configure procedure. Just
27  * use these in place of the ones that libg++ used to provide.
28  */
29 #if defined(HAVE_INTTYPES_H)
30 #include <inttypes.h>
31 #elif defined(HAVE_SYS_TYPES_H)
32 #include <sys/types.h>
33 #elif defined(HAVE__G_CONFIG_H)
34 #include <_G_config.h>
35 typedef _G_int32_t int32_t;
36 typedef _G_uint32_t uint32_t;
37 #endif
38 
39 #include <assert.h>
40 #include <math.h>
41 
42 union PrivateRNGSingleType { // used to access floats as unsigneds
43  float s;
45 };
46 
47 union PrivateRNGDoubleType { // used to access doubles as unsigneds
48  double d;
49  uint32_t u[2];
50 };
51 
52 //
53 // Base class for Random Number Generators. See ACG and MLCG for instances.
54 //
55 class RNG {
56  static PrivateRNGSingleType singleMantissa; // mantissa bit vector
57  static PrivateRNGDoubleType doubleMantissa; // mantissa bit vector
58 public:
59  RNG();
60  virtual ~RNG();
61  //
62  // Return a long-words word of random bits
63  //
64  virtual uint32_t asLong() = 0;
65  virtual void reset() = 0;
66  //
67  // Return random bits converted to either a float or a double
68  //
69  virtual float asFloat();
70  virtual double asDouble();
71 };
72 
73 #endif
Definition: RNG.h:55
static PrivateRNGDoubleType doubleMantissa
Definition: RNG.h:57
uint32_t u
Definition: RNG.h:44
static PrivateRNGSingleType singleMantissa
Definition: RNG.h:56
uint uint32_t
#define int32_t
Definition: nrnconf.h:1