Home Ask Login Register

Developers Planet

Your answer is one click away!

newt February 2016

Library for complex numbers in Dev-C++

What is the library for complex numbers in Dev-C++ (version 5.11)? I tried to use

#include <complex.h>

but it doesn't work:

39  2   C:\Users\Àíòîí\Documents\DevCC_Projects\fourier\main.cpp    [Error] 'complex' was not declared in this scope

So I cannot use functions like


What is an alternative?


FrankM February 2016

The complex class is c++ and is in the complex header. Use instead:

#include <complex>

Documentation for the class can be found in http://www.cplusplus.com/reference/complex/

Lajos Arpad February 2016

Why don't you implement one? It is not that hard. Basically you need a class Complex, which will have two members, r and i, you need to override a few operators, like:

+: (a + b).r === a.r + b.r, (a + b).i === (a.i + b.i)

-: (a - b).r === a.r - b.r, (a - b).i === (a.i - b.i)

*: (a * b).r === a.r * b.r - (a.i * b.i), (a * b).r === a.r * b.i + a.i * b.r

/: (a / b).r === a.r * b.r - (a.i * b.i), (a / b).i (a.r * b.i + a.i * b.r)

Make sure that you handle the special case of division by 0. Also, you might implement ++, --, <<, >> and so on, according to your taste.

Post Status

Asked in February 2016
Viewed 3,069 times
Voted 10
Answered 2 times


Leave an answer

Quote of the day: live life