Please take a minute to review and accept our Terms of Use.
Welcome to PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Working with complex numbers in C-Script block

+1 vote


I'm trying to make complex numbers operations in a C-Script in my model, but when i try to compile the next error is shown:

source:78:38: error: imaginary constants are an extension

I'm including the file "complex.h", and I defined the numbers as a + b * I for example. 

Have anyone worked with complex numbers and succesfully compiled the C-Script?

Best regards,

Sebastián Neira.

asked Jan 30 by sfneira (13 points)

1 Answer

+1 vote


you can work around the extension error by defining your own imaginary constant:

const double complex i = csqrt(-1);

However, depending on your operating system you'll most likely see other errors later. In short, we do not support complex calculations in C-Scripts at this time, but we'll see whether this can be improved in a later release.

Kind regards,

Oliver Schwartz

answered Jan 30 by Oliver Schwartz (34 points)
edited Jan 30 by Oliver Schwartz