Skip to content

Commit 548f623

Browse files
committed
Implement MSVC complex types
Implement the support for the `_Fcomplex` and `_Dcomplex` types used by MSVC in place of the standard C99 complex types. This is necessary to make LAPACK build out of the box with MSVC, since it does not implement the default C99 types. See: https://learn.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support I went for the simplest implementation possible, limiting the changes to swapping the default types used when MSVC is used as the compiler, also when `lapack_config.h` is not used. I haven't added a `LAPACK_COMPLEX_*` ifdef for it, but I can do that if you prefer. Signed-off-by: Michał Górny <mgorny@quansight.com>
1 parent 9f4032e commit 548f623

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

LAPACKE/include/lapack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@
4747
#else
4848
#include <complex>
4949
#endif
50+
#if _MSC_VER
51+
#define lapack_complex_float _Fcomplex
52+
#else
5053
#define lapack_complex_float float _Complex
5154
#endif
55+
#endif
5256

5357
#ifndef lapack_complex_float_real
5458
#define lapack_complex_float_real(z) (creal(z))
@@ -65,8 +69,12 @@
6569
#else
6670
#include <complex>
6771
#endif
72+
#if _MSC_VER
73+
#define lapack_complex_double _Dcomplex
74+
#else
6875
#define lapack_complex_double double _Complex
6976
#endif
77+
#endif
7078

7179
#ifndef lapack_complex_double_real
7280
#define lapack_complex_double_real(z) (creal(z))

LAPACKE/include/lapacke_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ typedef struct { double real, imag; } _lapack_complex_double;
9999
#define lapack_complex_double_real(z) ((z).real())
100100
#define lapack_complex_double_imag(z) ((z).imag())
101101

102+
#elif _MSC_VER
103+
104+
#include <complex.h>
105+
#define lapack_complex_float _Fcomplex
106+
#define lapack_complex_double _Dcomplex
107+
#define lapack_complex_float_real(z) (crealf(z))
108+
#define lapack_complex_float_imag(z) (cimagf(z))
109+
#define lapack_complex_double_real(z) (creal(z))
110+
#define lapack_complex_double_imag(z) (cimag(z))
111+
102112
#else
103113

104114
#include <complex.h>

LAPACKE/utils/lapacke_make_complex_double.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ lapack_complex_double lapack_make_complex_double( double re, double im ) {
4343
z = re + im * I;
4444
#elif defined(LAPACK_COMPLEX_CPP)
4545
z = std::complex<double>(re,im);
46+
#elif _MSC_VER
47+
z = _Cbuild(re, im);
4648
#else /* C99 is default */
4749
z = re + im*I;
4850
#endif

LAPACKE/utils/lapacke_make_complex_float.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ lapack_complex_float lapack_make_complex_float( float re, float im ) {
4343
z = re + im * I;
4444
#elif defined(LAPACK_COMPLEX_CPP)
4545
z = std::complex<float>(re,im);
46+
#elif _MSC_VER
47+
z = _FCbuild(re, im);
4648
#else /* C99 is default */
4749
z = re + im*I;
4850
#endif

0 commit comments

Comments
 (0)