tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
fmax.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_CMATH_FMAX_HPP
5#define TETL_CMATH_FMAX_HPP
6
7#include <etl/_3rd_party/gcem/gcem.hpp>
8#include <etl/_type_traits/is_constant_evaluated.hpp>
9
10namespace etl {
11
12namespace detail {
13
14inline constexpr struct fmax {
15 template <typename Float>
16 [[nodiscard]] constexpr auto operator()(Float x, Float y) const noexcept -> Float
17 {
19#if __has_builtin(__builtin_fmaxf)
20 if constexpr (etl::same_as<Float, float>) {
21 return __builtin_fmaxf(x, y);
22 }
23#endif
24#if __has_builtin(__builtin_fmax)
25 if constexpr (etl::same_as<Float, double>) {
26 return __builtin_fmax(x, y);
27 }
28#endif
29 }
30 return etl::detail::gcem::max(x, y);
31 }
32} fmax;
33
34} // namespace detail
35
36/// \ingroup cmath
37/// @{
38
39/// Returns the larger of two floating point arguments, treating NaNs as
40/// missing data (between a NaN and a numeric value, the numeric value is chosen)
41///
42/// https://en.cppreference.com/w/cpp/numeric/math/fmax
43[[nodiscard]] constexpr auto fmax(float x, float y) noexcept -> float
44{
45 return etl::detail::fmax(x, y);
46}
47
48[[nodiscard]] constexpr auto fmaxf(float x, float y) noexcept -> float
49{
50 return etl::detail::fmax(x, y);
51}
52
53[[nodiscard]] constexpr auto fmax(double x, double y) noexcept -> double
54{
55 return etl::detail::fmax(x, y);
56}
57
58[[nodiscard]] constexpr auto fmax(long double x, long double y) noexcept -> long double
59{
60 return etl::detail::fmax(x, y);
61}
62
63[[nodiscard]] constexpr auto fmaxl(long double x, long double y) noexcept -> long double
64{
65 return etl::detail::fmax(x, y);
66}
67
68/// @}
69
70} // namespace etl
71
72#endif // TETL_CMATH_FMAX_HPP
constexpr auto fmax(double x, double y) noexcept -> double
Definition fmax.hpp:53
constexpr auto fmaxf(float x, float y) noexcept -> float
Definition fmax.hpp:48
constexpr auto fmax(long double x, long double y) noexcept -> long double
Definition fmax.hpp:58
constexpr auto fmax(float x, float y) noexcept -> float
Definition fmax.hpp:43
constexpr auto fmaxl(long double x, long double y) noexcept -> long double
Definition fmax.hpp:63
Definition adjacent_find.hpp:9
constexpr auto is_constant_evaluated() noexcept -> bool
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition is_constant_evaluated.hpp:17