Talk:Arithmetic/Complex: Difference between revisions

Content added Content deleted
(C99 is correct)
(→‎C99 example incorrect?: more explanation, change task to require output for confirmation)
Line 12: Line 12:
:::::::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)
:::::::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)
:::::Waldorf, I don't know what you're going on about. When I compile this with '''gcc -std=c99''' I get correct results (once I corrected the constants). The implicit conversions only happen when there are type mismatches, but all the operations are between complex types. For 1.0/a, there is an ''up'' conversion to 1+0i before dividing. The standard operators are all defined correctly for complex types, and other library functions like '''conj()''' for the conjugate are defined for complex-specific operations. --[[User:IanOsgood|IanOsgood]] 10:47, 13 March 2008 (MDT)
:::::Waldorf, I don't know what you're going on about. When I compile this with '''gcc -std=c99''' I get correct results (once I corrected the constants). The implicit conversions only happen when there are type mismatches, but all the operations are between complex types. For 1.0/a, there is an ''up'' conversion to 1+0i before dividing. The standard operators are all defined correctly for complex types, and other library functions like '''conj()''' for the conjugate are defined for complex-specific operations. --[[User:IanOsgood|IanOsgood]] 10:47, 13 March 2008 (MDT)
:::::As for operator overloading, perhaps you are confusing this with operator overloading for ''user defined'' types. This is trivially true for C because you cannot define functions that overload the symbolic infix operators (as opposed to the operator+() overloading in C++). However operator overloading for ''built-in'' types is well supported in C. C99 happens to add complex numbers as built-in types. --[[User:IanOsgood|IanOsgood]] 11:10, 13 March 2008 (MDT)
:::::To avoid this kind of argument in the future, I am changing the task requirements to require printing the results. --[[User:IanOsgood|IanOsgood]] 11:10, 13 March 2008 (MDT)