From b77a7b914928308f793d55566b908589a1fd7bde Mon Sep 17 00:00:00 2001 From: chatlanin Date: Mon, 16 Mar 2026 15:32:22 +0300 Subject: [PATCH] add max abs --- bin/examples/math/main.cpp | 2 ++ bin/meson.build | 4 ++-- src/hack/math/math.hpp | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/examples/math/main.cpp b/bin/examples/math/main.cpp index 2b29dde..63d11a6 100644 --- a/bin/examples/math/main.cpp +++ b/bin/examples/math/main.cpp @@ -11,6 +11,8 @@ auto main(int argc, char *argv[]) -> int hack::log()(hack::math::min(4, 5)); hack::log()(hack::math::min(c, b)); + int a1 = -4, b1 = -5; + hack::log()(hack::math::max_abs(a1, b1)); return 0; } diff --git a/bin/meson.build b/bin/meson.build index ae6ae80..cef20af 100755 --- a/bin/meson.build +++ b/bin/meson.build @@ -2,10 +2,10 @@ executable( meson.project_name(), # 'examples/audio/main.cpp', # 'examples/concepts/main.cpp', - # 'examples/math/main.cpp', + 'examples/math/main.cpp', # 'examples/range/main.cpp', # 'examples/patterns/main.cpp', - 'examples/logger/main.cpp', + # 'examples/logger/main.cpp', # 'examples/exception/main.cpp', # 'examples/comparators/main.cpp', dependencies : deps, diff --git a/src/hack/math/math.hpp b/src/hack/math/math.hpp index 2a6cbb6..5a0899d 100755 --- a/src/hack/math/math.hpp +++ b/src/hack/math/math.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace hack::math { @@ -18,4 +19,16 @@ namespace hack::math { return a < b ? a : b; } + + template> + inline RT max_abs(T a, U b) + { + return std::abs(a) > std::abs(b) ? a : b; + } + + template> + inline RT min_abs(T a, U b) + { + return std::abs(a) < std::abs(b) ? a : b; + } }