Arithmetic/Complex: Difference between revisions

(→‎{{header|Java}}: Add conjugate)
(→‎{{header|C}}: conjugate)
Line 265:
The more recent [[C99]] standard has built-in complex number primitive types, which can be declared with float, double, or long double precision. To use these types and their associated library functions, you must include the <complex.h> header. (Note: this is a ''different'' header than the <complex> templates that are defined by [[C++]].) [http://www.opengroup.org/onlinepubs/009695399/basedefs/complex.h.html] [http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm]
<lang c>#include <complex.h>
#include <stdio.h>
 
void cprint(double complex c)
Line 290 ⟶ 291:
// negation
c = -a;
printf("\n-a="); cprint(c); printf("\n");
// conjugate
c = conj(a);
printf("\nconj a="); cprint(c); printf("\n");
}</lang>
 
Line 325 ⟶ 329:
Complex ans;
ans.real = -a.real;
ans.imag = -a.imag;
return ans;
}
 
Complex conj(Complex a){
Complex ans;
ans.imag = -a.imag;
return ans;
Line 344 ⟶ 354:
printf("\na*b="); put(mult(a,b));
printf("\n1/a="); put(inv(a));
printf("\n-a="); put(neg(a)); printf("\n");
printf("\nconj a="); put(conj(a)); printf("\n");
}</lang>
 
Anonymous user