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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
+
+
+
-
+
+
-
+
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
-
-
-
+
-
-
+
+
+
-
-
+
+
-
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#define pi 3.14159 // Predefine pi
#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH
#ifdef __CPLUSPLUS
template <class return_t>
template <class class_t>
typedef class_t &classref_t;
#else
#define inline // strip from pre-processed file
#define return_t double
#define class_t double
#define class_t double
typedef class_t classref_t;
#endif // __CPLUSPLUS
#ifndef MTT_UNUSED
#ifdef __GNUC__
#define MTT_UNUSED __attribute__ ((unused))
#else
#define MTT_UNUSED
#endif // __GNUC__
#endif // MTT_UNUSED
// == Template functions ==
static inline class_t max (const class_t &x1, const class_t &x2) MTT_UNUSED;
static inline class_t min (const class_t &x1, const class_t &x2) MTT_UNUSED;
static inline class_t sign (const class_t &x) MTT_UNUSED;
// == Declarations ==
// - Template functions -
static inline return_t max (const classref_t x1, const classref_t x2) MTT_UNUSED;
static inline return_t min (const classref_t x1, const classref_t x2) MTT_UNUSED;
class_t
max (const class_t &x1, const class_t &x2)
{
static inline return_t nonsingular (const classref_t x) MTT_UNUSED;
static inline return_t sign (const classref_t x) MTT_UNUSED;
return ((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}
// - Octave functions -
#ifdef __CPLUSPLUS
static inline Matrix ones (const int r = 1, const int c = 1) MTT_UNUSED;
static inline ColumnVector nozeros (const ColumnVector v0, const double tol = 0.0) MTT_UNUSED;
static inline ColumnVector zeros (const int r) MTT_UNUSED;
static inline Matrix zeros (const int r, const int c) MTT_UNUSED;
#endif // __CPLUSPLUS
class_t
min (const class_t &x1, const class_t &x2)
{
return ((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}
// == Defininitions ==
// - Template functions -
class_t
sign (const class_t &x)
static inline return_t
max (const classref_t x1, const classref_t x2)
{
return ((x > 0) ? +1 : (x < 0) ? -1 : 0);
return static_cast<return_t>((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}
static inline return_t
min (const classref_t x1, const classref_t x2)
{
// == Octave functions ==
static inline Matrix ones (const int r = 1, const int c = 1) MTT_UNUSED;
static inline ColumnVector nozeros (const ColumnVector v0, const double tol = 0.0) MTT_UNUSED;
static inline ColumnVector zeros (const int r) MTT_UNUSED;
static inline Matrix zeros (const int r, const int c) MTT_UNUSED;
return static_cast<return_t>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}
static inline return_t
nonsingular (const classref_t x)
{
return static_cast<return_t>((x == 0) ? 1.0e-30 : x);
}
static inline return_t
sign (const classref_t x)
{
return static_cast<return_t>((x > 0) ? +1 : (x < 0) ? -1 : 0);
}
// - Octave functions -
#ifdef __CPLUSPLUS
Matrix
ones (const int r = 1, const int c = 1)
{
Matrix m (r, c, 1.0);
return m;
}
|
88
89
90
91
92
93
94
95
96
|
112
113
114
115
116
117
118
119
120
121
122
123
|
+
+
+
|
Matrix
zeros (const int r, const int c)
{
Matrix m (r, c, 0.0);
return m;
}
#endif __CPLUSPLUS
#endif // HAVE_USEFUL_FUNCTIONS_HH
|