tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
signbit.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_SIGNBIT_HPP
5#define TETL_CMATH_SIGNBIT_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_type_traits/is_constant_evaluated.hpp>
10
11namespace etl {
12
13namespace detail {
14
15template <typename T>
16[[nodiscard]] constexpr auto signbit_fallback(T arg) noexcept -> bool
17{
18 return arg == T(-0.0) || arg < T(0);
19}
20
21} // namespace detail
22
23/// Determines if the given floating point number arg is negative.
24///
25/// This function detects the sign bit of zeroes, infinities, and NaNs.
26/// Along with etl::copysign, etl::signbit is one of the only two portable ways
27/// to examine the sign of a NaN.
28///
29/// https://en.cppreference.com/w/cpp/numeric/math/signbit
30///
31/// \ingroup cmath
32[[nodiscard]] constexpr auto signbit(float arg) noexcept -> bool
33{
35 return detail::signbit_fallback(arg);
36 }
37#if __has_builtin(__builtin_signbit) and not defined(TETL_COMPILER_CLANG)
38 return __builtin_signbit(arg);
39#else
40 return detail::signbit_fallback(arg);
41#endif
42}
43
44/// Determines if the given floating point number arg is negative.
45///
46/// This function detects the sign bit of zeroes, infinities, and NaNs.
47/// Along with etl::copysign, etl::signbit is one of the only two portable ways
48/// to examine the sign of a NaN.
49///
50/// https://en.cppreference.com/w/cpp/numeric/math/signbit
51///
52/// \ingroup cmath
53[[nodiscard]] constexpr auto signbit(double arg) noexcept -> bool
54{
56 return detail::signbit_fallback(arg);
57 }
58#if __has_builtin(__builtin_signbit) and not defined(TETL_COMPILER_CLANG)
59 return __builtin_signbit(arg);
60#else
61 return detail::signbit_fallback(arg);
62#endif
63}
64
65/// Determines if the given floating point number arg is negative.
66///
67/// This function detects the sign bit of zeroes, infinities, and NaNs.
68/// Along with etl::copysign, etl::signbit is one of the only two portable ways
69/// to examine the sign of a NaN.
70///
71/// https://en.cppreference.com/w/cpp/numeric/math/signbit
72///
73/// \ingroup cmath
74[[nodiscard]] constexpr auto signbit(long double arg) noexcept -> bool
75{
77 return detail::signbit_fallback(arg);
78 }
79#if __has_builtin(__builtin_signbit) and not defined(TETL_COMPILER_CLANG)
80 return __builtin_signbit(arg);
81#else
82 return detail::signbit_fallback(arg);
83#endif
84}
85
86} // namespace etl
87
88#endif // TETL_CMATH_SIGNBIT_HPP
constexpr auto signbit(long double arg) noexcept -> bool
Determines if the given floating point number arg is negative.
Definition signbit.hpp:74
constexpr auto signbit(float arg) noexcept -> bool
Determines if the given floating point number arg is negative.
Definition signbit.hpp:32
constexpr auto signbit(double arg) noexcept -> bool
Determines if the given floating point number arg is negative.
Definition signbit.hpp:53
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