Empirical
Namespaces | Functions
math.h File Reference

Useful mathematical functions (that are constexpr when possible.) More...

#include <initializer_list>
#include <algorithm>
#include <cmath>
#include "../base/assert.h"
#include "../meta/reflection.h"
#include "const.h"

Go to the source code of this file.

Namespaces

 emp
 If we are in emscripten, make sure to include the header.
 
 emp::internal
 

Functions

constexpr int emp::Mod (int in_val, int mod_val)
 % is actually remainder; Mod is a proper modulus command that handles negative #'s correctly More...
 
double emp::Mod (double in_val, double mod_val)
 Regular Mod doesn't work on doubles. Build one that does! More...
 
template<typename T >
constexpr T emp::Abs (T in)
 Find the absolute value for any variable. More...
 
template<typename TYPE >
constexpr TYPE emp::ToRange (const TYPE &value, const TYPE &in_min, const TYPE &in_max)
 Run both min and max on a value to put it into a desired range. More...
 
template<typename T >
constexpr T emp::Min (T in1)
 Min of only one element is that element itself! More...
 
template<typename T , typename... Ts>
constexpr T emp::Min (T in1, T in2, Ts...extras)
 Min of multiple elements is solved recursively. More...
 
template<typename T >
constexpr T emp::Max (T in1)
 Max of only one element is that element itself! More...
 
template<typename T , typename... Ts>
constexpr T emp::Max (T in1, T in2, Ts...extras)
 Max of multiple elements is solved recursively. More...
 
template<typename T >
constexpr const T & emp::MinRef (const T &in1)
 
template<typename T , typename... Ts>
constexpr const T & emp::MinRef (const T &in1, const T &in2, const Ts &...extras)
 MinRef of multiple elements returns reference to minimum value. More...
 
template<typename T >
constexpr const T & emp::MaxRef (const T &in1)
 
template<typename T , typename... Ts>
constexpr const T & emp::MaxRef (const T &in1, const T &in2, const Ts &...extras)
 MaxRef of multiple elements returns reference to maximum value. More...
 
static constexpr double emp::internal::Log2_base (double x)
 
static constexpr double emp::internal::Log2_frac (double x)
 
static constexpr double emp::internal::Log2_pos (double x)
 
static constexpr double emp::Log2 (double x)
 Compile-time log base 2 calculator. More...
 
static constexpr double emp::Log (double x, double base=10.0)
 Compile-time log calculator. More...
 
static constexpr double emp::Ln (double x)
 Compile-time natural log calculator. More...
 
static constexpr double emp::Log10 (double x)
 Compile-time log base 10 calculator. More...
 
template<typename T >
static constexpr T emp::Square (T val)
 A simple function to square a value. More...
 
static constexpr double emp::internal::Pow2_lt1 (double exp, int id=0)
 
static constexpr double emp::internal::Pow2_impl (double exp)
 
template<typename T >
static constexpr type_if< T, std::is_integral > emp::Pow (T base, T p)
 A fast (O(log p)) integral-power command. More...
 
static constexpr double emp::Pow2 (double exp)
 A fast 2^x command. More...
 
template<typename TYPE >
static constexpr TYPE emp::IntPow (TYPE base, TYPE exp)
 A fast method for calculating exponents for int types. More...
 
static constexpr double emp::Pow (double base, double exp)
 A fast method for calculating exponents on doubles. More...
 
static constexpr double emp::Exp (double exp)
 A fast method of calculating e^x. More...
 
template<typename TYPE >
static constexpr int emp::IntLog2 (TYPE x)
 A compile-time int-log calculator (aka, significant bits) More...
 
template<typename TYPE >
static constexpr int emp::CountOnes (TYPE x)
 A compile-time bit counter. More...
 
template<typename TYPE >
static constexpr TYPE emp::MaskLow (std::size_t num_bits)
 Quick bit-mask generator for low bits. More...
 
template<typename TYPE >
static constexpr TYPE emp::MaskHigh (std::size_t num_bits)
 Quick bit-mask generator for high bits. More...
 
template<typename T >
constexpr const T & emp::Min (const T &in1, const T &in2, const T &in3)
 Return the minimum of three values. More...
 
template<typename T >
const T & emp::Min (std::initializer_list< const T & > lst)
 A version of Min that allows a variable number of inputs to be compared. More...
 
template<typename T >
const T & emp::Max (std::initializer_list< const T & > lst)
 A version of Max that allows a variable number of inputs to be compared. More...
 

Detailed Description

Useful mathematical functions (that are constexpr when possible.)

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Date
2016-2018
Note
Status: BETA (though new functions are added frequently)