cpp-utilities/math/math.h

43 lines
1.3 KiB
C
Raw Normal View History

2015-04-22 18:36:40 +02:00
#ifndef MATHUTILITIES_H
#define MATHUTILITIES_H
2017-05-01 03:13:11 +02:00
#include "../global.h"
2015-04-22 18:36:40 +02:00
2019-03-13 19:00:37 +01:00
#include <cstdint>
2015-09-06 15:30:16 +02:00
namespace MathUtilities {
2015-04-22 18:36:40 +02:00
CPP_UTILITIES_EXPORT int digitsum(int number, int base = 10);
CPP_UTILITIES_EXPORT int factorial(int number);
2019-03-13 19:00:37 +01:00
CPP_UTILITIES_EXPORT std::uint64_t powerModulo(std::uint64_t base, std::uint64_t expontent, std::uint64_t module);
CPP_UTILITIES_EXPORT std::int64_t inverseModulo(std::int64_t number, std::int64_t module);
CPP_UTILITIES_EXPORT std::uint64_t orderModulo(std::uint64_t number, std::uint64_t module);
/// \brief Returns the smallest of the given items.
template <typename T> constexpr T min(T first, T second)
{
return first < second ? first : second;
}
/// \brief Returns the smallest of the given items.
template <typename T1, typename... T2> constexpr T1 min(T1 first, T1 second, T2... remaining)
{
return first < second ? min(first, remaining...) : min(second, remaining...);
}
/// \brief Returns the greatest of the given items.
template <typename T> constexpr T max(T first, T second)
{
return first > second ? first : second;
}
/// \brief Returns the greatest of the given items.
template <typename T1, typename... T2> constexpr T1 max(T1 first, T1 second, T2... remaining)
{
return first > second ? max(first, remaining...) : max(second, remaining...);
}
} // namespace MathUtilities
2015-04-22 18:36:40 +02:00
#endif // MATHUTILITIES_H