numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
abs.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cmath>
23#include <complex>
24
28
29namespace num_collect {
30inline namespace base {
31
39template <concepts::real_scalar T>
40auto abs(const T& val) -> T {
41 return std::abs(val);
42}
43
51template <concepts::real_scalar T>
52auto abs(const std::complex<T>& val) -> T {
53 return std::abs(val);
54}
55
63template <concepts::signed_integral T>
64auto abs(const T& val) -> T {
65 return std::abs(val);
66}
67
75template <concepts::unsigned_integral T>
76auto abs(const T& val) -> T {
77 return val;
78}
79
80} // namespace base
81} // namespace num_collect
Namespace of definitions common in this project.
Definition abs.h:30
auto abs(const T &val) -> T
Calculate the absolute value of a number.
Definition abs.h:40
Namespace of num_collect source codes.
Definition of real_scalar concept.
Definition of signed_integral concept.
Definition of unsigned_integral concept.