Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
minmax.h File Reference
#include <cmath>
#include <cfloat>
#include "wcpplib/stream/prstream.h"
#include "wcpplib/util/FunNameStack.h"

Go to the source code of this file.

Functions

double find_min (double a, double b)
 
double find_max (double a, double b)
 
float find_min (float a, float b)
 
float find_max (float a, float b)
 
long find_min (long a, long b)
 
long find_max (long a, long b)
 
int find_min (int a, int b)
 
int find_max (int a, int b)
 
long left_round (double f)
 
int even_num (long n)
 
int check_value_inside_bounds (double val, double b1, double b2)
 
int check_value_inside_bounds (float val, float b1, float b2)
 
int check_value_inside_bounds (long val, long b1, long b2)
 
int check_value_inside_bounds (int val, int b1, int b2)
 
int check_value_in_bounds (double val, double b1, double b2)
 
int check_value_in_bounds (float val, float b1, float b2)
 
int check_value_in_bounds (long val, long b1, long b2)
 
int check_value_in_bounds (int val, int b1, int b2)
 
int check_value_inside_bounds (double val, double b[2])
 
int check_value_inside_bounds (float val, float b[2])
 
int check_value_inside_bounds (long val, long b[2])
 
int check_value_inside_bounds (int val, int b[2])
 
int check_value_in_bounds (double val, double b[2])
 
int check_value_in_bounds (float val, float b[2])
 
int check_value_in_bounds (long val, long b[2])
 
int check_value_in_bounds (int val, int b[2])
 
template<class T >
void fcopy (T ar_source, T ar_dest, long q)
 
template<class T >
void arr_copy (const T *ar_source, T *ar_dest, long q)
 
template<class T >
void arr_assign (const T source, T *ar_dest, long q)
 
template<class T >
long fmax_ar (T ar, long q)
 
template<class T >
tabs (const T &x)
 
template<class T >
int apeq_mant (const T &x1, const T &x2, T prec)
 

Function Documentation

◆ apeq_mant()

template<class T >
int apeq_mant ( const T &  x1,
const T &  x2,
prec 
)

Definition at line 206 of file minmax.h.

206 {
207 if (x1 == x2) return 1;
208 if (prec == 0) return 0;
209 if (x1 == 0 && x2 == 0) return 1;
210 if ((x1 < 0 && x2 > 0) || (x1 > 0 && x2 < 0)) return 0;
211 if (tabs((x1 - x2) / (x1 + x2)) <= prec) return 1;
212 return 0;
213}
T tabs(const T &x)
Definition: minmax.h:204

◆ arr_assign()

template<class T >
void arr_assign ( const T  source,
T *  ar_dest,
long  q 
)
inline

Definition at line 187 of file minmax.h.

187 {
188 for (long n = 0; n < q; ++n)
189 ar_dest[n] = source;
190}

◆ arr_copy()

template<class T >
void arr_copy ( const T *  ar_source,
T *  ar_dest,
long  q 
)
inline

Definition at line 182 of file minmax.h.

182 {
183 for (long n = 0; n < q; ++n)
184 ar_dest[n] = ar_source[n];
185}

◆ check_value_in_bounds() [1/8]

int check_value_in_bounds ( double  val,
double  b1,
double  b2 
)
inline

Definition at line 127 of file minmax.h.

127 {
128 return ((val >= b1 && val <= b2) ? 1 : 0);
129}

◆ check_value_in_bounds() [2/8]

int check_value_in_bounds ( double  val,
double  b[2] 
)
inline

Definition at line 153 of file minmax.h.

153 {
154 return ((val >= b[0] && val <= b[1]) ? 1 : 0);
155}

◆ check_value_in_bounds() [3/8]

int check_value_in_bounds ( float  val,
float  b1,
float  b2 
)
inline

Definition at line 130 of file minmax.h.

130 {
131 return ((val >= b1 && val <= b2) ? 1 : 0);
132}

◆ check_value_in_bounds() [4/8]

int check_value_in_bounds ( float  val,
float  b[2] 
)
inline

Definition at line 156 of file minmax.h.

156 {
157 return ((val >= b[0] && val <= b[1]) ? 1 : 0);
158}

◆ check_value_in_bounds() [5/8]

int check_value_in_bounds ( int  val,
int  b1,
int  b2 
)
inline

Definition at line 136 of file minmax.h.

136 {
137 return ((val >= b1 && val <= b2) ? 1 : 0);
138}

◆ check_value_in_bounds() [6/8]

int check_value_in_bounds ( int  val,
int  b[2] 
)
inline

Definition at line 162 of file minmax.h.

162 {
163 return ((val >= b[0] && val <= b[1]) ? 1 : 0);
164}

◆ check_value_in_bounds() [7/8]

int check_value_in_bounds ( long  val,
long  b1,
long  b2 
)
inline

Definition at line 133 of file minmax.h.

133 {
134 return ((val >= b1 && val <= b2) ? 1 : 0);
135}

◆ check_value_in_bounds() [8/8]

int check_value_in_bounds ( long  val,
long  b[2] 
)
inline

Definition at line 159 of file minmax.h.

159 {
160 return ((val >= b[0] && val <= b[1]) ? 1 : 0);
161}

◆ check_value_inside_bounds() [1/8]

int check_value_inside_bounds ( double  val,
double  b1,
double  b2 
)
inline

Definition at line 114 of file minmax.h.

114 {
115 return ((val > b1 && val < b2) ? 1 : 0);
116}

◆ check_value_inside_bounds() [2/8]

int check_value_inside_bounds ( double  val,
double  b[2] 
)
inline

Definition at line 140 of file minmax.h.

140 {
141 return ((val > b[0] && val < b[1]) ? 1 : 0);
142}

◆ check_value_inside_bounds() [3/8]

int check_value_inside_bounds ( float  val,
float  b1,
float  b2 
)
inline

Definition at line 117 of file minmax.h.

117 {
118 return ((val > b1 && val < b2) ? 1 : 0);
119}

◆ check_value_inside_bounds() [4/8]

int check_value_inside_bounds ( float  val,
float  b[2] 
)
inline

Definition at line 143 of file minmax.h.

143 {
144 return ((val > b[0] && val < b[1]) ? 1 : 0);
145}

◆ check_value_inside_bounds() [5/8]

int check_value_inside_bounds ( int  val,
int  b1,
int  b2 
)
inline

Definition at line 123 of file minmax.h.

123 {
124 return ((val > b1 && val < b2) ? 1 : 0);
125}

◆ check_value_inside_bounds() [6/8]

int check_value_inside_bounds ( int  val,
int  b[2] 
)
inline

Definition at line 149 of file minmax.h.

149 {
150 return ((val > b[0] && val < b[1]) ? 1 : 0);
151}

◆ check_value_inside_bounds() [7/8]

int check_value_inside_bounds ( long  val,
long  b1,
long  b2 
)
inline

Definition at line 120 of file minmax.h.

120 {
121 return ((val > b1 && val < b2) ? 1 : 0);
122}

◆ check_value_inside_bounds() [8/8]

int check_value_inside_bounds ( long  val,
long  b[2] 
)
inline

Definition at line 146 of file minmax.h.

146 {
147 return ((val > b[0] && val < b[1]) ? 1 : 0);
148}

◆ even_num()

int even_num ( long  n)
inline

Definition at line 105 of file minmax.h.

105 {
106 long v = n / 2;
107 long n1 = v * 2;
108 if (n == n1)
109 return 1;
110 else
111 return 0;
112}

Referenced by cos(), and sin().

◆ fcopy()

template<class T >
void fcopy ( ar_source,
ar_dest,
long  q 
)
inline

Definition at line 176 of file minmax.h.

176 {
177 for (long n = 0; n < q; ++n)
178 ar_dest[n] = ar_source[n];
179}

◆ find_max() [1/4]

double find_max ( double  a,
double  b 
)
inline

Definition at line 91 of file minmax.h.

91{ return (a > b ? a : b); }

◆ find_max() [2/4]

float find_max ( float  a,
float  b 
)
inline

Definition at line 93 of file minmax.h.

93{ return (a > b ? a : b); }

◆ find_max() [3/4]

int find_max ( int  a,
int  b 
)
inline

Definition at line 97 of file minmax.h.

97{ return (a > b ? a : b); }

◆ find_max() [4/4]

long find_max ( long  a,
long  b 
)
inline

Definition at line 95 of file minmax.h.

95{ return (a > b ? a : b); }

◆ find_min() [1/4]

double find_min ( double  a,
double  b 
)
inline

Definition at line 90 of file minmax.h.

90{ return (a < b ? a : b); }

◆ find_min() [2/4]

float find_min ( float  a,
float  b 
)
inline

Definition at line 92 of file minmax.h.

92{ return (a < b ? a : b); }

◆ find_min() [3/4]

int find_min ( int  a,
int  b 
)
inline

Definition at line 96 of file minmax.h.

96{ return (a < b ? a : b); }

◆ find_min() [4/4]

long find_min ( long  a,
long  b 
)
inline

Definition at line 94 of file minmax.h.

94{ return (a < b ? a : b); }

◆ fmax_ar()

template<class T >
long fmax_ar ( ar,
long  q 
)
inline

Definition at line 192 of file minmax.h.

192 {
193 if (q <= 0) {
194 mcerr << "inline long fmax_ar(T ar, long q): q<=0\n";
195 spexit(mcerr);
196 }
197 long nmval = 0;
198 for (long n = 1; n < q; ++n) {
199 if (ar[n] > ar[nmval]) nmval = n;
200 }
201 return nmval;
202}
#define spexit(stream)
Definition: FunNameStack.h:536
#define mcerr
Definition: prstream.h:135

◆ left_round()

long left_round ( double  f)
inline

Definition at line 99 of file minmax.h.

99 {
100 if (f >= 0)
101 return long(f);
102 else
103 return -long(-f) - 1;
104}

Referenced by cos(), and sin().

◆ tabs()

template<class T >
T tabs ( const T &  x)
inline

Definition at line 204 of file minmax.h.

204{ return x >= 0 ? x : -x; }

Referenced by apeq_mant().