From e0ccf1d92467ebaffdf4e438f821700f3c938962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 28 Oct 2025 18:07:35 +0100 Subject: [PATCH] POSIX: add CMPLX(), CMPLXF(), CMPLXL() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit appeared in issue 8: https://pubs.opengroup.org/onlinepubs/9799919799/functions/CMPLX.html Change-Id: I037e7368611e201df28589172f926e7a9fc52be2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9758 Reviewed-by: Jérôme Duval Tested-by: Commit checker robot --- headers/posix/complex.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/headers/posix/complex.h b/headers/posix/complex.h index 1e1e92c272..6a28936c2e 100644 --- a/headers/posix/complex.h +++ b/headers/posix/complex.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Haiku, Inc. All Rights Reserved. + * Copyright 2015, 2025 Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _COMPLEX_H_ @@ -15,6 +15,16 @@ #define complex _Complex #define I _Complex_I +#ifdef _Imaginary_I +#define CMPLX(x, y) ((double complex)((double)(x) + _Imaginary_I * (double)(y))) +#define CMPLXF(x, y) ((float complex)((float)(x) + _Imaginary_I * (float)(y))) +#define CMPLXL(x, y) ((long double complex)((long double)(x) + _Imaginary_I * (long double)(y))) +#else +#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))) +#endif + #ifdef __cplusplus extern "C" { #endif