Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is a good way to implement complex numbers in C?
What is a good way to implement complex numbers in C?
✍: Guest
It is straightforward to define a simple structure and some arithmetic functions to manipulate them. C99 supports complex as a standard type. Here is a tiny example, to give you a feel for it:
typedef struct {
double real;
double imag;
} complex;
#define Real(c) (c).real
#define Imag(c) (c).imag
complex cpx_make(double real, double imag)
{
complex ret;
ret.real = real;
ret.imag = imag;
return ret;
}
complex cpx_add(complex a, complex b)
{
return cpx_make(Real(a) + Real(b), Imag(a) + Imag(b));
}
You can use these routines with code like
complex a = cpx_make(1, 2);
complex b = cpx_make(3, 4);
complex c = cpx_add(a, b);
or, even more simply,
complex c = cpx_add(cpx_make(1, 2), cpx_make(3, 4));
2015-06-19, 1922👍, 0💬
Popular Posts:
How To Run "mysql" Commands from a Batch File? - MySQL FAQs - Command-Line End User Interface mysql ...
An application needs to load a library before it starts to run, how to code? One option is to use a ...
What is Traceability Matrix? Traceability Matrix is one of the document will prepare by QA.To make s...
Enable ASP.NET polling using “web.config” file Now that all our database side is configured in order...
How To Change System Global Area (SGA)? - Oracle DBA FAQ - Introduction to Oracle Database 10g Expre...