Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
abs_diff.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ABS_DIFF_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ABS_DIFF_HPP_
7
8// IWYU pragma: private, include "arene/base/math.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12#include "arene/base/constraints/constraints.hpp"
13#include "arene/base/stdlib_choice/enable_if.hpp"
14#include "arene/base/stdlib_choice/is_arithmetic.hpp"
15// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
16
17namespace arene {
18namespace base {
19
20/// @brief Calculate the absolute difference between two numbers
21/// @tparam Number The type of the number.
22/// @param first The first value to take the absolute difference of
23/// @param second The second value to take the absolute difference of
24/// @return The absolute difference between @c first and @c second
25template <typename Number, constraints<std::enable_if_t<std::is_arithmetic<Number>::value>> = nullptr>
26constexpr auto abs_diff(Number first, Number second) noexcept -> Number {
27 if (first < second) {
28 return static_cast<Number>(second - first);
29 }
30 return static_cast<Number>(first - second);
31}
32
33} // namespace base
34} // namespace arene
35
36#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ABS_DIFF_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10