add max abs

This commit is contained in:
2026-03-16 15:32:22 +03:00
parent 5fc6b43ea0
commit b77a7b9149
3 changed files with 17 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ auto main(int argc, char *argv[]) -> int
hack::log()(hack::math::min(4, 5)); hack::log()(hack::math::min(4, 5));
hack::log()(hack::math::min(c, b)); hack::log()(hack::math::min(c, b));
int a1 = -4, b1 = -5;
hack::log()(hack::math::max_abs(a1, b1));
return 0; return 0;
} }

View File

@@ -2,10 +2,10 @@ executable(
meson.project_name(), meson.project_name(),
# 'examples/audio/main.cpp', # 'examples/audio/main.cpp',
# 'examples/concepts/main.cpp', # 'examples/concepts/main.cpp',
# 'examples/math/main.cpp', 'examples/math/main.cpp',
# 'examples/range/main.cpp', # 'examples/range/main.cpp',
# 'examples/patterns/main.cpp', # 'examples/patterns/main.cpp',
'examples/logger/main.cpp', # 'examples/logger/main.cpp',
# 'examples/exception/main.cpp', # 'examples/exception/main.cpp',
# 'examples/comparators/main.cpp', # 'examples/comparators/main.cpp',
dependencies : deps, dependencies : deps,

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include <math.h>
namespace hack::math namespace hack::math
{ {
@@ -18,4 +19,16 @@ namespace hack::math
{ {
return a < b ? a : b; return a < b ? a : b;
} }
template<typename T, typename U, typename RT = std::common_type_t<T, U>>
inline RT max_abs(T a, U b)
{
return std::abs(a) > std::abs(b) ? a : b;
}
template<typename T, typename U, typename RT = std::common_type_t<T, U>>
inline RT min_abs(T a, U b)
{
return std::abs(a) < std::abs(b) ? a : b;
}
} }