]> www.ginac.de Git - cln.git/blob - src/complex/cl_C.h
- Compatibility was not really broken, so: C=0, R=1, A=0.
[cln.git] / src / complex / cl_C.h
1 // cl_C internals
2
3 #ifndef _CL_C_H
4 #define _CL_C_H
5
6 #include "cl_number.h"
7 #include "cl_complex.h"
8 #include "cl_sfloat_class.h"
9 #include "cl_ffloat_class.h"
10 #include "cl_dfloat_class.h"
11 #include "cl_lfloat_class.h"
12 #include "cl_macros.h"
13 #include "cl_malloc.h"
14
15 struct cl_heap_complex : cl_heap {
16         cl_R realpart;
17         cl_R imagpart;
18 };
19
20 inline cl_heap_complex* TheComplex (cl_heap_complex* p)
21         { return p; }
22 inline cl_heap_complex* TheComplex (const cl_number& obj)
23         { return (cl_heap_complex*)(obj.pointer); }
24
25 inline cl_heap_complex* allocate_complex (const cl_R& real, const cl_R& imag)
26 {
27         cl_heap_complex* p = (cl_heap_complex*) cl_malloc_hook(sizeof(cl_heap_complex));
28         p->refcount = 1;
29         p->type = &cl_class_complex;
30         p->realpart.pointer = real.pointer;     cl_inc_refcount(real);
31         p->imagpart.pointer = imag.pointer;     cl_inc_refcount(imag);
32         return p;
33 }
34
35 // Private constructor.
36 // ptr should be the result of some allocate_complex() call.
37 inline cl_N::cl_N (cl_heap_complex* ptr)
38         : cl_number ((cl_private_thing) ptr) {}
39
40 // Both work, but the first definition results in less compiler-generated
41 // temporaries.
42 #if 1
43   #define Complex  cl_heap_complex*
44 #else
45   #define Complex  cl_N
46 #endif
47
48 // Type tests
49 inline cl_boolean realp (const cl_N& x)
50 {
51         if (x.pointer_p())
52                 if (x.heappointer->type == &cl_class_complex)
53                         return cl_false;
54         return cl_true;
55 }
56 inline cl_boolean complexp (const cl_N& x)
57 {
58         if (x.pointer_p())
59                 if (x.heappointer->type == &cl_class_complex)
60                         return cl_true;
61         return cl_false;
62 }
63
64 // Comparison with a fixnum.
65 inline cl_boolean eq (const cl_N& x, sint32 y)
66 {
67         return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
68 }
69
70 inline cl_boolean exact_zerop (const cl_N& x)
71 {
72         return eq(x,0);
73 }
74
75
76 // A complex (cl_C) is a number which is not a real number (cl_R).
77
78 // typedef
79 class cl_C : public cl_N {
80 public:
81 };
82
83 inline cl_boolean realp (const cl_C& x)
84         { unused x; return cl_false; }
85 inline cl_boolean complexp (const cl_C& x)
86         { unused x; return cl_true; }
87
88
89 // Liefert zu reellen Zahlen a und b /= Fixnum 0 die komplexe Zahl a+bi.
90 // complex_C(a,b)
91 extern const cl_N complex_C (const cl_R& a, const cl_R& b);
92
93 // realpart(x) liefert den Realteil der Zahl x.
94 // imagpart(x) liefert den Imaginärteil der Zahl x.
95 inline const cl_R& realpart (const cl_C& x)
96 {
97         return TheComplex(x)->realpart;
98 }
99 inline const cl_R& imagpart (const cl_C& x)
100 {
101         return TheComplex(x)->imagpart;
102 }
103
104
105 // Primitive forms of complex numbers with restricted part type.
106
107 // typedef
108 struct cl_C_SF {
109         cl_SF realpart;
110         cl_SF imagpart;
111         cl_C_SF (const cl_SF& re, const cl_SF& im) : realpart(re), imagpart(im) {}
112 };
113 inline const cl_N complex_C (const cl_C_SF& c)
114         { return complex_C(c.realpart,c.imagpart); }
115
116 // typedef
117 struct cl_C_FF {
118         cl_FF realpart;
119         cl_FF imagpart;
120         cl_C_FF (const cl_FF& re, const cl_FF& im) : realpart(re), imagpart(im) {}
121 };
122 inline const cl_N complex_C (const cl_C_FF& c)
123         { return complex_C(c.realpart,c.imagpart); }
124
125 // typedef
126 struct cl_C_DF {
127         cl_DF realpart;
128         cl_DF imagpart;
129         cl_C_DF (const cl_DF& re, const cl_DF& im) : realpart(re), imagpart(im) {}
130 };
131 inline const cl_N complex_C (const cl_C_DF& c)
132         { return complex_C(c.realpart,c.imagpart); }
133
134 // typedef
135 struct cl_C_LF {
136         cl_LF realpart;
137         cl_LF imagpart;
138         cl_C_LF (const cl_LF& re, const cl_LF& im) : realpart(re), imagpart(im) {}
139 };
140 inline const cl_N complex_C (const cl_C_LF& c)
141         { return complex_C(c.realpart,c.imagpart); }
142
143 // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b Short-Floats sind.
144 extern const cl_C_SF cl_C_recip (const cl_SF& a, const cl_SF& b);
145
146 // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b Single-Floats sind.
147 extern const cl_C_FF cl_C_recip (const cl_FF& a, const cl_FF& b);
148
149 // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b Double-Floats sind.
150 extern const cl_C_DF cl_C_recip (const cl_DF& a, const cl_DF& b);
151
152 // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b gleichlange Long-Floats sind.
153 extern const cl_C_LF cl_C_recip (const cl_LF& a, const cl_LF& b);
154
155
156 // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b Short-Floats sind.
157 extern const cl_SF cl_hypot (const cl_SF& a, const cl_SF& b);
158
159 // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b Single-Floats sind.
160 extern const cl_FF cl_hypot (const cl_FF& a, const cl_FF& b);
161
162 // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b Double-Floats sind.
163 extern const cl_DF cl_hypot (const cl_DF& a, const cl_DF& b);
164
165 // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b gleichlange Long-Floats sind.
166 extern const cl_LF cl_hypot (const cl_LF& a, const cl_LF& b);
167
168 // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b reelle Zahlen sind.
169 extern const cl_R cl_hypot (const cl_R& a, const cl_R& b);
170
171 // Liefert (abs x), wo x eine nicht-reelle Zahl ist.
172 extern const cl_R abs (const cl_C& x);
173
174
175 // typedef
176 struct cl_C_R {
177         cl_R realpart;
178         cl_R imagpart;
179         cl_C_R () : realpart(0), imagpart(0) {}
180         cl_C_R (const cl_R& re, const cl_R& im) : realpart(re), imagpart(im) {}
181 };
182
183 // Hilfsfunktion für atanh und atan: u+iv := artanh(x+iy). Liefert cl_C_R(u,v).
184 extern const cl_C_R atanh (const cl_R& x, const cl_R& y);
185
186 // Hilfsfunktion für asinh und asin: u+iv := arsinh(x+iy). Liefert cl_C_R(u,v).
187 extern const cl_C_R asinh (const cl_R& x, const cl_R& y);
188
189
190 #endif /* _CL_C_H */