hello everyone,
I have been working for my Data structures class for a week now and have been attempting to understand this whole complex numbers concept. My textbook has very little description on the operations for complex numbers, so I was hoping someone here would be better able to explain it to me. I am trying to write the code to overload the - symbol for a complex number for my complex class. I was struggling mostly with understanding how does one negate a complex number. Heres the basic outline for the code I have come up with. Any and all help would really be appreciated.
heres the definition within the class.
complex operator- () const;
//negation of a complex number
first off, C99 has all of this as does MSVC++ (Complex class)
Seondly, complex numbers do messy stuff for relatively simple operations.
Here is a simplified version of some really old complex functions written in C for students learning pointers & structs. This is NOT production code, it's too slow.
I'm sure you can find a good description of complex numbers and it's operations on the internet. Don't search for code, but rather for pure math. Or ask in the Math forum here, but I'm not sure if anyone still goes there.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Hello again,
The problem I was given gives me a class description, and left the class implementation for me to finish. I have attached the header file and the source file. Everything works except for when I attempt to negate a complex number. if you compile the code and run it it wont come up with any errors because I have commented the three lines that are giving me problems. Ultimately I am trying to prove that -i * i = 1.
I cant quite figure out how to negate a complex number. I have been searching on the internet, but most of the complex number information does not include negating a complex number.
Originally posted by CornedBee return complex(-real, -imag);
even shorter, and you should inline this function.
I was thinking about that but wasnt so sure it would work and since i didnt have time to check, i just did what i thought was the safest, shortest way! lol.