tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
fmin.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_FMIN_HPP
5#define TETL_CMATH_FMIN_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 fmin {
15 template <typename Float>
16 [[nodiscard]] constexpr auto operator()(Float x, Float y) const noexcept -> Float
17 {
19#if __has_builtin(__builtin_fminf)
20 if constexpr (etl::same_as<Float, float>) {
21 return __builtin_fminf(x, y);
22 }
23#endif
24#if __has_builtin(__builtin_fmin)
25 if constexpr (etl::same_as<Float, double>) {
26 return __builtin_fmin(x, y);
27 }
28#endif
29 }
30 return etl::detail::gcem::min(x, y);
31 }
32} fmin;
33
34} // namespace detail
35
36/// \ingroup cmath
37/// @{
38
39/// Returns the smaller of two floating point arguments, treating NaNs as
40/// missing data (between a NaN and a numeric value, the numeric value is
41/// chosen)
42///
43/// https://en.cppreference.com/w/cpp/numeric/math/fmin
44[[nodiscard]] constexpr auto fmin(float x, float y) noexcept -> float
45{
46 return etl::detail::fmin(x, y);
47}
48
49[[nodiscard]] constexpr auto fminf(float x, float y) noexcept -> float
50{
51 return etl::detail::fmin(x, y);
52}
53
54[[nodiscard]] constexpr auto fmin(double x, double y) noexcept -> double
55{
56 return etl::detail::fmin(x, y);
57}
58
59[[nodiscard]] constexpr auto fmin(long double x, long double y) noexcept -> long double
60{
61 return etl::detail::fmin(x, y);
62}
63
64[[nodiscard]] constexpr auto fminl(long double x, long double y) noexcept -> long double
65{
66 return etl::detail::fmin(x, y);
67}
68
69/// @}
70
71} // namespace etl
72
73#endif // TETL_CMATH_FMIN_HPP
constexpr auto fminl(long double x, long double y) noexcept -> long double
Definition fmin.hpp:64
constexpr auto fmin(float x, float y) noexcept -> float
Definition fmin.hpp:44
constexpr auto fmin(double x, double y) noexcept -> double
Definition fmin.hpp:54
constexpr auto fmin(long double x, long double y) noexcept -> long double
Definition fmin.hpp:59
constexpr auto fminf(float x, float y) noexcept -> float
Definition fmin.hpp:49
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