All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MissingMath.h
Go to the documentation of this file.
1 /*
2  * MissingMath.h
3  *
4  * Created on: 21.03.2013
5  * Author: cls
6  */
7 
8 #ifndef MISSINGMATH_H_
9 #define MISSINGMATH_H_
10 
11 #include <cinttypes>
12 #include <cmath>
13 #include <cassert>
14 #include <stdexcept>
15 
16 namespace Aux {
17 
21 namespace MissingMath {
22 
23 
24 inline int64_t binomial(int64_t n, int64_t k) {
25  if (k == 0) return 1;
26  if (2 * k > n) return binomial(n, n - k);
27 
28  int64_t b = n - k + 1;
29  for (int64_t i = 2; i <= k; ++i) {
30  b = b * (n - k + i);
31  b = b / i;
32  }
33  return b;
34 }
35 
36 inline double log_b(double x, double b) {
37  if (x == 0) {
38  throw std::domain_error("log(0) is undefined");
39  }
40  assert (log(b) != 0);
41  return log(x) / log(b);
42 }
43 
44 } /* namespace MissingMath */
45 
46 } /* namespace Aux */
47 #endif /* MISSINGMATH_H_ */
void log(const Location &loc, LogLevel p, const std::string msg)
Definition: Log.cpp:202
int64_t binomial(int64_t n, int64_t k)
Definition: MissingMath.h:24
double log_b(double x, double b)
Definition: MissingMath.h:36