Compare commits
5 Commits
7aded906b7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8df7eb638b | |||
| 7e85152094 | |||
| d645d7223b | |||
| b77a7b9149 | |||
| 5fc6b43ea0 |
@@ -11,6 +11,11 @@ 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));
|
||||||
|
|
||||||
|
// 1, 2, 3, 4, 5
|
||||||
|
hack::log()(hack::math::sum_arithmetic_progression(1, 1, 5));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
29
run.sh
29
run.sh
@@ -1,29 +0,0 @@
|
|||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
PROJECT_NAME=$(basename $PWD)
|
|
||||||
|
|
||||||
run() {
|
|
||||||
command meson compile -C build
|
|
||||||
cd build
|
|
||||||
./bin/$PROJECT_NAME
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
# run test [name_test]
|
|
||||||
# example: run test pattrens
|
|
||||||
if [[ "$1" == "test" ]]; then
|
|
||||||
echo ""
|
|
||||||
meson test $2 -C build
|
|
||||||
echo ""
|
|
||||||
awk '/^-------------------------------------------------------------------------------/{flag=1} /===============================================================================/{flag=0} flag' ./build/meson-logs/testlog.txt
|
|
||||||
elif [[ "$1" == "tests" ]]; then
|
|
||||||
echo ""
|
|
||||||
meson test -C build
|
|
||||||
echo ""
|
|
||||||
# awk '/^-------------------------------------------------------------------------------/{flag=1} /===============================================================================/{flag=0} flag' ./build/meson-logs/testlog.txt
|
|
||||||
elif [[ -d "build" ]]; then
|
|
||||||
run
|
|
||||||
else
|
|
||||||
command meson setup build
|
|
||||||
run
|
|
||||||
fi
|
|
||||||
@@ -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,26 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Функция для вычисления суммы арифметической прогрессии
|
||||||
|
// a1 - первый член
|
||||||
|
// d - разность (шаг)
|
||||||
|
// n - количество членов
|
||||||
|
inline long long sum_arithmetic_progression(long long a1, long long d, std::size_t n) {
|
||||||
|
// Формула суммы: S = n * (2*a1 + (n-1)*d) / 2
|
||||||
|
// см. wiki/math
|
||||||
|
return n * (2 * a1 + (n - 1) * d) / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user