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; + } }