Complex numer

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Tomper
Posts: 19
Joined: 30 Aug 2008 02:15

Complex numer

#1 Post by Tomper » 22 Oct 2008 13:28

Hi

Can I use complex numbers in mikroC? How would I go about using complex numbers? i.e a + b*I where I=sqrt(-1) is this possible? I am new to programming and really need help

ebeinecke
Posts: 32
Joined: 20 Apr 2010 21:54

Re: Complex numer

#2 Post by ebeinecke » 20 Apr 2010 21:56

I would like to know that too ! My research is dependent in Transfer Functions who extensally use complex numbers

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: Complex numbers

#3 Post by womai » 19 May 2010 17:07

There's not built-in supply for complex numbers in MikroC (or in any standard C compiler for that matter). But you can always write your own functions that take real and imaginary part (a and b in your example) and perform the calculations according to textbook rules for imaginary numbers. Storage for complex numbers is easy - just use two float variables, one holding the real part and one the imaginary part. Also I'm sure a web search will turn up plenty of code examples in ANSI C. You may want to define a struct for easier handling.
Last edited by womai on 19 Jul 2010 08:51, edited 1 time in total.

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: Complex numer

#4 Post by womai » 18 Jul 2010 17:25

Here is a link to ANSI C routines for complex numbers. That should be easy to adapt for MikroC (if there are any changes required at all - I haven't tried it):

http://www.phanderson.com/complex/index.html

Regards,

Wolfgang

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Complex numer

#5 Post by slavisa.zlatanovic » 19 Jul 2010 08:40

Hi!

Just to confirm that I agree with womai on this subject.

Regards
Slavisa
Best regards
Slavisa

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”