Talk:Arithmetic/Complex: Difference between revisions

I see now...sorry
(Wrong is still wrong.)
(I see now...sorry)
Line 8:
:::::The only ways I can think of to convert a complex number to a purely real number without losing information is to find the length of the number in the complex plane or convert it to polar form. You can't reconstruct the original number from the length, so that shouldn't be done for this conversion. The polar form still requires two parts (magnitude and angle), so it's not really a primitive (at least in C). I don't know why anyone would want to convert a complex number to a real number when you can just get the "real part." The C example is not incorrect as the task is written because the task says nothing about casting to anything. A complex number is a complex number and that's all it will ever be. Any casts to purely real types ''should'' have information loss. (int)(2.5 + 3.2i) should be 2. (Complex)(3*5) should be 15 + 0i. That's how anyone could expect it to work. --[[User:Mwn3d|Mwn3d]] 08:49, 13 March 2008 (MDT)
::::::I agree with what you say. The task requires addition and multiplication of two complex numbers, and inversion and negation of a single complex number. The C solution uses C arithmetic operators. C99 does not provide operator overloading. This means that the arithmetic operators can only be used if implicit conversion to a primitive type occurs. Either the example is wrong because it improperly uses arithmetic operators for complex arithmetic, or it is wrong because implicit conversions result in real arithmetic, not complex arithmetic. The truth can be easily demonstrated by printing the results of the operations in C.--[[User:Waldorf|Waldorf]] 09:30, 13 March 2008 (MDT)
:::::::OK...looking into it you're right. I offer two solutions. 1: I added an example which defines a struct and the desired operations, 2: rework the complex.h solution to use creal and cimag functions (from [http://en.wikipedia.org/wiki/Complex.h complex.h]) as part of other functions to do the math. --[[User:Mwn3d|Mwn3d]] 10:01, 13 March 2008 (MDT)
Anonymous user