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
11namespace etl {
12
13/// \ingroup cmath
14/// @{
15
16/// Determines if the given floating point number arg is a not-a-number (NaN) value.
17/// \details https://en.cppreference.com/w/cpp/numeric/math/isnan
18[[nodiscard]] constexpr auto isnan(float arg) -> bool
19{
20#if __has_builtin(__builtin_isnanf) or defined(TETL_COMPILER_GCC)
21 return __builtin_isnanf(arg);
22#else
23 return arg != arg;
24#endif
25}
26
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[[nodiscard]] constexpr auto isnan(long double arg) -> bool
37{
38#if __has_builtin(__builtin_isnanl) or defined(TETL_COMPILER_GCC)
39 return __builtin_isnanl(arg);
40#else
41 return arg != arg;
42#endif
43}
44
45/// Determines if the given floating point number arg is a not-a-number (NaN) value.
46/// \details https://en.cppreference.com/w/cpp/numeric/math/isnan
47template <integral Int>
48[[nodiscard]] constexpr auto isnan(Int arg) -> bool
49{
50 return isnan(static_cast<double>(arg));
51}
52
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
Definition isnan.hpp:18
constexpr auto isnan(Int arg) -> bool
Determines if the given floating point number arg is a not-a-number (NaN) value.
Definition isnan.hpp:48
constexpr auto isnan(long double arg) -> bool
Definition isnan.hpp:36
Definition adjacent_find.hpp:9