IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_common_math.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <type_traits>
9#include <algorithm>
10#include <cstdint>
11#include <cstdlib>
12#include <limits>
13
14namespace peak
15{
16namespace common
17{
18namespace detail
19{
20
39template <typename H
41 ,
42 typename std::enable_if_t<std::is_floating_point<H>::value, int> = 0
44 >
45constexpr bool AreAlmostEqual(H lhs, H rhs, uint32_t ulp)
46{
47 return std::abs(lhs - rhs) <= std::numeric_limits<H>::epsilon() * (std::max)(std::abs(lhs), std::abs(rhs)) * static_cast<H>(ulp);
48}
49
50template<typename T>
51constexpr T Clamp(T value, T minimum, T maximum)
52{
53 if (value < minimum)
54 {
55 return minimum;
56 }
57 if (value > maximum)
58 {
59 return maximum;
60 }
61 return value;
62}
63
64} // namespace detail
65} // namespace common
66} // namespace peak
constexpr bool AreAlmostEqual(H lhs, H rhs, uint32_t ulp)
Compares two floating-point values for approximate equality using a ULP-based tolerance.
Definition peak_common_math.hpp:45
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:19
constexpr T Clamp(T value, T minimum, T maximum)
Definition peak_common_math.hpp:51
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29