C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
math.h
Go to the documentation of this file.
1 #ifndef MATHUTILITIES_H
2 #define MATHUTILITIES_H
3 
4 #include "../conversion/types.h"
5 #include "../global.h"
6 
7 namespace MathUtilities {
8 
9 CPP_UTILITIES_EXPORT int random(int lowerbounds, int upperbounds);
10 CPP_UTILITIES_EXPORT int digitsum(int number, int base = 10);
11 CPP_UTILITIES_EXPORT int factorial(int number);
15 
17 template <typename T> constexpr T min(T first, T second)
18 {
19  return first < second ? first : second;
20 }
21 
23 template <typename T1, typename... T2> constexpr T1 min(T1 first, T1 second, T2... remaining)
24 {
25  return first < second ? min(first, remaining...) : min(second, remaining...);
26 }
27 
29 template <typename T> constexpr T max(T first, T second)
30 {
31  return first > second ? first : second;
32 }
33 
35 template <typename T1, typename... T2> constexpr T1 max(T1 first, T1 second, T2... remaining)
36 {
37  return first > second ? max(first, remaining...) : max(second, remaining...);
38 }
39 
40 } // namespace MathUtilities
41 
42 #endif // MATHUTILITIES_H
CPP_UTILITIES_EXPORT int factorial(int number)
Returns the factorial of the given number.
Definition: math.cpp:42
CPP_UTILITIES_EXPORT uint64 orderModulo(uint64 number, uint64 module)
Computes the order of number modulo module.
Definition: math.cpp:92
std::int64_t int64
signed 64-bit integer
Definition: types.h:29
#define CPP_UTILITIES_EXPORT
CPP_UTILITIES_EXPORT int64 inverseModulo(int64 number, int64 module)
Computes the inverse of number modulo module.
Definition: math.cpp:74
Contains various mathematical functions.
Definition: math.h:7
std::uint64_t uint64
unsigned 64-bit integer
Definition: types.h:49
CPP_UTILITIES_EXPORT int random(int lowerbounds, int upperbounds)
Returns a pseudo random number between lowerbounds and upperbounds.
Definition: math.cpp:18
constexpr T max(T first, T second)
Returns the greatest of the given items.
Definition: math.h:29
CPP_UTILITIES_EXPORT int digitsum(int number, int base=10)
Returns the digitsum of the given number using the specified base.
Definition: math.cpp:28
constexpr T min(T first, T second)
Returns the smallest of the given items.
Definition: math.h:17
CPP_UTILITIES_EXPORT uint64 powerModulo(uint64 base, uint64 expontent, uint64 module)
Computes base power exponent modulo module.
Definition: math.cpp:55