Overview
Comment:Stripped template stuff.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 100c5795583627151655c411f5fe236ef7ffe4893e19583368070f7c0aa03449
User & Date: geraint@users.sourceforge.net on 2001-04-30 03:02:52
Other Links: branch diff | manifest | tags
Context
2001-05-01
14:16:06
New P+D controller for collocated use and effort output check-in: bb4060a00e user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2001-04-30
03:02:53
Created branch numerical-algebraic-solution check-in: e96b3471d0 user: gawthrop@users.sourceforge.net tags: origin/numerical-algebraic-solution, trunk
03:02:52
Stripped template stuff. check-in: 100c579558 user: geraint@users.sourceforge.net tags: origin/master, trunk
2001-04-28
03:38:36
Refined selection of matching patterns - checks for exact match. check-in: 9b7ef81b4b user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/cc/include/useful-functions.hh from [1c223463ca] to [61119a71b8].

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
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113

114
115
116
117
118
119

120
121
122
123
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
85
86
87






-
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-

-
-
+
+
-


+
+
-
+
-
-
+
+
-

-
-
-
-
-
+
+
+
-
-
-
-
-
+
-
+
-

-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
+


-
-
+
+

-
+



-
-
-
+
+
+






-
+




















-
+






-
+





-
+




#define pi 3.14159 // Predefine pi

#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH


#ifdef __CPLUSPLUS
#ifndef __cplusplus
template <class return_t>
template <class class_t>
typedef class_t &classref_t;
#else
#define inline			// strip from pre-processed file
#define inline			/* strip */
#define return_t double
#define class_t  double
typedef class_t  classref_t;
#endif // __CPLUSPLUS

typedef double  doubleref_t;
#ifndef MTT_UNUSED
#ifdef __GNUC__
#define MTT_UNUSED __attribute__ ((unused))
#else
#define MTT_UNUSED
#endif // __GNUC__
typedef double &doubleref_t;
#endif // ! __cplusplus
#endif // MTT_UNUSED


static inline double
max (const doubleref_t x1, const doubleref_t x2)

{
// == Declarations ==

  return static_cast<double>((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}
// - 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;
static inline return_t nonsingular (const classref_t x) MTT_UNUSED;
static inline return_t sign        (const classref_t x) MTT_UNUSED;

static inline double
min (const doubleref_t x1, const doubleref_t x2)
{
// - 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;
  return static_cast<double>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
static inline Matrix 	   zeros   (const int r, const int c) MTT_UNUSED;
}
#endif // __CPLUSPLUS



// == Defininitions ==

// - Template functions -

static inline return_t
static inline double
max (const classref_t x1, const classref_t x2)
{
  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)
{
  return static_cast<return_t>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}

static inline return_t
nonsingular (const classref_t x)
nonsingular (const doubleref_t x)
{
  return static_cast<return_t>((x == 0) ? 1.0e-30 : x);
  return static_cast<double>((x == 0) ? 1.0e-30 : x);
}

static inline return_t
sign (const classref_t x)
static inline double
sign (const doubleref_t x)
{
  return static_cast<return_t>((x > 0) ? +1 : (x < 0) ? -1 : 0);
  return static_cast<double>((x > 0) ? +1 : (x < 0) ? -1 : 0);
}


// - Octave functions -
#ifdef __CPLUSPLUS
Matrix
// Octave functions
#ifdef __cplusplus
static Matrix
ones (const int r = 1, const int c = 1)
{
  Matrix m (r, c, 1.0);
  return m;
}

ColumnVector
static ColumnVector
nozeros (const ColumnVector v0, const double tol = 0.0)
{
  ColumnVector v (v0.length ());
  register int i, j;
  for (i = j = 0; i < v.length (); i++)
    if (tol < abs (v0 (i)))
      {
	v (j) = v0 (i);
	j++;
      }
  if (0 == j)
    {
      return *new ColumnVector ();
    }
  else
    {
      return (v.extract (0, --j));
    }
}

ColumnVector
static ColumnVector
zeros (const int r)
{
  ColumnVector v (r, 0.0);
  return v;
}

Matrix
static Matrix
zeros (const int r, const int c)
{
  Matrix m (r, c, 0.0);
  return m;
}
#endif __CPLUSPLUS
#endif __cplusplus



#endif // HAVE_USEFUL_FUNCTIONS_HH


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]