xref: /llvm-project/libc/src/__support/CPP/type_traits/is_floating_point.h (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
1 //===-- is_floating_point type_traits ---------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
9 #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
10 
11 #include "src/__support/CPP/type_traits/is_same.h"
12 #include "src/__support/CPP/type_traits/remove_cv.h"
13 #include "src/__support/macros/attributes.h"
14 #include "src/__support/macros/config.h"
15 #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
16 
17 namespace LIBC_NAMESPACE_DECL {
18 namespace cpp {
19 
20 // is_floating_point
21 template <typename T> struct is_floating_point {
22 private:
23   template <typename Head, typename... Args>
24   LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
25     return (... || is_same_v<remove_cv_t<Head>, Args>);
26   }
27 
28 public:
29   LIBC_INLINE_VAR static constexpr bool value =
30       __is_unqualified_any_of<T, float, double, long double
31 #ifdef LIBC_TYPES_HAS_FLOAT16
32                               ,
33                               float16
34 #endif
35 #ifdef LIBC_TYPES_HAS_FLOAT128
36                               ,
37                               float128
38 #endif
39                               >();
40 };
41 template <typename T>
42 LIBC_INLINE_VAR constexpr bool is_floating_point_v =
43     is_floating_point<T>::value;
44 
45 } // namespace cpp
46 } // namespace LIBC_NAMESPACE_DECL
47 
48 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
49