44 template<
typename T,
int size>
52 template<
typename T,
int size>
56 return x | (x >> size/2);
62 constexpr
double pi = 3.14159265358979323846;
65 constexpr
double pi_2 = 1.57079632679489661923;
68 constexpr
double pi_180 = 0.01745329251994329576;
71 constexpr
double one_rad = 57.29577951308232087679;
77 constexpr
double gamma = 0.57721566490153286061;
82 return internal::nextPower2<T, sizeof(T)*8>(x - 1) + 1;
86 template<
typename T,
typename... Args>
87 inline static T
nextPower2(T arg1, T arg2, Args... args) {
88 return nextPower2(std::max(arg1, arg2, args...));
122 template <
typename T>
124 return (T(0) < val) - (val < T(0));
146 return (
int) std::tgamma(n+1);
152 return std::tgamma(n+1);
169 return std::ilogb(v);
186 template<
class T,
class INDEX =
int>
188 T current_gcd = numbers[numbers.
low()];
189 for (INDEX i = numbers.
low()+1; i <= numbers.
high(); i++) {
190 current_gcd =
gcd(current_gcd, numbers[i]);
204 inline void getFraction(
double d,
int &num,
int &denom,
const double epsilon = 5e-10,
const int count = 10) {
209 continuedFrac.
push(z);
212 while (d > epsilon && i++ < count) {
215 continuedFrac.
push(z);
222 while (!continuedFrac.
empty()) {
223 int last = continuedFrac.
popRet();
224 std::swap(num, denom);
230 template<
class Container>
231 inline typename Container::value_type
minValue(
const Container &values) {
233 return *std::min_element(values.begin(), values.end());
237 template<
class Container>
238 inline typename Container::value_type
maxValue(
const Container &values) {
240 return *std::max_element(values.begin(), values.end());
244 template<
class Container>
245 inline typename Container::value_type
sum(
const Container &values) {
246 return std::accumulate(values.begin(), values.end(),
static_cast<typename Container::value_type
>(0));
250 template<
class Container>
251 inline double mean(
const Container &values) {
253 return sum(values) /
static_cast<double>(values.size());
258 template<
class Container>
262 for (
auto value : values) {
263 double d = value -
mean;
266 return sqrt(sum / values.size());
270 template<
class Container>
double mean(const Container &values)
Returns the mean of an iterable container of given values.
int sgn(T val)
Returns +1 for val > 0, 0 for val = 0, and -1 for val < 0.
The parameterized class Array implements dynamic arrays of type E.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
INDEX high() const
Returns the maximal array index.
void push(E e)
Puts a new element in the buffer.
T gcd(T a, T b)
Returns the greatest common divisor of two numbers.
constexpr double pi_180
The constant .
double radiansToDegrees(const double &angleInRadians)
Converts an angle from radians to degrees.
double degreesToRadians(const double &angleInDegrees)
Converts an angle from degrees to radians.
Declaration and implementation of Array class and Array algorithms.
double factorial_d(int n)
Returns n!.
constexpr double pi
The constant .
T lcm(T a, T b)
Returns the least common multipler of two numbers.
constexpr double one_rad
The constant .
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
std::enable_if< size==1, T >::type nextPower2(T x)
bool empty() const
Returns true if the buffer is empty, false otherwise.
T log2(T x)
Returns the logarithm of x to the base 2.
const double log_of_4
The constant log(4.0).
double harmonic(unsigned n)
Returns the n-th harmonic number or 1.0 if n < 1.
int factorial(int n)
Returns n!.
void getFraction(double d, int &num, int &denom, const double epsilon=5e-10, const int count=10)
Converts a double to a fraction.
constexpr double gamma
The Euler-Mascheroni constant gamma.
Container::value_type minValue(const Container &values)
Returns the minimum of an iterable container of given values.
int floorLog2(int v)
A method to obtain the rounded down binary logarithm of v.
Basic declarations, included by all source files.
E popRet()
Removes the newest element from the buffer and returns it.
int binomial(int n, int k)
Returns .
Container::value_type maxValue(const Container &values)
Returns the maximum of an iterable container of given values.
double log4(double x)
Returns the logarithm of x to the base 4.
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
constexpr double pi_2
The constant .
The namespace for all OGDF objects.
Container::value_type sum(const Container &values)
Returns the sum of an iterable container of given values.
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
INDEX low() const
Returns the minimal array index.
double binomial_d(int n, int k)
Returns .
double standardDeviation(const Container &values, double mean)
Returns the standard deviation of an iterable container of given values.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.