f3e15b8c8d
- aggiunti file della libreria e progetto visual studio.
288 lines
7.3 KiB
C
288 lines
7.3 KiB
C
/*****************************************************************************/
|
|
/* */
|
|
/* Copyright (C) 2010-2023 M. Held, S. Huber */
|
|
/* */
|
|
/* This code is not in the public domain. All rights reserved! Please make */
|
|
/* sure to read the full copyright statement contained in "README.txt" or in */
|
|
/* the "main" file of this code, such as "main.cc". */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* Written by: Stefan Huber, Martin Held */
|
|
/* */
|
|
/* E-Mail: held@cs.sbg.ac.at */
|
|
/* Fax Mail: (+43 662) 8044-611 */
|
|
/* Voice Mail: (+43 662) 8044-6304 */
|
|
/* Snail Mail: Martin Held */
|
|
/* FB Informatik */
|
|
/* Universitaet Salzburg */
|
|
/* A-5020 Salzburg, Austria */
|
|
/* */
|
|
/*****************************************************************************/
|
|
|
|
#ifndef VRONI_UTIL_H
|
|
#define VRONI_UTIL_H
|
|
|
|
#ifndef DOUBLE_OVERRIDE
|
|
#include <math.h>
|
|
#endif
|
|
|
|
#include "consts.h"
|
|
|
|
|
|
inline static int Sign(double_arg x)
|
|
{
|
|
if ((x == 0.0) || (x == -0.0))
|
|
return 0;
|
|
|
|
if ( x > 0.0)
|
|
return 1;
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
|
|
/** Like Sign but closed interval (-eps, eps) is identified with 0 */
|
|
inline static int SignEps(double_arg x, double_arg eps)
|
|
{
|
|
if (x > eps)
|
|
return 1;
|
|
else if (x < -eps)
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
inline static double Abs(double_arg x)
|
|
{
|
|
return fabs(x);
|
|
}
|
|
|
|
inline static void Swap_d(double* x, double* y)
|
|
{
|
|
double t = *y;
|
|
*y = *x;
|
|
*x = t;
|
|
}
|
|
|
|
inline static void Swap_i(int* x, int* y)
|
|
{
|
|
int t = *y;
|
|
*y = *x;
|
|
*x = t;
|
|
}
|
|
|
|
inline static double Ceiling(double_arg x)
|
|
{
|
|
return ceil(x);
|
|
}
|
|
|
|
#ifndef DOUBLE_OVERRIDE
|
|
//function currently unused. In case it is used later, it requires
|
|
//another way to calculate the CubicRoot for CORE and possibly MPFR
|
|
inline static double CubicRoot(double_arg x)
|
|
{
|
|
const double r = pow(x, M_1_3);
|
|
if(Sign(x)<0)
|
|
return -r;
|
|
else
|
|
return r;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
#define Sq(x) ((x) * (x))
|
|
|
|
#define Swap(i1, i2, i) \
|
|
{(i) = (i1); \
|
|
(i1) = (i2); \
|
|
(i2) = (i); }
|
|
|
|
#define Min(a, b) ((a) < (b) ? (a) : (b))
|
|
#define Max(a, b) ((b) < (a) ? (a) : (b))
|
|
#define Min3(a, b, c) (((a) < (b)) ? \
|
|
(((a) < (c)) ? \
|
|
(a) : (c)) \
|
|
: \
|
|
(((b) < (c)) ? \
|
|
(b) : (c)))
|
|
#define Max3(a, b, c) (((a) < (b)) ? \
|
|
(((b) < (c)) ? \
|
|
(c) : (b)) \
|
|
: \
|
|
(((a) < (c)) ? \
|
|
(c) : (a)))
|
|
#define Min4(a, b, c, d) (((a) < (b)) ? \
|
|
(((a) < (c)) ? \
|
|
(((a) < (d)) ?\
|
|
(a) : (d)) \
|
|
: \
|
|
(((c) < (d)) ? \
|
|
(c) : (d))) \
|
|
: \
|
|
(((b) < (c)) ? \
|
|
(((b) < (d)) ? \
|
|
(b) : (d)) \
|
|
: \
|
|
(((c) < (d)) ? \
|
|
(c) : (d))))
|
|
#define Max4(a, b, c, d) (((a) < (b)) ? \
|
|
(((b) < (c)) ? \
|
|
(((c) < (d)) ?\
|
|
(d) : (c)) \
|
|
: \
|
|
(((b) < (d)) ? \
|
|
(d) : (b))) \
|
|
: \
|
|
(((a) < (c)) ? \
|
|
(((c) < (d)) ? \
|
|
(d) : (c)) \
|
|
: \
|
|
(((a) < (d)) ? \
|
|
(d) : (a))))
|
|
|
|
#define MinMax3(a, b, c, min, max) {\
|
|
if ((a) < (b)) {\
|
|
if ((a) < (c)) {\
|
|
min = (a); \
|
|
if ((b) < (c)) max = (c); \
|
|
else max = (b); \
|
|
}\
|
|
else { \
|
|
min = (c); \
|
|
max = (b); \
|
|
}\
|
|
}\
|
|
else { \
|
|
if ((a) < (c)) {\
|
|
min = (b); \
|
|
max = (c); \
|
|
} \
|
|
else { \
|
|
max = (a); \
|
|
if ((b) < (c)) min = (b); \
|
|
else min = (c); \
|
|
} \
|
|
}\
|
|
}
|
|
|
|
|
|
#define MinMax4(a, b, c, d, min, max) {\
|
|
if ((a) < (b)) {\
|
|
if ((a) < (c)) {\
|
|
min = (a); \
|
|
if ((b) < (c)) max = (c); \
|
|
else max = (b); \
|
|
} \
|
|
else { \
|
|
min = (c); \
|
|
max = (b); \
|
|
} \
|
|
}\
|
|
else { \
|
|
if ((a) < (c)) { \
|
|
min = (b); \
|
|
max = (c); \
|
|
} \
|
|
else { \
|
|
max = (a); \
|
|
if ((b) < (c)) min = (b); \
|
|
else min = (c); \
|
|
}\
|
|
} \
|
|
if ((d) < min) min = (d); \
|
|
else if ((d) > max) max = (d); \
|
|
}
|
|
|
|
|
|
#define SortTwoNumbers(a, b, c) {\
|
|
if (a > b) { \
|
|
c = a; \
|
|
a = b; \
|
|
b = c; \
|
|
} \
|
|
}
|
|
|
|
|
|
|
|
#define SortThreeNumbers(a, b, c, d) {\
|
|
if (a < b) {\
|
|
if (a < c) {\
|
|
if (b > c) {\
|
|
d = b; \
|
|
b = c; \
|
|
c = d; \
|
|
}\
|
|
}\
|
|
else { \
|
|
d = a; \
|
|
a = c; \
|
|
c = b; \
|
|
b = d; \
|
|
}\
|
|
}\
|
|
else { \
|
|
if (a < c) { \
|
|
d = a; \
|
|
a = b; \
|
|
b = d; \
|
|
} \
|
|
else { \
|
|
if (b < c) {\
|
|
d = a; \
|
|
a = b; \
|
|
b = c; \
|
|
c = d; \
|
|
}\
|
|
else { \
|
|
d = a; \
|
|
a = c; \
|
|
c = d; \
|
|
}\
|
|
}\
|
|
}\
|
|
}
|
|
|
|
|
|
#define MinMax(a, b, min, max) {\
|
|
if ((b) < (a)) {\
|
|
min = (b); \
|
|
max = (a); \
|
|
} \
|
|
else { \
|
|
min = (a); \
|
|
max = (b); \
|
|
} \
|
|
}
|
|
|
|
|
|
#define MinMaxQ(a, b, min, max) \
|
|
(((b) < (a)) ? (min = (b), max = (a)) : (min = (a), max = (b)))
|
|
|
|
|
|
#define MinMax3Q(a, b, c, min, max) \
|
|
(((b) < (a)) ? (((c) < (b)) ? (min = (c), max = (a)) : \
|
|
(((c) > (a)) ? (min = (b), max = (c)) : \
|
|
(min = (b), max = (a)))) : \
|
|
(((c) > (b)) ? (min = (a), max = (c)) : \
|
|
(((c) > (a)) ? (min = (a), max = (b)) : \
|
|
(min = (c), max = (b)))))
|
|
|
|
|
|
|
|
|
|
/* */
|
|
/* some macros for epsilon-based comparisons with respect to zero... */
|
|
/* */
|
|
#define lt(a, b) ( ((a) < -b) )
|
|
#define ge(a, b) (! ((a) < -b) )
|
|
#define le(a, b) ( ((a) <= b) )
|
|
#define gt(a, b) (! ((a) <= b) )
|
|
#define eq(a, eps) ( (((a) <= eps) && !((a) < -eps)) )
|
|
#define ne(a, eps) ( !eq(a,eps) )
|
|
|
|
|
|
#endif
|
|
|