NEURON
rxdmath.cpp
Go to the documentation of this file.
1 #include <math.h>
2 #ifndef M_PI
3 #define M_PI (3.14159265358979323846)
4 #endif
5 
6 #include "nrn_export.hpp"
7 
8 /*Some functions supported by numpy that aren't included in math.h
9  * names and arguments match the wrappers used in rxdmath.py
10  */
11 
12 extern "C" NRN_EXPORT double factorial(const double x) {
13  return tgamma(x + 1.);
14 }
15 
16 
17 extern "C" NRN_EXPORT double degrees(const double radians) {
18  return radians * (180. / M_PI);
19 }
20 
21 extern "C" NRN_EXPORT void radians(const double degrees, double* radians) {
22  *radians = degrees * (M_PI / 180.);
23 }
24 
25 
26 extern "C" NRN_EXPORT double log1p(const double x) {
27  return log(x + 1.);
28 }
29 
30 extern "C" NRN_EXPORT double vtrap(const double x, const double y) {
31  if (fabs(x / y) < 1e-6) {
32  return y * (1.0 - x / y / 2.0);
33  } else {
34  return x / (exp(x / y) - 1.0);
35  }
36 }
exp
Definition: extdef.h:5
log
Definition: extdef.h:4
fabs
Definition: extdef.h:3
#define NRN_EXPORT
Definition: nrn_export.hpp:6
NRN_EXPORT double factorial(const double x)
Definition: rxdmath.cpp:12
NRN_EXPORT double vtrap(const double x, const double y)
Definition: rxdmath.cpp:30
NRN_EXPORT void radians(const double degrees, double *radians)
Definition: rxdmath.cpp:21
NRN_EXPORT double log1p(const double x)
Definition: rxdmath.cpp:26
#define M_PI
Definition: rxdmath.cpp:3
NRN_EXPORT double degrees(const double radians)
Definition: rxdmath.cpp:17