tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
isnan.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_ISNAN_HPP
5#define TETL_CMATH_ISNAN_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_concepts/integral.hpp>
10#include <etl/_type_traits/is_constant_evaluated.hpp>
11
12namespace etl {
13
14/// Determines if the given floating point number arg is a not-a-number (NaN) value.
15/// \details https://en.cppreference.com/w/cpp/numeric/math/isnan
16/// \ingroup cmath
17[[nodiscard]] constexpr auto isnan(float arg) -> bool
18{
19#if __has_builtin(__builtin_isnanf) or defined(TETL_COMPILER_GCC)
20 return __builtin_isnanf(arg);
21#else
22 return arg != arg;
23#endif
24}
25
26/// \ingroup cmath
27[[nodiscard]] constexpr auto isnan(double arg) -> bool
28{
29#if __has_builtin(__builtin_isnan) or defined(TETL_COMPILER_GCC)
30 return __builtin_isnan(arg) != 0;
31#else
32 return arg != arg;
33#endif
34}
35
36/// \ingroup cmath
37[[nodiscard]] constexpr auto isnan(long double arg) -> bool
38{
39#if __has_builtin(__builtin_isnanl) or defined(TETL_COMPILER_GCC)
40 return __builtin_isnanl(arg);
41#else
42 return arg != arg;
43#endif
44}
45
46/// Determines if the given floating point number arg is a not-a-number (NaN) value.
47/// \details https://en.cppreference.com/w/cpp/numeric/math/isnan
48/// \ingroup cmath
49template <integral Int>
50[[nodiscard]] constexpr auto isnan(Int arg) -> bool
51{
52 return isnan(static_cast<double>(arg));
53}
54
55} // namespace etl
56
57#endif // TETL_CMATH_ISNAN_HPP
constexpr auto isnan(double arg) -> bool
Definition isnan.hpp:27
constexpr auto isnan(float arg) -> bool
Determines if the given floating point number arg is a not-a-number (NaN) value.
Definition isnan.hpp:17
constexpr auto isnan(Int arg) -> bool
Determines if the given floating point number arg is a not-a-number (NaN) value.
Definition isnan.hpp:50
constexpr auto isnan(long double arg) -> bool
Definition isnan.hpp:37
Definition adjacent_find.hpp:9