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"
15 struct cl_heap_complex : cl_heap {
20 inline cl_heap_complex* TheComplex (cl_heap_complex* p)
22 inline cl_heap_complex* TheComplex (const cl_number& obj)
23 { return (cl_heap_complex*)(obj.pointer); }
25 inline cl_heap_complex* allocate_complex (const cl_R& real, const cl_R& imag)
27 cl_heap_complex* p = (cl_heap_complex*) cl_malloc_hook(sizeof(cl_heap_complex));
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);
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) {}
40 // Both work, but the first definition results in less compiler-generated
43 #define Complex cl_heap_complex*
49 inline cl_boolean realp (const cl_N& x)
52 if (x.heappointer->type == &cl_class_complex)
56 inline cl_boolean complexp (const cl_N& x)
59 if (x.heappointer->type == &cl_class_complex)
64 // Comparison with a fixnum.
65 inline cl_boolean eq (const cl_N& x, sint32 y)
67 return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
70 inline cl_boolean exact_zerop (const cl_N& x)
76 // A complex (cl_C) is a number which is not a real number (cl_R).
79 class cl_C : public cl_N {
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; }
89 // Liefert zu reellen Zahlen a und b /= Fixnum 0 die komplexe Zahl a+bi.
91 extern const cl_N complex_C (const cl_R& a, const cl_R& b);
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)
97 return TheComplex(x)->realpart;
99 inline const cl_R& imagpart (const cl_C& x)
101 return TheComplex(x)->imagpart;
105 // Primitive forms of complex numbers with restricted part type.
111 cl_C_SF (const cl_SF& re, const cl_SF& im) : realpart(re), imagpart(im) {}
113 inline const cl_N complex_C (const cl_C_SF& c)
114 { return complex_C(c.realpart,c.imagpart); }
120 cl_C_FF (const cl_FF& re, const cl_FF& im) : realpart(re), imagpart(im) {}
122 inline const cl_N complex_C (const cl_C_FF& c)
123 { return complex_C(c.realpart,c.imagpart); }
129 cl_C_DF (const cl_DF& re, const cl_DF& im) : realpart(re), imagpart(im) {}
131 inline const cl_N complex_C (const cl_C_DF& c)
132 { return complex_C(c.realpart,c.imagpart); }
138 cl_C_LF (const cl_LF& re, const cl_LF& im) : realpart(re), imagpart(im) {}
140 inline const cl_N complex_C (const cl_C_LF& c)
141 { return complex_C(c.realpart,c.imagpart); }
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);
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);
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);
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);
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);
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);
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);
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);
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);
171 // Liefert (abs x), wo x eine nicht-reelle Zahl ist.
172 extern const cl_R abs (const cl_C& x);
179 cl_C_R () : realpart(0), imagpart(0) {}
180 cl_C_R (const cl_R& re, const cl_R& im) : realpart(re), imagpart(im) {}
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);
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);