1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#define pi 3.14159 // Predefine pi
#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH
#ifndef __cplusplus
#define inline /* strip */
typedef double doubleref_t;
#else
typedef double &doubleref_t;
#endif // ! __cplusplus
static inline double
max (const doubleref_t x1, const doubleref_t x2)
{
return static_cast<double>((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}
static inline double
min (const doubleref_t x1, const doubleref_t x2)
{
return static_cast<double>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}
static inline double
nonsingular (const doubleref_t x)
{
return static_cast<double>((x == 0) ? 1.0e-30 : x);
}
static inline double
sign (const doubleref_t x)
{
return static_cast<double>((x > 0) ? +1 : (x < 0) ? -1 : 0);
}
// Octave functions
#ifdef __cplusplus
|
<
<
<
|
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#define pi 3.14159 // Predefine pi
#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH
#ifndef __cplusplus
#define inline /* strip */
#endif // ! __cplusplus
static inline double
max (const double x1, const double x2)
{
return static_cast<double>((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}
static inline double
min (const double x1, const double x2)
{
return static_cast<double>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}
static inline double
nonsingular (const double x)
{
return static_cast<double>((x == 0) ? 1.0e-30 : x);
}
static inline double
sign (const double x)
{
return static_cast<double>((x > 0) ? +1 : (x < 0) ? -1 : 0);
}
// Octave functions
#ifdef __cplusplus
|