[PATCH] libc/include/complex.h: Add CMPLX, CMPLXF, and CMPLXL

Andrew Pinski pinskia@gmail.com
Mon Jul 1 20:58:01 GMT 2024


On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org> wrote:
>
> ---
>  newlib/libc/include/complex.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
> index ad3028e4c..dbabdf67a 100644
> --- a/newlib/libc/include/complex.h
> +++ b/newlib/libc/include/complex.h
> @@ -16,6 +16,19 @@
>
>  __BEGIN_DECLS
>
> +/* Implementation from FreeBSD */
> +#if __ISO_C_VISIBLE >= 2011
> +#ifdef __clang__
> +#define        CMPLX(x, y)     ((double complex){ x, y })
> +#define        CMPLXF(x, y)    ((float complex){ x, y })
> +#define        CMPLXL(x, y)    ((long double complex){ x, y })
> +#elif __GNUC_PREREQ__(4, 7)
> +#define        CMPLX(x, y)     __builtin_complex((double)(x), (double)(y))
> +#define        CMPLXF(x, y)    __builtin_complex((float)(x), (float)(y))
> +#define        CMPLXL(x, y)    __builtin_complex((long double)(x), (long double)(y))

I only know this because I have been working with complex in the last
few weeks but __builtin_complex does not work with GCC's C++ front-end
(but it is not documented).
I don't know if you care about using this part of the header with C++
but I am just putting it out there.

Thanks,
Andrew Pinski

> +#endif
> +#endif /* __ISO_C_VISIBLE >= 2011 */
> +
>  /* 7.3.5 Trigonometric functions */
>  /* 7.3.5.1 The cacos functions */
>  double complex cacos(double complex);
> --
> 2.24.4
>


More information about the Newlib mailing list