54 lines · c
1//===-- Definition of macros to be used with complex functions ------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef __LLVM_LIBC_MACROS_COMPLEX_MACROS_H10#define __LLVM_LIBC_MACROS_COMPLEX_MACROS_H11 12#include "cfloat128-macros.h"13#include "cfloat16-macros.h"14 15#ifndef __STDC_NO_COMPLEX__16 17#define __STDC_VERSION_COMPLEX_H__ 202311L18 19#define complex _Complex20#define _Complex_I ((_Complex float)1.0fi)21#define I _Complex_I22 23// TODO: Add imaginary macros once GCC or Clang support _Imaginary builtin-type.24 25#if __has_builtin(__builtin_complex)26#define __CMPLX(r, i, t) (__builtin_complex((t)(r), (t)(i)))27#else28#define __CMPLX(r, i, t) ((_Complex t){(t)(r), (t)(i)})29#endif30 31#define CMPLX(r, i) __CMPLX(r, i, double)32#define CMPLXF(r, i) __CMPLX(r, i, float)33#define CMPLXL(r, i) __CMPLX(r, i, long double)34 35#ifdef LIBC_TYPES_HAS_CFLOAT1636#if !defined(__clang__) || (__clang_major__ >= 22 && __clang_minor__ > 0)37#define CMPLXF16(r, i) __CMPLX(r, i, _Float16)38#else39#define CMPLXF16(r, i) ((complex _Float16)(__CMPLX(r, i, float)))40#endif41#endif // LIBC_TYPES_HAS_CFLOAT1642 43#ifdef LIBC_TYPES_HAS_CFLOAT12844#ifdef LIBC_TYPES_CFLOAT128_IS_COMPLEX_LONG_DOUBLE45#define CMPLXF128(r, i) __CMPLX(r, i, long double)46#else47#define CMPLXF128(r, i) __CMPLX(r, i, float128)48#endif // LIBC_TYPES_CFLOAT128_IS_COMPLEX_LONG_DOUBLE49#endif // LIBC_TYPES_HAS_CFLOAT12850 51#endif // __STDC_NO_COMPLEX__52 53#endif // __LLVM_LIBC_MACROS_COMPLEX_MACROS_H54