56 const double pi = 3.14159265358979323846;
63 #if !defined __GNUC__ || (__GNUC__ == 2 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)) 73 inline double sign(
double x) {
return (x > 0.0) ? 1.0 : ((x < 0.0) ? -1.0 : 0.0); }
75 inline int sign(
int x) {
return (x > 0) ? 1 : ((x < 0) ? -1 : 0); }
77 inline double nint(
const double x) {
return int(x + 0.5 *
sign(x)); }
79 inline double sqr(
double x) {
return (x * x); }
81 inline int sqr(
int x) {
return (x * x); }
88 std::cout << " " #i "= " << i; \ 90 #define write2(i, j) \ 95 #define write3(i, j, k) \ 100 #define write4(i, j, k, l) \ 105 #define write5(i, j, k, l, m) \ 107 write4(i, j, k, l); \ 110 #define write6(i, j, k, l, m, n) \ 112 write5(i, j, k, l, m); \ 115 #define write7(i, j, k, l, m, n, o) \ 117 write6(i, j, k, l, m, n); \ 120 #define write8(i, j, k, l, m, n, o, p) \ 122 write7(i, j, k, l, m, n, o); \ 125 #define write9(i, j, k, l, m, n, o, p, q) \ 127 write8(i, j, k, l, m, n, o, p); \ 130 #define write10(i, j, k, l, m, n, o, p, q, r) \ 132 write9(i, j, k, l, m, n, o, p, q); \ 139 std::cout << std::endl; \ 141 #define BMWrite2(i, j) \ 144 std::cout << std::endl; \ 146 #define BMWrite3(i, j, k) \ 149 std::cout << std::endl; \ 151 #define BMWrite4(i, j, k, l) \ 153 write4(i, j, k, l); \ 154 std::cout << std::endl; \ 156 #define BMWrite5(i, j, k, l, m) \ 158 write5(i, j, k, l, m); \ 159 std::cout << std::endl; \ 161 #define BMWrite6(i, j, k, l, m, n) \ 163 write6(i, j, k, l, m, n); \ 164 std::cout << std::endl; \ 166 #define BMWrite7(i, j, k, l, m, n, o) \ 168 write7(i, j, k, l, m, n, o); \ 169 std::cout << std::endl; \ 171 #define BMWrite8(i, j, k, l, m, n, o, p) \ 173 write8(i, j, k, l, m, n, o, p); \ 174 std::cout << std::endl; \ 176 #define BMWrite9(i, j, k, l, m, n, o, p, q) \ 178 write9(i, j, k, l, m, n, o, p, q); \ 179 std::cout << std::endl; \ 181 #define BMWrite10(i, j, k, l, m, n, o, p, q, r) \ 183 write10(i, j, k, l, m, n, o, p, q, r); \ 184 std::cout << std::endl; \ 191 const std::string errorString =
"Error ";
196 std::cout.precision(16);
197 std::cout << errorString << ss.str() << std::endl;
199 std::cerr.precision(16);
200 std::cerr << errorString << ss.str() << std::endl;
206 std::ostringstream ss;
214 std::ostringstream ss;
219 template<
class T,
class U>
220 inline void error(
char const*
m,
const T& t,
const U& u)
222 std::ostringstream ss;
223 ss <<
m <<
" " << t <<
" " << u;
227 template<
class T,
class U,
class V>
228 inline void error(
char const*
m,
const T& t,
const U& u,
const V& v)
230 std::ostringstream ss;
231 ss <<
m <<
" " << t <<
" " << u <<
" " << v;
235 template<
class T,
class U,
class V,
class W>
236 inline void error(
char const*
m,
const T& t,
const U& u,
const V& v,
const W& w)
238 std::ostringstream ss;
239 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w;
243 template<
class T,
class U,
class V,
class W,
class X>
244 inline void error(
char const*
m,
const T& t,
const U& u,
const V& v,
const W& w,
const X& x)
246 std::ostringstream ss;
247 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w <<
" " << x;
251 template<
class T,
class U,
class V,
class W,
class X,
class Y>
252 inline void error(
char const*
m,
const T& t,
const U& u,
const V& v,
const W& w,
const X& x,
const Y& y)
254 std::ostringstream ss;
255 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w <<
" " << x <<
" " << y;
259 template<
class T,
class U,
class V,
class W,
class X,
class Y,
class Z>
260 inline void error(
char const*
m,
const T& t,
const U& u,
const V& v,
const W& w,
const X& x,
const Y& y,
const Z& z)
262 std::ostringstream ss;
263 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w <<
" " << x <<
" " << y <<
" " << z;
269 const std::string warningString =
"WARNING ";
271 std::cout << warningString << ss.str() << std::endl;
277 std::ostringstream ss;
284 std::ostringstream ss;
292 std::ostringstream ss;
297 template<
class T,
class U>
298 inline void warning(
const char*
m,
const T& t,
const U& u)
300 std::ostringstream ss;
301 ss <<
m <<
" " << t <<
" " << u;
305 template<
class T,
class U,
class V>
306 inline void warning(
const char*
m,
const T& t,
const U& u,
const V& v)
308 std::ostringstream ss;
309 ss <<
m <<
" " << t <<
" " << u <<
" " << v;
313 template<
class T,
class U,
class V,
class W>
314 inline void warning(
const char*
m,
const T& t,
const U& u,
const V& v,
const W& w)
316 std::ostringstream ss;
317 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w;
321 template<
class T,
class U,
class V,
class W,
class X>
322 inline void warning(
const char*
m,
const T& t,
const U& u,
const V& v,
const W& w,
const X& x)
324 std::ostringstream ss;
325 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w <<
" " << x;
329 template<
class T,
class U,
class V,
class W,
class X,
class Y>
330 inline void warning(
const char*
m,
const T& t,
const U& u,
const V& v,
const W& w,
const X& x,
const Y& y)
332 std::ostringstream ss;
333 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w <<
" " << x <<
" " << y;
337 template<
class T,
class U,
class V,
class W,
class X,
class Y,
class Z>
338 inline void warning(
const char*
m,
const T& t,
const U& u,
const V& v,
const W& w,
const X& x,
const Y& y,
const Z& z)
340 std::ostringstream ss;
341 ss <<
m <<
" " << t <<
" " << u <<
" " << v <<
" " << w <<
" " << x <<
" " << y <<
" " << z;
349 inline void Limits(
const int n,
const int max)
351 #ifdef RANGE_CHECKING 352 if ((
n < 0) || (
n >= max))
354 error(
"Array Index out of range ",
n, max);
355 std::cerr <<
"Array error: Index out of range: 0<= " <<
n <<
" < " << max <<
"\n";
358 #endif // RANGE_CHECKING 365 #ifdef RANGE_CHECKING 366 if ((
n < 0) || (
n > max))
369 std::cerr <<
"Array error: Upper limit for index out of range: 0<= " <<
n <<
" <= " << max <<
"\n";
372 #endif // RANGE_CHECKING 377 #ifdef RANGE_CHECKING 380 std::cerr <<
"Array copy error: array sizes not equal:" << max1 <<
"," << max2 << std::endl;
383 #endif // RANGE_CHECKING 388 #ifdef RANGE_CHECKING 391 std::cerr <<
"Sub-array limits error: lower limit not lower " << lower <<
"," << upper << std::endl;
394 #endif // RANGE_CHECKING void LimitsInclusive(const int n, const int max)
void WriteError(std::ostringstream &ss)
std::string LowerCase(const std::string &s)
void Limits(const int n, const int max)
int StringToInt(const std::string &s)
double StringToDouble(const std::string &s)
std::string UpperCase(const std::string &s)
void error(char const *m)
void EqualLimits(const int max1, const int max2)
void BiggerLimit(const int lower, const int upper)
std::string DoubleToString(const double d)
double nint(const double x)
void WriteWarning(std::ostringstream &ss)
std::string IntToString(const int i)