NEST  2.6.0,not_revisioned_source_dir@0
numerics.h
Go to the documentation of this file.
1 /*
2  * numerics.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef NUMERICS_H
24 #define NUMERICS_H
25 
26 #include <limits>
27 #include <cmath>
28 
29 #if HAVE_EXPM1
30 # include <math.h>
31 #endif
32 
33 namespace numerics {
34 
35  extern const double e;
36  extern const double pi;
37 
41  inline
42  double expm1(double x)
43  {
44 #if HAVE_EXPM1
45  return ::expm1(x); // use library implementation if available
46 #else
47  // compute using Taylor series, see GSL
48  // e^x-1 = x + x^2/2! + x^3/3! + ...
49  if ( x == 0 )
50  return 0;
51  if ( std::abs(x) > std::log(2.0) )
52  return std::exp(x) - 1;
53  else
54  {
55  double sum = x;
56  double term = x*x/2;
57  long n = 2;
58 
59  while ( std::abs(term) >
60  std::abs(sum) * std::numeric_limits<double>::epsilon() )
61  {
62  sum += term;
63  ++n;
64  term *= x/n;
65  }
66 
67  return sum;
68  }
69 #endif
70  }
71 
72 }
73 
74 
75 // later also in namespace
83 long ld_round(double);
84 
92 double dround(double);
93 
97 double dtruncate(double);
98 
99 
100 # endif
long ld_round(double)
Round to nearest int, rounding midpoints upwards.
Definition: numerics.cpp:83
double expm1(double x)
Supply expm1() function independent of system.
Definition: numerics.h:42
const double pi
Definition: numerics.cpp:63
double dround(double)
Round to nearest int, rounding midpoints upwards.
Definition: numerics.cpp:88
const Name x("x")
current scaling factor of the synaptic weight [0...1] (Tsodyks2_connection)
Definition: nest_names.h:356
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
double dtruncate(double)
Return integer part of argument.
Definition: numerics.cpp:93
const double e
Definition: numerics.cpp:62