A library for working with phylogenetic and population genetic data.
v0.27.0
common.hpp File Reference
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <functional>
#include <limits>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>

Go to the source code of this file.

Namespaces

 genesis
 Container namespace for all symbols of genesis in order to keep them separate when used as a library.
 
 genesis::utils
 

Functions

template<typename T >
constexpr T abs_diff (T const &lhs, T const &rhs)
 Calculate the absolute differenence between two values. More...
 
bool almost_equal_relative (double lhs, double rhs, double max_rel_diff=std::numeric_limits< double >::epsilon())
 Check whether two doubles are almost equal, using a relative epsilon to compare them. More...
 
size_t binomial_coefficient (size_t n, size_t k)
 Compute the binomial coefficient, that is n choose k, for two integer numbers. More...
 
double binomial_coefficient_approx (size_t n, size_t k, bool lenient=false)
 Compute the binomial coefficient, that is n choose k, for two integer numbers, for large numbers. More...
 
double binomial_distribution (size_t k, size_t n, double p, bool lenient=false)
 Compute the probability mass function for a binomial distribution. More...
 
double circumference (double radius)
 
constexpr double cubed (double x)
 Cube of a number. More...
 
template<class ForwardIteratorA , class ForwardIteratorB >
std::pair< std::vector< double >, std::vector< double > > finite_pairs (ForwardIteratorA first_a, ForwardIteratorA last_a, ForwardIteratorB first_b, ForwardIteratorB last_b)
 Helper function that cleans two ranges of double of the same length from non-finite values. More...
 
template<class ForwardIteratorA , class ForwardIteratorB >
void for_each_finite_pair (ForwardIteratorA first_a, ForwardIteratorA last_a, ForwardIteratorB first_b, ForwardIteratorB last_b, std::function< void(double value_a, double value_b)> execute)
 Iterate two ranges of double values in parallel, and execute a function for each pair of values from the two ranges where both values are finite. More...
 
size_t int_pow (size_t base, size_t exp)
 Calculate the power base^exp for positive integer values. More...
 
bool is_valid_int_pow (size_t base, size_t exp)
 Return whether the given power can be stored within a size_t. More...
 
double log_factorial (size_t n)
 Return the logarithm (base e) of the factorial of n, that is log(n!). More...
 
double round_to (double x, size_t accuracy_order)
 Retun the value of x, rounded to the decimal digit given by accuracy_order. More...
 
template<typename T >
constexpr int signum (T x)
 Get the sign of a value, which is either -1, 0, or 1. More...
 
template<typename T >
constexpr int signum (T x, std::false_type)
 Implementation of signum(T x) for unsigned types. See there for details. More...
 
template<typename T >
constexpr int signum (T x, std::true_type)
 Implementation of signum(T x) for signed types. See there for details. More...
 
constexpr double squared (double x)
 Square of a number. More...
 

Variables

constexpr double PI = 3.141592653589793238463
 Make the world go round. More...