1 //===-- complex type --------------------------------------------*- 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 9 #ifndef LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H 10 #define LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H 11 12 #include "src/__support/macros/config.h" 13 #include "src/__support/macros/properties/complex_types.h" 14 #include "src/__support/macros/properties/types.h" 15 16 namespace LIBC_NAMESPACE_DECL { 17 template <typename T> struct Complex { 18 T real; 19 T imag; 20 }; 21 22 template <typename T> struct make_complex; 23 24 template <> struct make_complex<float> { 25 using type = _Complex float; 26 }; 27 template <> struct make_complex<double> { 28 using type = _Complex double; 29 }; 30 template <> struct make_complex<long double> { 31 using type = _Complex long double; 32 }; 33 34 #if defined(LIBC_TYPES_HAS_CFLOAT16) 35 template <> struct make_complex<float16> { 36 using type = cfloat16; 37 }; 38 #endif 39 #ifdef LIBC_TYPES_CFLOAT128_IS_NOT_COMPLEX_LONG_DOUBLE 40 template <> struct make_complex<float128> { 41 using type = cfloat128; 42 }; 43 #endif 44 45 template <typename T> using make_complex_t = typename make_complex<T>::type; 46 47 template <typename T> struct make_real; 48 49 template <> struct make_real<_Complex float> { 50 using type = float; 51 }; 52 template <> struct make_real<_Complex double> { 53 using type = double; 54 }; 55 template <> struct make_real<_Complex long double> { 56 using type = long double; 57 }; 58 59 #if defined(LIBC_TYPES_HAS_CFLOAT16) 60 template <> struct make_real<cfloat16> { 61 using type = float16; 62 }; 63 #endif 64 #ifdef LIBC_TYPES_CFLOAT128_IS_NOT_COMPLEX_LONG_DOUBLE 65 template <> struct make_real<cfloat128> { 66 using type = float128; 67 }; 68 #endif 69 70 template <typename T> using make_real_t = typename make_real<T>::type; 71 72 } // namespace LIBC_NAMESPACE_DECL 73 #endif // LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H 74