tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
abs.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_NUMERIC_ABS_HPP
3#define TETL_NUMERIC_ABS_HPP
4
6
7namespace etl {
8
11template <typename Type>
12[[nodiscard]] constexpr auto abs(Type input) noexcept -> Type
13{
14 using limits = etl::numeric_limits<Type>;
15 if constexpr (limits::is_signed or not limits::is_specialized) {
16 if (input < 0) {
17 return static_cast<Type>(-input);
18 }
19 return input;
20 } else {
21 return input;
22 }
23}
24
25} // namespace etl
26
27#endif // TETL_NUMERIC_ABS_HPP
constexpr auto abs(complex< T > const &z) -> T
Definition abs.hpp:13
Definition adjacent_find.hpp:8
Definition numeric_limits.hpp:17