VCCC  2024.05
VisualCamp Common C++ library
norm.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/12/08.
3 # */
4 #
5 # ifndef VCCC_NUMERIC_NORM_HPP
6 # define VCCC_NUMERIC_NORM_HPP
7 #
8 # include <cmath>
9 #
10 # include "vccc/type_traits.hpp"
11 # include "vccc/__numeric/sum.hpp"
12 
13 namespace vccc {
14 
33 inline auto
34 norm(InputIterator first, InputIterator last)
35 {
36  return std::sqrt(square_sum(first, last));
37 }
38 
40 inline T norm(T arg) {
41  return std::abs(arg);
42 }
43 
48 template<typename Arg, typename ...Args,
49  std::enable_if_t<conjunction<std::is_arithmetic<Arg>, std::is_arithmetic<Args...>>::value, int> = 0>
50 inline auto
51 norm(Arg arg, Args... args)
52 {
53  return std::sqrt(square_sum(arg, args...));
54 }
55 
57 
58 } // namespace vccc
59 
60 #endif // VCCC_NUMERIC_NORM_HPP
auto norm(InputIterator first, InputIterator last)
calculate norm on iterator [first, last)
Definition: norm.hpp:34
constexpr auto square_sum(InputIterator first, InputIterator last)
square sum of iterator [first, last)
Definition: sum.hpp:132
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 0 > first
Definition: key_value.hpp:34
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35