diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2024-07-03 09:08:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-03 09:08:11 (GMT) |
commit | 51c4a324c037fb2e31640202243fd1c8b33800d5 (patch) | |
tree | 08621c55e9f848fc08e22852fb54e0ccc1d16d97 /Modules/_complex.h | |
parent | c9bdfbe86853fcf5f2b7dce3a50b383e23384ed2 (diff) | |
download | cpython-51c4a324c037fb2e31640202243fd1c8b33800d5.zip cpython-51c4a324c037fb2e31640202243fd1c8b33800d5.tar.gz cpython-51c4a324c037fb2e31640202243fd1c8b33800d5.tar.bz2 |
gh-61103: Support float and long double complex types in ctypes module (#121248)
This amends 6988ff02a5: memory allocation for
stginfo->ffi_type_pointer.elements in PyCSimpleType_init() should be
more generic (perhaps someday fmt->pffi_type->elements will be not a
two-elements array).
It should finally resolve #61103.
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Modules/_complex.h')
-rw-r--r-- | Modules/_complex.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/_complex.h b/Modules/_complex.h index 1c1d1c8..28d4a32 100644 --- a/Modules/_complex.h +++ b/Modules/_complex.h @@ -21,6 +21,8 @@ #if !defined(CMPLX) # if defined(__clang__) && __has_builtin(__builtin_complex) # 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)) # else static inline double complex CMPLX(double real, double imag) @@ -30,5 +32,23 @@ CMPLX(double real, double imag) ((double *)(&z))[1] = imag; return z; } + +static inline float complex +CMPLXF(float real, float imag) +{ + float complex z; + ((float *)(&z))[0] = real; + ((float *)(&z))[1] = imag; + return z; +} + +static inline long double complex +CMPLXL(long double real, long double imag) +{ + long double complex z; + ((long double *)(&z))[0] = real; + ((long double *)(&z))[1] = imag; + return z; +} # endif #endif |