]> www.ginac.de Git - cln.git/blob - include/cln/real.h
2006-05-30 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
[cln.git] / include / cln / real.h
1 // Public real number operations.
2
3 #ifndef _CL_REAL_H
4 #define _CL_REAL_H
5
6 #include "cln/number.h"
7 #include "cln/real_class.h"
8 #include "cln/rational_class.h"
9 #include "cln/integer_class.h"
10 #include "cln/float.h"
11 #include "cln/floatformat.h"
12 #include "cln/random.h"
13
14 namespace cln {
15
16 CL_DEFINE_AS_CONVERSION(cl_R)
17
18
19 // zerop(x) testet, ob (= x 0).
20 extern cl_boolean zerop (const cl_R& x);
21
22 // minusp(x) testet, ob (< x 0).
23 extern cl_boolean minusp (const cl_R& x);
24
25 // plusp(x) testet, ob (> x 0).
26 extern cl_boolean plusp (const cl_R& x);
27
28
29 // R_to_SF(x) wandelt eine reelle Zahl x in ein Short-Float um.
30 // < ergebnis: (coerce x 'short-float)
31 extern const cl_SF cl_R_to_SF (const cl_R& x);
32
33 // R_to_FF(x) wandelt eine reelle Zahl x in ein Single-Float um.
34 // < ergebnis: (coerce x 'single-float)
35 extern const cl_FF cl_R_to_FF (const cl_R& x);
36
37 // R_to_DF(x) wandelt eine reelle Zahl x in ein Double-Float um.
38 // < ergebnis: (coerce x 'double-float)
39 extern const cl_DF cl_R_to_DF (const cl_R& x);
40
41 // R_to_LF(x,len) wandelt eine reelle Zahl x in ein Long-Float mit len Digits um.
42 // > uintC len: gewünschte Anzahl Digits, >=LF_minlen
43 // < ergebnis: (coerce x `(long-float ,len))
44 extern const cl_LF cl_R_to_LF (const cl_R& x, uintC len);
45
46 // cl_float(x,y) wandelt eine reelle Zahl x in das Float-Format des
47 // Floats y um und rundet dabei nötigenfalls.
48 // > x: eine reelle Zahl
49 // > y: ein Float
50 // < ergebnis: (float x y)
51 extern const cl_F cl_float (const cl_R& x, const cl_F& y);
52
53 // cl_float(x,f) wandelt eine reelle Zahl x in das Float-Format f um
54 // und rundet dabei nötigenfalls.
55 // > x: eine reelle Zahl
56 // > f: eine Float-Format-Spezifikation
57 // < ergebnis: (float x f)
58 extern const cl_F cl_float (const cl_R& x, float_format_t f);
59
60 // cl_float(x) wandelt eine reelle Zahl x in ein Float um
61 // und rundet dabei nötigenfalls.
62 // > x: eine reelle Zahl
63 // < ergebnis: (float x)
64 // Abhängig von default_float_format.
65 extern const cl_F cl_float (const cl_R& x);
66
67
68 // Liefert (- x), wo x eine reelle Zahl ist.
69 extern const cl_R operator- (const cl_R& x);
70
71 // Liefert (+ x y), wo x und y reelle Zahlen sind.
72 extern const cl_R operator+ (const cl_R& x, const cl_R& y);
73 // Spezialfall: x oder y Float -> Ergebnis Float
74 inline const cl_F operator+ (const cl_R& x, const cl_F& y)
75         { return The(cl_F)(x + The(cl_R)(y)); }
76 inline const cl_F operator+ (const cl_F& x, const cl_R& y)
77         { return The(cl_F)(The(cl_R)(x) + y); }
78 // Dem C++-Compiler muß man nun auch das Folgende sagen:
79 inline const cl_R operator+ (const int x, const cl_R& y)
80         { return cl_I(x) + y; }
81 inline const cl_R operator+ (const unsigned int x, const cl_R& y)
82         { return cl_I(x) + y; }
83 inline const cl_R operator+ (const long x, const cl_R& y)
84         { return cl_I(x) + y; }
85 inline const cl_R operator+ (const unsigned long x, const cl_R& y)
86         { return cl_I(x) + y; }
87 inline const cl_F operator+ (const float x, const cl_R& y)
88         { return The(cl_F)(cl_R(x) + y); }
89 inline const cl_F operator+ (const double x, const cl_R& y)
90         { return The(cl_F)(cl_R(x) + y); }
91 inline const cl_R operator+ (const cl_R& x, const int y)
92         { return x + cl_I(y); }
93 inline const cl_R operator+ (const cl_R& x, const unsigned int y)
94         { return x + cl_I(y); }
95 inline const cl_R operator+ (const cl_R& x, const long y)
96         { return x + cl_I(y); }
97 inline const cl_R operator+ (const cl_R& x, const unsigned long y)
98         { return x + cl_I(y); }
99 inline const cl_F operator+ (const cl_R& x, const float y)
100         { return The(cl_F)(x + cl_R(y)); }
101 inline const cl_F operator+ (const cl_R& x, const double y)
102         { return The(cl_F)(x + cl_R(y)); }
103
104 // Liefert (- x y), wo x und y reelle Zahlen sind.
105 extern const cl_R operator- (const cl_R& x, const cl_R& y);
106 // Spezialfall: x oder y Float -> Ergebnis Float
107 inline const cl_F operator- (const cl_R& x, const cl_F& y)
108         { return The(cl_F)(x - The(cl_R)(y)); }
109 inline const cl_F operator- (const cl_F& x, const cl_R& y)
110         { return The(cl_F)(The(cl_R)(x) - y); }
111 // Dem C++-Compiler muß man nun auch das Folgende sagen:
112 inline const cl_R operator- (const int x, const cl_R& y)
113         { return cl_I(x) - y; }
114 inline const cl_R operator- (const unsigned int x, const cl_R& y)
115         { return cl_I(x) - y; }
116 inline const cl_R operator- (const long x, const cl_R& y)
117         { return cl_I(x) - y; }
118 inline const cl_R operator- (const unsigned long x, const cl_R& y)
119         { return cl_I(x) - y; }
120 inline const cl_F operator- (const float x, const cl_R& y)
121         { return The(cl_F)(cl_R(x) - y); }
122 inline const cl_F operator- (const double x, const cl_R& y)
123         { return The(cl_F)(cl_R(x) - y); }
124 inline const cl_R operator- (const cl_R& x, const int y)
125         { return x - cl_I(y); }
126 inline const cl_R operator- (const cl_R& x, const unsigned int y)
127         { return x - cl_I(y); }
128 inline const cl_R operator- (const cl_R& x, const long y)
129         { return x - cl_I(y); }
130 inline const cl_R operator- (const cl_R& x, const unsigned long y)
131         { return x - cl_I(y); }
132 inline const cl_F operator- (const cl_R& x, const float y)
133         { return The(cl_F)(x - cl_R(y)); }
134 inline const cl_F operator- (const cl_R& x, const double y)
135         { return The(cl_F)(x - cl_R(y)); }
136
137 // Liefert (* x y), wo x und y reelle Zahlen sind.
138 extern const cl_R operator* (const cl_R& x, const cl_R& y);
139 // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int * cl_F' u.ä.):
140 inline const cl_R operator* (const int x, const cl_R& y)
141         { return cl_I(x) * y; }
142 inline const cl_R operator* (const unsigned int x, const cl_R& y)
143         { return cl_I(x) * y; }
144 inline const cl_R operator* (const long x, const cl_R& y)
145         { return cl_I(x) * y; }
146 inline const cl_R operator* (const unsigned long x, const cl_R& y)
147         { return cl_I(x) * y; }
148 inline const cl_R operator* (const float x, const cl_R& y)
149         { return cl_R(x) * y; }
150 inline const cl_R operator* (const double x, const cl_R& y)
151         { return cl_R(x) * y; }
152 inline const cl_R operator* (const cl_R& x, const int y)
153         { return x * cl_I(y); }
154 inline const cl_R operator* (const cl_R& x, const unsigned int y)
155         { return x * cl_I(y); }
156 inline const cl_R operator* (const cl_R& x, const long y)
157         { return x * cl_I(y); }
158 inline const cl_R operator* (const cl_R& x, const unsigned long y)
159         { return x * cl_I(y); }
160 inline const cl_R operator* (const cl_R& x, const float y)
161         { return x * cl_R(y); }
162 inline const cl_R operator* (const cl_R& x, const double y)
163         { return x * cl_R(y); }
164
165 // Liefert (* x x), wo x eine reelle Zahl ist.
166 extern const cl_R square (const cl_R& x);
167
168 // Liefert (/ x y), wo x und y reelle Zahlen sind.
169 extern const cl_R operator/ (const cl_R& x, const cl_R& y);
170 // Spezialfall: x Float -> Ergebnis Float
171 inline const cl_F operator/ (const cl_F& x, const cl_R& y)
172         { return The(cl_F)(The(cl_R)(x) / y); }
173 // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int / cl_F' u.ä.):
174 inline const cl_R operator/ (const int x, const cl_R& y)
175         { return cl_I(x) / y; }
176 inline const cl_R operator/ (const unsigned int x, const cl_R& y)
177         { return cl_I(x) / y; }
178 inline const cl_R operator/ (const long x, const cl_R& y)
179         { return cl_I(x) / y; }
180 inline const cl_R operator/ (const unsigned long x, const cl_R& y)
181         { return cl_I(x) / y; }
182 inline const cl_F operator/ (const float x, const cl_R& y)
183         { return The(cl_F)(cl_R(x) / y); }
184 inline const cl_F operator/ (const double x, const cl_R& y)
185         { return The(cl_F)(cl_R(x) / y); }
186 inline const cl_R operator/ (const cl_R& x, const int y)
187         { return x / cl_I(y); }
188 inline const cl_R operator/ (const cl_R& x, const unsigned int y)
189         { return x / cl_I(y); }
190 inline const cl_R operator/ (const cl_R& x, const long y)
191         { return x / cl_I(y); }
192 inline const cl_R operator/ (const cl_R& x, const unsigned long y)
193         { return x / cl_I(y); }
194 inline const cl_R operator/ (const cl_R& x, const float y)
195         { return x / cl_R(y); }
196 inline const cl_R operator/ (const cl_R& x, const double y)
197         { return x / cl_R(y); }
198
199 // Liefert (abs x), wo x eine reelle Zahl ist.
200 extern const cl_R abs (const cl_R& x);
201
202 // recip(x) liefert (/ x), wo x eine reelle Zahl ist.
203 extern const cl_R recip (const cl_R& x);
204
205 // (1+ x), wo x eine reelle Zahl ist.
206 extern const cl_R plus1 (const cl_R& x);
207
208 // (1- x), wo x eine reelle Zahl ist.
209 extern const cl_R minus1 (const cl_R& x);
210
211
212 // Return type for rounding operators.
213 // x / y  --> (q,r) with x = y*q+r.
214 struct cl_R_div_t {
215         cl_I quotient;
216         cl_R remainder;
217 // Constructor.
218         cl_R_div_t () {}
219         cl_R_div_t (const cl_I& q, const cl_R& r) : quotient(q), remainder(r) {}
220         cl_R_div_t (const struct cl_I_div_t &);
221         cl_R_div_t (const struct cl_RA_div_t &);
222         cl_R_div_t (const struct cl_F_div_t &);
223 };
224
225 // floor2(x) liefert (floor x), wo x eine reelle Zahl ist.
226 extern const cl_R_div_t floor2 (const cl_R& x);
227 extern const cl_I floor1 (const cl_R& x);
228
229 // ceiling2(x) liefert (ceiling x), wo x eine reelle Zahl ist.
230 extern const cl_R_div_t ceiling2 (const cl_R& x);
231 extern const cl_I ceiling1 (const cl_R& x);
232
233 // truncate2(x) liefert (truncate x), wo x eine reelle Zahl ist.
234 extern const cl_R_div_t truncate2 (const cl_R& x);
235 extern const cl_I truncate1 (const cl_R& x);
236
237 // round2(x) liefert (round x), wo x eine reelle Zahl ist.
238 extern const cl_R_div_t round2 (const cl_R& x);
239 extern const cl_I round1 (const cl_R& x);
240
241 // floor2(x,y) liefert (floor x y), wo x und y reelle Zahlen sind.
242 extern const cl_R_div_t floor2 (const cl_R& x, const cl_R& y);
243 extern const cl_I floor1 (const cl_R& x, const cl_R& y);
244
245 // ceiling2(x,y) liefert (ceiling x y), wo x und y reelle Zahlen sind.
246 extern const cl_R_div_t ceiling2 (const cl_R& x, const cl_R& y);
247 extern const cl_I ceiling1 (const cl_R& x, const cl_R& y);
248
249 // truncate2(x,y) liefert (truncate x y), wo x und y reelle Zahlen sind.
250 extern const cl_R_div_t truncate2 (const cl_R& x, const cl_R& y);
251 extern const cl_I truncate1 (const cl_R& x, const cl_R& y);
252
253 // round2(x,y) liefert (round x y), wo x und y reelle Zahlen sind.
254 extern const cl_R_div_t round2 (const cl_R& x, const cl_R& y);
255 extern const cl_I round1 (const cl_R& x, const cl_R& y);
256
257
258 // Return type for frounding operators.
259 // x / y  --> (q,r) with x = y*q+r.
260 struct cl_R_fdiv_t {
261         cl_F quotient;
262         cl_R remainder;
263 // Constructor.
264         cl_R_fdiv_t () {}
265         cl_R_fdiv_t (const cl_F& q, const cl_R& r) : quotient(q), remainder(r) {}
266         cl_R_fdiv_t (const struct cl_F_fdiv_t &);
267 };
268
269 // ffloor2(x) liefert (ffloor x), wo x eine reelle Zahl ist.
270 extern const cl_R_fdiv_t ffloor2 (const cl_R& x);
271 extern const cl_F ffloor (const cl_R& x);
272
273 // fceiling2(x) liefert (fceiling x), wo x eine reelle Zahl ist.
274 extern const cl_R_fdiv_t fceiling2 (const cl_R& x);
275 extern const cl_F fceiling (const cl_R& x);
276
277 // ftruncate2(x) liefert (ftruncate x), wo x eine reelle Zahl ist.
278 extern const cl_R_fdiv_t ftruncate2 (const cl_R& x);
279 extern const cl_F ftruncate (const cl_R& x);
280
281 // fround2(x) liefert (fround x), wo x eine reelle Zahl ist.
282 extern const cl_R_fdiv_t fround2 (const cl_R& x);
283 extern const cl_F fround (const cl_R& x);
284
285 // ffloor2(x,y) liefert (ffloor x y), wo x und y reelle Zahlen sind.
286 extern const cl_R_fdiv_t ffloor2 (const cl_R& x, const cl_R& y);
287 extern const cl_F ffloor (const cl_R& x, const cl_R& y);
288
289 // fceiling2(x,y) liefert (fceiling x y), wo x und y reelle Zahlen sind.
290 extern const cl_R_fdiv_t fceiling2 (const cl_R& x, const cl_R& y);
291 extern const cl_F fceiling (const cl_R& x, const cl_R& y);
292
293 // ftruncate2(x,y) liefert (ftruncate x y), wo x und y reelle Zahlen sind.
294 extern const cl_R_fdiv_t ftruncate2 (const cl_R& x, const cl_R& y);
295 extern const cl_F ftruncate (const cl_R& x, const cl_R& y);
296
297 // fround2(x,y) liefert (fround x y), wo x und y reelle Zahlen sind.
298 extern const cl_R_fdiv_t fround2 (const cl_R& x, const cl_R& y);
299 extern const cl_F fround (const cl_R& x, const cl_R& y);
300
301
302 // mod(x,y) = (mod x y), wo x und y reelle Zahlen sind.
303 extern const cl_R mod (const cl_R& x, const cl_R& y);
304
305 // rem(x,y) = (rem x y), wo x und y reelle Zahlen sind.
306 extern const cl_R rem (const cl_R& x, const cl_R& y);
307
308
309 // rational(x) liefert (rational x), wo x eine reelle Zahl ist.
310 extern const cl_RA rational (const cl_R& x);
311 // Spezialfall:
312 inline const cl_RA rational (const cl_RA& x) { return x; }
313
314
315 // equal(x,y) vergleicht zwei reelle Zahlen x und y auf Gleichheit.
316 extern cl_boolean equal (const cl_R& x, const cl_R& y);
317 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
318 extern uint32 equal_hashcode (const cl_R& x);
319
320 // compare(x,y) vergleicht zwei reelle Zahlen x und y.
321 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
322 extern cl_signean compare (const cl_R& x, const cl_R& y);
323
324 inline bool operator== (const cl_R& x, const cl_R& y)
325         { return equal(x,y); }
326 inline bool operator!= (const cl_R& x, const cl_R& y)
327         { return !equal(x,y); }
328 inline bool operator<= (const cl_R& x, const cl_R& y)
329         { return compare(x,y)<=0; }
330 inline bool operator< (const cl_R& x, const cl_R& y)
331         { return compare(x,y)<0; }
332 inline bool operator>= (const cl_R& x, const cl_R& y)
333         { return compare(x,y)>=0; }
334 inline bool operator> (const cl_R& x, const cl_R& y)
335         { return compare(x,y)>0; }
336
337 // max(x,y) liefert (max x y), wo x und y reelle Zahlen sind.
338 extern const cl_R max (const cl_R& x, const cl_R& y);
339
340 // min(x,y) liefert (min x y), wo x und y reelle Zahlen sind.
341 extern const cl_R min (const cl_R& x, const cl_R& y);
342
343 // signum(x) liefert (signum x), wo x eine reelle Zahl ist.
344 extern const cl_R signum (const cl_R& x);
345
346 // sqrt(x) = (sqrt x) zieht die Wurzel aus einer reellen Zahl x >=0.
347 extern const cl_R sqrt (const cl_R& x);
348 // sqrt(x) = (sqrt x) zieht die Wurzel aus einer rationalen Zahl x >=0.
349 extern const cl_R sqrt (const cl_RA& x);
350
351 // (expt x y), wo x eine reelle Zahl und y ein Integer ist.
352 extern const cl_R expt (const cl_R& x, sintL y);
353 extern const cl_R expt (const cl_R& x, const cl_I& y);
354
355 // rationalize(x) liefert (rationalize x), wo x eine reelle Zahl ist.
356 extern const cl_RA rationalize (const cl_R& x);
357
358
359 // Konversion zu einem C "float".
360 extern float float_approx (const cl_R& x);
361
362 // Konversion zu einem C "double".
363 extern double double_approx (const cl_R& x);
364
365
366 // Transcendental functions
367
368
369 // atan(x,y) liefert zu zwei reellen Zahlen x, y den Winkel von (x,y)
370 // in Polarkoordinaten. Ergebnis rational nur, wenn x>0 und y=0.
371 extern const cl_R atan (const cl_R& x, const cl_R& y);
372 // Spezialfall: y Float -> Ergebnis Float
373 inline const cl_F atan (const cl_R& x, const cl_F& y)
374         { return The(cl_F)(atan(x,The(cl_R)(y))); }
375 // Dem C++-Compiler muß man nun auch das Folgende sagen:
376 inline const cl_R atan (const cl_R& x, const int y)
377         { return atan(x,cl_I(y)); }
378 inline const cl_R atan (const cl_R& x, const unsigned int y)
379         { return atan(x,cl_I(y)); }
380 inline const cl_R atan (const cl_R& x, const long y)
381         { return atan(x,cl_I(y)); }
382 inline const cl_R atan (const cl_R& x, const unsigned long y)
383         { return atan(x,cl_I(y)); }
384
385 // atan(x) liefert den Arctan einer reellen Zahl x.
386 // Ergebnis rational nur, wenn x=0.
387 extern const cl_R atan (const cl_R& x);
388 // Spezialfall: x Float -> Ergebnis Float
389 inline const cl_F atan (const cl_F& x) { return The(cl_F)(atan(The(cl_R)(x))); }
390 // Dem C++-Compiler muß man nun auch das Folgende sagen:
391 inline const cl_R atan (const int x) { return atan(cl_I(x)); }
392 inline const cl_R atan (const unsigned int x) { return atan(cl_I(x)); }
393 inline const cl_R atan (const long x) { return atan(cl_I(x)); }
394 inline const cl_R atan (const unsigned long x) { return atan(cl_I(x)); }
395
396 // sin(x) liefert den Sinus (sin x) einer reellen Zahl x.
397 extern const cl_R sin (const cl_R& x);
398 // Dem C++-Compiler muß man nun auch das Folgende sagen:
399 inline const cl_R sin (const int x) { return sin(cl_I(x)); }
400 inline const cl_R sin (const unsigned int x) { return sin(cl_I(x)); }
401 inline const cl_R sin (const long x) { return sin(cl_I(x)); }
402 inline const cl_R sin (const unsigned long x) { return sin(cl_I(x)); }
403
404 // cos(x) liefert den Cosinus (cos x) einer reellen Zahl x.
405 extern const cl_R cos (const cl_R& x);
406 // Dem C++-Compiler muß man nun auch das Folgende sagen:
407 inline const cl_R cos (const int x) { return cos(cl_I(x)); }
408 inline const cl_R cos (const unsigned int x) { return cos(cl_I(x)); }
409 inline const cl_R cos (const long x) { return cos(cl_I(x)); }
410 inline const cl_R cos (const unsigned long x) { return cos(cl_I(x)); }
411
412 // cos_sin(x) liefert ((cos x),(sin x)), beide Werte.
413 extern const cos_sin_t cos_sin (const cl_R& x);
414
415 // tan(x) liefert den Tangens (tan x) einer reellen Zahl x.
416 extern const cl_R tan (const cl_R& x);
417 // Dem C++-Compiler muß man nun auch das Folgende sagen:
418 inline const cl_R tan (const int x) { return tan(cl_I(x)); }
419 inline const cl_R tan (const unsigned int x) { return tan(cl_I(x)); }
420 inline const cl_R tan (const long x) { return tan(cl_I(x)); }
421 inline const cl_R tan (const unsigned long x) { return tan(cl_I(x)); }
422
423 // ln(x) liefert zu einer reellen Zahl x>0 die Zahl ln(x).
424 extern const cl_R ln (const cl_R& x);
425 // Dem C++-Compiler muß man nun auch das Folgende sagen:
426 inline const cl_R ln (const int x) { return ln(cl_I(x)); }
427 inline const cl_R ln (const unsigned int x) { return ln(cl_I(x)); }
428 inline const cl_R ln (const long x) { return ln(cl_I(x)); }
429 inline const cl_R ln (const unsigned long x) { return ln(cl_I(x)); }
430
431 // log(a,b) liefert zu reellen Zahlen a>0, b>0 die Zahl
432 // log(a,b)=ln(a)/ln(b).
433 // Ergebnis rational nur, wenn a=1 oder a und b rational.
434 extern const cl_R log (const cl_R& a, const cl_R& b);
435
436 // exp(x) liefert zu einer reellen Zahl x die Zahl exp(x).
437 extern const cl_R exp (const cl_R& x);
438 // Dem C++-Compiler muß man nun auch das Folgende sagen:
439 inline const cl_R exp (const int x) { return exp(cl_I(x)); }
440 inline const cl_R exp (const unsigned int x) { return exp(cl_I(x)); }
441 inline const cl_R exp (const long x) { return exp(cl_I(x)); }
442 inline const cl_R exp (const unsigned long x) { return exp(cl_I(x)); }
443
444 // sinh(x) liefert zu einer reellen Zahl x die Zahl sinh(x).
445 extern const cl_R sinh (const cl_R& x);
446 // Dem C++-Compiler muß man nun auch das Folgende sagen:
447 inline const cl_R sinh (const int x) { return sinh(cl_I(x)); }
448 inline const cl_R sinh (const unsigned int x) { return sinh(cl_I(x)); }
449 inline const cl_R sinh (const long x) { return sinh(cl_I(x)); }
450 inline const cl_R sinh (const unsigned long x) { return sinh(cl_I(x)); }
451
452 // cosh(x) liefert zu einer reellen Zahl x die Zahl cosh(x).
453 extern const cl_R cosh (const cl_R& x);
454 // Dem C++-Compiler muß man nun auch das Folgende sagen:
455 inline const cl_R cosh (const int x) { return cosh(cl_I(x)); }
456 inline const cl_R cosh (const unsigned int x) { return cosh(cl_I(x)); }
457 inline const cl_R cosh (const long x) { return cosh(cl_I(x)); }
458 inline const cl_R cosh (const unsigned long x) { return cosh(cl_I(x)); }
459
460 // cosh_sinh(x) liefert ((cosh x),(sinh x)), beide Werte.
461 extern const cosh_sinh_t cosh_sinh (const cl_R& x);
462
463 // tanh(x) liefert zu einer reellen Zahl x die Zahl tanh(x).
464 extern const cl_R tanh (const cl_R& x);
465 // Dem C++-Compiler muß man nun auch das Folgende sagen:
466 inline const cl_R tanh (const int x) { return tanh(cl_I(x)); }
467 inline const cl_R tanh (const unsigned int x) { return tanh(cl_I(x)); }
468 inline const cl_R tanh (const long x) { return tanh(cl_I(x)); }
469 inline const cl_R tanh (const unsigned long x) { return tanh(cl_I(x)); }
470
471
472 // random_R(randomstate,n) liefert zu einer reellen Zahl n>0 eine Zufallszahl
473 // x mit 0 <= x < n.
474 extern const cl_R random_R (random_state& randomstate, const cl_R& n);
475
476 inline const cl_R random_R (const cl_R& n)
477         { return random_R(default_random_state,n); }
478
479
480 #ifdef WANT_OBFUSCATING_OPERATORS
481 // This could be optimized to use in-place operations.
482 inline cl_R& operator+= (cl_R& x, const cl_R& y) { return x = x + y; }
483 inline cl_F& operator+= (cl_F& x, const cl_R& y) { return x = x + y; }
484 inline cl_F& operator+= (cl_F& x, const cl_RA& y) { return x = x + y; }
485 inline cl_F& operator+= (cl_F& x, const cl_I& y) { return x = x + y; }
486 inline cl_R& operator+= (cl_R& x, const int y) { return x = x + y; }
487 inline cl_R& operator+= (cl_R& x, const unsigned int y) { return x = x + y; }
488 inline cl_R& operator+= (cl_R& x, const long y) { return x = x + y; }
489 inline cl_R& operator+= (cl_R& x, const unsigned long y) { return x = x + y; }
490 inline cl_F& operator+= (cl_R& x, const float y) { return static_cast<cl_F&>(x = x + y); }
491 inline cl_F& operator+= (cl_R& x, const double y) { return static_cast<cl_F&>(x = x + y); }
492 inline cl_F& operator+= (cl_F& x, const int y) { return x = x + y; }
493 inline cl_F& operator+= (cl_F& x, const unsigned int y) { return x = x + y; }
494 inline cl_F& operator+= (cl_F& x, const long y) { return x = x + y; }
495 inline cl_F& operator+= (cl_F& x, const unsigned long y) { return x = x + y; }
496 inline cl_R& operator++ /* prefix */ (cl_R& x) { return x = plus1(x); }
497 inline void operator++ /* postfix */ (cl_R& x, int dummy) { (void)dummy; x = plus1(x); }
498 inline cl_R& operator-= (cl_R& x, const cl_R& y) { return x = x - y; }
499 inline cl_F& operator-= (cl_F& x, const cl_R& y) { return x = x - y; }
500 inline cl_F& operator-= (cl_F& x, const cl_RA& y) { return x = x - y; }
501 inline cl_F& operator-= (cl_F& x, const cl_I& y) { return x = x - y; }
502 inline cl_R& operator-= (cl_R& x, const int y) { return x = x - y; }
503 inline cl_R& operator-= (cl_R& x, const unsigned int y) { return x = x - y; }
504 inline cl_R& operator-= (cl_R& x, const long y) { return x = x - y; }
505 inline cl_R& operator-= (cl_R& x, const unsigned long y) { return x = x - y; }
506 inline cl_F& operator-= (cl_R& x, const float y) { return static_cast<cl_F&>(x = x - y); }
507 inline cl_F& operator-= (cl_R& x, const double y) { return static_cast<cl_F&>(x = x - y); }
508 inline cl_F& operator-= (cl_F& x, const int y) { return x = x - y; }
509 inline cl_F& operator-= (cl_F& x, const unsigned int y) { return x = x - y; }
510 inline cl_F& operator-= (cl_F& x, const long y) { return x = x - y; }
511 inline cl_F& operator-= (cl_F& x, const unsigned long y) { return x = x - y; }
512 inline cl_R& operator-- /* prefix */ (cl_R& x) { return x = minus1(x); }
513 inline void operator-- /* postfix */ (cl_R& x, int dummy) { (void)dummy; x = minus1(x); }
514 inline cl_R& operator*= (cl_R& x, const cl_R& y) { return x = x * y; }
515 inline cl_R& operator*= (cl_R& x, const int y) { return x = x * y; }
516 inline cl_R& operator*= (cl_R& x, const unsigned int y) { return x = x * y; }
517 inline cl_R& operator*= (cl_R& x, const long y) { return x = x * y; }
518 inline cl_R& operator*= (cl_R& x, const unsigned long y) { return x = x * y; }
519 inline cl_R& operator*= (cl_R& x, const float y) { return x = x * y; }
520 inline cl_R& operator*= (cl_R& x, const double y) { return x = x * y; }
521 inline cl_R& operator/= (cl_R& x, const cl_R& y) { return x = x / y; }
522 inline cl_F& operator/= (cl_F& x, const cl_R& y) { return x = x / y; }
523 inline cl_F& operator/= (cl_F& x, const cl_RA& y) { return x = x / y; }
524 inline cl_F& operator/= (cl_F& x, const cl_I& y) { return x = x / y; }
525 inline cl_R& operator/= (cl_R& x, const int y) { return x = x / y; }
526 inline cl_R& operator/= (cl_R& x, const unsigned int y) { return x = x / y; }
527 inline cl_R& operator/= (cl_R& x, const long y) { return x = x / y; }
528 inline cl_R& operator/= (cl_R& x, const unsigned long y) { return x = x / y; }
529 inline cl_R& operator/= (cl_R& x, const float y) { return x = x / y; }
530 inline cl_R& operator/= (cl_R& x, const double y) { return x = x / y; }
531 inline cl_F& operator/= (cl_F& x, const int y) { return x = x / y; }
532 inline cl_F& operator/= (cl_F& x, const unsigned int y) { return x = x / y; }
533 inline cl_F& operator/= (cl_F& x, const long y) { return x = x / y; }
534 inline cl_F& operator/= (cl_F& x, const unsigned long y) { return x = x / y; }
535 #endif
536
537
538 // Complex operations, trivial for reals
539
540 inline const cl_R realpart (const cl_R& x)
541 {
542         return x;
543 }
544 inline const cl_R imagpart (const cl_R& x)
545 {
546         (void)x; // unused x
547         return 0;
548 }
549 inline const cl_R conjugate (const cl_R& x)
550 {
551         return x;
552 }
553
554
555 // Debugging support.
556 #ifdef CL_DEBUG
557 extern int cl_R_debug_module;
558 CL_FORCE_LINK(cl_R_debug_dummy, cl_R_debug_module)
559 #endif
560
561 }  // namespace cln
562
563 #endif /* _CL_REAL_H */