refactor: abs moved to constexpr_math.h

This commit is contained in:
Mateusz Pusz
2024-10-02 15:24:52 +02:00
parent 25e99fe0fa
commit 61817ae61f
2 changed files with 7 additions and 6 deletions

View File

@@ -39,6 +39,12 @@ import std;
namespace mp_units::detail { namespace mp_units::detail {
template<typename T>
[[nodiscard]] MP_UNITS_CONSTEVAL T abs(T v) noexcept
{
return v < 0 ? -v : v;
}
// Raise an arbitrary arithmetic type to a positive integer power at compile time. // Raise an arbitrary arithmetic type to a positive integer power at compile time.
template<typename T> template<typename T>
[[nodiscard]] consteval T int_power(T base, std::integral auto exp) [[nodiscard]] consteval T int_power(T base, std::integral auto exp)

View File

@@ -22,6 +22,7 @@
#pragma once #pragma once
#include <mp-units/bits/constexpr_math.h>
#include <mp-units/bits/hacks.h> #include <mp-units/bits/hacks.h>
#include <mp-units/bits/module_macros.h> #include <mp-units/bits/module_macros.h>
#include <mp-units/compat_macros.h> #include <mp-units/compat_macros.h>
@@ -39,12 +40,6 @@ import std;
namespace mp_units::detail { namespace mp_units::detail {
template<typename T>
[[nodiscard]] MP_UNITS_CONSTEVAL T abs(T v) noexcept
{
return v < 0 ? -v : v;
}
[[nodiscard]] consteval std::intmax_t safe_multiply(std::intmax_t lhs, std::intmax_t rhs) [[nodiscard]] consteval std::intmax_t safe_multiply(std::intmax_t lhs, std::intmax_t rhs)
{ {
constexpr std::intmax_t c = std::uintmax_t{1} << (sizeof(std::intmax_t) * 4); constexpr std::intmax_t c = std::uintmax_t{1} << (sizeof(std::intmax_t) * 4);