]> www.ginac.de Git - cln.git/blob - src/complex/elem/cl_C_square.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / complex / elem / cl_C_square.cc
1 // square().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/complex.h"
8
9
10 // Implementation.
11
12 #include "cl_C.h"
13 #include "cln/real.h"
14
15 namespace cln {
16
17 const cl_N square (const cl_N& x)
18 {
19 // Methode:
20 // x reell -> klar.
21 // x=a+bi -> (a^2-b^2)+(2*a*b)i
22         if (realp(x)) {
23                 DeclareType(cl_R,x);
24                 return square(x);
25         } else {
26                 DeclareType(cl_C,x);
27                 var const cl_R& a = realpart(x);
28                 var const cl_R& b = imagpart(x);
29                 return complex_C(square(a)-square(b),2*a*b);
30         }
31 }
32
33 }  // namespace cln