tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
isfinite.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_CMATH_ISFINITE_HPP
5#define TETL_CMATH_ISFINITE_HPP
6
7#include <etl/_cmath/isinf.hpp>
8#include <etl/_cmath/isnan.hpp>
9#include <etl/_type_traits/is_constant_evaluated.hpp>
10
11namespace etl {
12
13namespace detail {
14
15inline constexpr struct isfinite {
16 template <typename Float>
17 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> bool
18 {
20#if __has_builtin(__builtin_isfinitef)
21 if constexpr (etl::same_as<Float, float>) {
22 return __builtin_isfinitef(arg);
23 }
24#endif
25#if __has_builtin(__builtin_isfinite)
26 if constexpr (etl::same_as<Float, double>) {
27 return __builtin_isfinite(arg);
28 }
29#endif
30 }
31 return not etl::isnan(arg) and not etl::isinf(arg);
32 }
33} isfinite;
34
35} // namespace detail
36
37/// \ingroup cmath
38/// @{
39
40/// Determines if the given floating point number arg has finite value
41/// i.e. it is normal, subnormal or zero, but not infinite or NaN.
42/// \details https://en.cppreference.com/w/cpp/numeric/math/isfinite
43[[nodiscard]] constexpr auto isfinite(float arg) -> bool
44{
45 return etl::detail::isfinite(arg);
46}
47
48[[nodiscard]] constexpr auto isfinite(double arg) -> bool
49{
50 return etl::detail::isfinite(arg);
51}
52
53[[nodiscard]] constexpr auto isfinite(long double arg) -> bool
54{
55 return etl::detail::isfinite(arg);
56}
57
58/// @}
59
60} // namespace etl
61
62#endif // TETL_CMATH_ISFINITE_HPP
constexpr auto isfinite(long double arg) -> bool
Definition isfinite.hpp:53
constexpr auto isfinite(double arg) -> bool
Definition isfinite.hpp:48
constexpr auto isfinite(float arg) -> bool
Definition isfinite.hpp:43
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