|
|
2fb9fd |
#ifndef REAL_H
|
|
|
2fb9fd |
#define REAL_H
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
145120 |
#include <utility></utility>
|
|
|
145120 |
|
|
|
145120 |
|
|
|
2fb9fd |
typedef double Real;
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
145120 |
const Real precision = 1e-10;
|
|
|
a7e4c0 |
const Real differential = 0.05;
|
|
|
2fb9fd |
const Real pi = 3.1415926535897932384626433;
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
a7e4c0 |
inline bool equal(const Real &a, const Real &b, const Real &precision)
|
|
|
2fb9fd |
{ return (a < b ? b - a : a - b) < precision; }
|
|
|
a7e4c0 |
inline bool equal(const Real &a, const Real &b)
|
|
|
a7e4c0 |
{ return equal(a, b, precision); }
|
|
|
2fb9fd |
inline bool less(const Real &a, const Real &b)
|
|
|
2fb9fd |
{ return !equal(a, b) && a < b; }
|
|
|
2fb9fd |
inline bool greater(const Real &a, const Real &b)
|
|
|
2fb9fd |
{ return less(b, a); }
|
|
|
2fb9fd |
inline bool lesseq(const Real &a, const Real &b)
|
|
|
145120 |
{ return !less(b, a); }
|
|
|
2fb9fd |
inline bool greatereq(const Real &a, const Real &b)
|
|
|
2fb9fd |
{ return lesseq(b, a); }
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
145120 |
template<typename t=""></typename>
|
|
|
145120 |
bool sort(T &a, T &b) {
|
|
|
145120 |
if (!(a < b)) { std::swap(a, b); return true; }
|
|
|
145120 |
return false;
|
|
|
145120 |
}
|
|
|
145120 |
|
|
|
145120 |
template<typename t=""></typename>
|
|
|
145120 |
bool sort(T &a, T &b, T &c) {
|
|
|
145120 |
bool x = false;
|
|
|
145120 |
if (sort(a, b)) x = true;
|
|
|
145120 |
if (sort(b, c)) x = true;
|
|
|
145120 |
if (x) sort(a, b);
|
|
|
145120 |
return x;
|
|
|
145120 |
}
|
|
|
145120 |
|
|
|
145120 |
template<typename t=""></typename>
|
|
|
145120 |
T merge(const Real &l, T &a, T &b)
|
|
|
145120 |
{ return a*(1 - l) + b*l; }
|
|
|
145120 |
|
|
|
145120 |
inline Real sign(const Real &x)
|
|
|
145120 |
{ return equal(x, 0) ? 0 : x < 0 ? -1 : 1; }
|
|
|
a7e4c0 |
inline Real clamp(const Real &x, const Real &min, const Real &max)
|
|
|
a7e4c0 |
{ return x < min ? min : (max < x ? max : x); }
|
|
|
145120 |
|
|
|
145120 |
int solve_equation(Real *roots, const Real &k0, const Real &k1);
|
|
|
145120 |
int solve_equation(Real *roots, const Real &k0, const Real &k1, const Real &k2);
|
|
|
145120 |
int solve_equation(Real *roots, const Real &k0, const Real &k1, const Real &k2, const Real &k3);
|
|
|
145120 |
|
|
|
2fb9fd |
#endif
|