Skip to content

Commit

Permalink
interface: Start MSVC fixes
Browse files Browse the repository at this point in the history
MSVC does not support C complex numbers.
There's a different approach here. Thus, we try to fix it with some
additional burden. Let's poke the CI.

Signed-off-by: Johannes Demel <[email protected]>
  • Loading branch information
jdemel committed Oct 2, 2021
1 parent 043099a commit 6f6ef23
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion include/volk/volk_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <volk/volk_common.h>

__VOLK_DECL_BEGIN

#ifndef __STDC_NO_COMPLEX__
// Obviously, we would love `typedef float complex lv_32fc_t` to work.
// However, this clashes with C++ definitions.
// error: expected initializer before ‘lv_32fc_t’
Expand All @@ -35,6 +35,37 @@ typedef long long _Complex lv_64sc_t;
typedef float _Complex lv_32fc_t;
typedef double _Complex lv_64fc_t;

#else
// MSVC requires different treatment.
// https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-160
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support?view=msvc-160
// Refer to `complex.h` in
// https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/

typedef _Fcomplex lv_32fc_t;
typedef _Dcomplex lv_64fc_t;

// typedef char _Complex lv_8sc_t;
typedef struct lv_8sc_t {
char _Val[2];
} lv_8sc_t;

// typedef short _Complex lv_16sc_t;
typedef struct lv_16sc_t {
short _Val[2];
} lv_16sc_t;

// typedef long _Complex lv_32sc_t;
typedef struct lv_32sc_t {
long _Val[2];
} lv_32sc_t;

// typedef long long _Complex lv_64sc_t;
typedef struct lv_64sc_t {
long long _Val[2];
} lv_64sc_t;
#endif

#define lv_cmake(r, i) ((r) + _Complex_I * (i))
// We want `_Imaginary_I` to ensure the correct sign.
// https://en.cppreference.com/w/c/numeric/complex/Imaginary_I
Expand Down

0 comments on commit 6f6ef23

Please sign in to comment.