]> www.ginac.de Git - cln.git/blob - include/cln/real.h
Finalize CLN 1.3.7 release.
[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 bool zerop (const cl_R& x);
21
22 // minusp(x) testet, ob (< x 0).
23 extern bool minusp (const cl_R& x);
24
25 // plusp(x) testet, ob (> x 0).
26 extern bool 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_R operator+ (const long long x, const cl_R& y)
88         { return cl_I(x) + y; }
89 inline const cl_R operator+ (const unsigned long long x, const cl_R& y)
90         { return cl_I(x) + y; }
91 inline const cl_F operator+ (const float x, const cl_R& y)
92         { return The(cl_F)(cl_R(x) + y); }
93 inline const cl_F operator+ (const double x, const cl_R& y)
94         { return The(cl_F)(cl_R(x) + y); }
95 inline const cl_R operator+ (const cl_R& x, const int y)
96         { return x + cl_I(y); }
97 inline const cl_R operator+ (const cl_R& x, const unsigned int y)
98         { return x + cl_I(y); }
99 inline const cl_R operator+ (const cl_R& x, const long y)
100         { return x + cl_I(y); }
101 inline const cl_R operator+ (const cl_R& x, const unsigned long y)
102         { return x + cl_I(y); }
103 inline const cl_R operator+ (const cl_R& x, const long long y)
104         { return x + cl_I(y); }
105 inline const cl_R operator+ (const cl_R& x, const unsigned long long y)
106         { return x + cl_I(y); }
107 inline const cl_F operator+ (const cl_R& x, const float y)
108         { return The(cl_F)(x + cl_R(y)); }
109 inline const cl_F operator+ (const cl_R& x, const double y)
110         { return The(cl_F)(x + cl_R(y)); }
111
112 // Liefert (- x y), wo x und y reelle Zahlen sind.
113 extern const cl_R operator- (const cl_R& x, const cl_R& y);
114 // Spezialfall: x oder y Float -> Ergebnis Float
115 inline const cl_F operator- (const cl_R& x, const cl_F& y)
116         { return The(cl_F)(x - The(cl_R)(y)); }
117 inline const cl_F operator- (const cl_F& x, const cl_R& y)
118         { return The(cl_F)(The(cl_R)(x) - y); }
119 // Dem C++-Compiler muß man nun auch das Folgende sagen:
120 inline const cl_R operator- (const int x, const cl_R& y)
121         { return cl_I(x) - y; }
122 inline const cl_R operator- (const unsigned int x, const cl_R& y)
123         { return cl_I(x) - y; }
124 inline const cl_R operator- (const long x, const cl_R& y)
125         { return cl_I(x) - y; }
126 inline const cl_R operator- (const unsigned long x, const cl_R& y)
127         { return cl_I(x) - y; }
128 inline const cl_R operator- (const long long x, const cl_R& y)
129         { return cl_I(x) - y; }
130 inline const cl_R operator- (const unsigned long long x, const cl_R& y)
131         { return cl_I(x) - y; }
132 inline const cl_F operator- (const float x, const cl_R& y)
133         { return The(cl_F)(cl_R(x) - y); }
134 inline const cl_F operator- (const double x, const cl_R& y)
135         { return The(cl_F)(cl_R(x) - y); }
136 inline const cl_R operator- (const cl_R& x, const int y)
137         { return x - cl_I(y); }
138 inline const cl_R operator- (const cl_R& x, const unsigned int y)
139         { return x - cl_I(y); }
140 inline const cl_R operator- (const cl_R& x, const long y)
141         { return x - cl_I(y); }
142 inline const cl_R operator- (const cl_R& x, const unsigned long y)
143         { return x - cl_I(y); }
144 inline const cl_R operator- (const cl_R& x, const long long y)
145         { return x - cl_I(y); }
146 inline const cl_R operator- (const cl_R& x, const unsigned long long y)
147         { return x - cl_I(y); }
148 inline const cl_F operator- (const cl_R& x, const float y)
149         { return The(cl_F)(x - cl_R(y)); }
150 inline const cl_F operator- (const cl_R& x, const double y)
151         { return The(cl_F)(x - cl_R(y)); }
152
153 // Liefert (* x y), wo x und y reelle Zahlen sind.
154 extern const cl_R operator* (const cl_R& x, const cl_R& y);
155 // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int * cl_F' u.ä.):
156 inline const cl_R operator* (const int x, const cl_R& y)
157         { return cl_I(x) * y; }
158 inline const cl_R operator* (const unsigned int x, const cl_R& y)
159         { return cl_I(x) * y; }
160 inline const cl_R operator* (const long x, const cl_R& y)
161         { return cl_I(x) * y; }
162 inline const cl_R operator* (const unsigned long x, const cl_R& y)
163         { return cl_I(x) * y; }
164 inline const cl_R operator* (const long long x, const cl_R& y)
165         { return cl_I(x) * y; }
166 inline const cl_R operator* (const unsigned long long x, const cl_R& y)
167         { return cl_I(x) * y; }
168 inline const cl_R operator* (const float x, const cl_R& y)
169         { return cl_R(x) * y; }
170 inline const cl_R operator* (const double x, const cl_R& y)
171         { return cl_R(x) * y; }
172 inline const cl_R operator* (const cl_R& x, const int y)
173         { return x * cl_I(y); }
174 inline const cl_R operator* (const cl_R& x, const unsigned int y)
175         { return x * cl_I(y); }
176 inline const cl_R operator* (const cl_R& x, const long y)
177         { return x * cl_I(y); }
178 inline const cl_R operator* (const cl_R& x, const unsigned long y)
179         { return x * cl_I(y); }
180 inline const cl_R operator* (const cl_R& x, const long long y)
181         { return x * cl_I(y); }
182 inline const cl_R operator* (const cl_R& x, const unsigned long long y)
183         { return x * cl_I(y); }
184 inline const cl_R operator* (const cl_R& x, const float y)
185         { return x * cl_R(y); }
186 inline const cl_R operator* (const cl_R& x, const double y)
187         { return x * cl_R(y); }
188
189 // Liefert (* x x), wo x eine reelle Zahl ist.
190 extern const cl_R square (const cl_R& x);
191
192 // Liefert (/ x y), wo x und y reelle Zahlen sind.
193 extern const cl_R operator/ (const cl_R& x, const cl_R& y);
194 // Spezialfall: x Float -> Ergebnis Float
195 inline const cl_F operator/ (const cl_F& x, const cl_R& y)
196         { return The(cl_F)(The(cl_R)(x) / y); }
197 // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int / cl_F' u.ä.):
198 inline const cl_R operator/ (const int x, const cl_R& y)
199         { return cl_I(x) / y; }
200 inline const cl_R operator/ (const unsigned int x, const cl_R& y)
201         { return cl_I(x) / y; }
202 inline const cl_R operator/ (const long x, const cl_R& y)
203         { return cl_I(x) / y; }
204 inline const cl_R operator/ (const unsigned long x, const cl_R& y)
205         { return cl_I(x) / y; }
206 inline const cl_R operator/ (const long long x, const cl_R& y)
207         { return cl_I(x) / y; }
208 inline const cl_R operator/ (const unsigned long long x, const cl_R& y)
209         { return cl_I(x) / y; }
210 inline const cl_F operator/ (const float x, const cl_R& y)
211         { return The(cl_F)(cl_R(x) / y); }
212 inline const cl_F operator/ (const double x, const cl_R& y)
213         { return The(cl_F)(cl_R(x) / y); }
214 inline const cl_R operator/ (const cl_R& x, const int y)
215         { return x / cl_I(y); }
216 inline const cl_R operator/ (const cl_R& x, const unsigned int y)
217         { return x / cl_I(y); }
218 inline const cl_R operator/ (const cl_R& x, const long y)
219         { return x / cl_I(y); }
220 inline const cl_R operator/ (const cl_R& x, const unsigned long y)
221         { return x / cl_I(y); }
222 inline const cl_R operator/ (const cl_R& x, const long long y)
223         { return x / cl_I(y); }
224 inline const cl_R operator/ (const cl_R& x, const unsigned long long y)
225         { return x / cl_I(y); }
226 inline const cl_R operator/ (const cl_R& x, const float y)
227         { return x / cl_R(y); }
228 inline const cl_R operator/ (const cl_R& x, const double y)
229         { return x / cl_R(y); }
230
231 // Liefert (abs x), wo x eine reelle Zahl ist.
232 extern const cl_R abs (const cl_R& x);
233
234 // recip(x) liefert (/ x), wo x eine reelle Zahl ist.
235 extern const cl_R recip (const cl_R& x);
236
237 // (1+ x), wo x eine reelle Zahl ist.
238 extern const cl_R plus1 (const cl_R& x);
239
240 // (1- x), wo x eine reelle Zahl ist.
241 extern const cl_R minus1 (const cl_R& x);
242
243
244 // Return type for rounding operators.
245 // x / y  --> (q,r) with x = y*q+r.
246 struct cl_R_div_t {
247         cl_I quotient;
248         cl_R remainder;
249 // Constructor.
250         cl_R_div_t () {}
251         cl_R_div_t (const cl_I& q, const cl_R& r) : quotient(q), remainder(r) {}
252         cl_R_div_t (const struct cl_I_div_t &);
253         cl_R_div_t (const struct cl_RA_div_t &);
254         cl_R_div_t (const struct cl_F_div_t &);
255 };
256
257 // floor2(x) liefert (floor x), wo x eine reelle Zahl ist.
258 extern const cl_R_div_t floor2 (const cl_R& x);
259 extern const cl_I floor1 (const cl_R& x);
260
261 // ceiling2(x) liefert (ceiling x), wo x eine reelle Zahl ist.
262 extern const cl_R_div_t ceiling2 (const cl_R& x);
263 extern const cl_I ceiling1 (const cl_R& x);
264
265 // truncate2(x) liefert (truncate x), wo x eine reelle Zahl ist.
266 extern const cl_R_div_t truncate2 (const cl_R& x);
267 extern const cl_I truncate1 (const cl_R& x);
268
269 // round2(x) liefert (round x), wo x eine reelle Zahl ist.
270 extern const cl_R_div_t round2 (const cl_R& x);
271 extern const cl_I round1 (const cl_R& x);
272
273 // floor2(x,y) liefert (floor x y), wo x und y reelle Zahlen sind.
274 extern const cl_R_div_t floor2 (const cl_R& x, const cl_R& y);
275 extern const cl_I floor1 (const cl_R& x, const cl_R& y);
276
277 // ceiling2(x,y) liefert (ceiling x y), wo x und y reelle Zahlen sind.
278 extern const cl_R_div_t ceiling2 (const cl_R& x, const cl_R& y);
279 extern const cl_I ceiling1 (const cl_R& x, const cl_R& y);
280
281 // truncate2(x,y) liefert (truncate x y), wo x und y reelle Zahlen sind.
282 extern const cl_R_div_t truncate2 (const cl_R& x, const cl_R& y);
283 extern const cl_I truncate1 (const cl_R& x, const cl_R& y);
284
285 // round2(x,y) liefert (round x y), wo x und y reelle Zahlen sind.
286 extern const cl_R_div_t round2 (const cl_R& x, const cl_R& y);
287 extern const cl_I round1 (const cl_R& x, const cl_R& y);
288
289
290 // Return type for frounding operators.
291 // x / y  --> (q,r) with x = y*q+r.
292 struct cl_R_fdiv_t {
293         cl_F quotient;
294         cl_R remainder;
295 // Constructor.
296         cl_R_fdiv_t () {}
297         cl_R_fdiv_t (const cl_F& q, const cl_R& r) : quotient(q), remainder(r) {}
298         cl_R_fdiv_t (const struct cl_F_fdiv_t &);
299 };
300
301 // ffloor2(x) liefert (ffloor x), wo x eine reelle Zahl ist.
302 extern const cl_R_fdiv_t ffloor2 (const cl_R& x);
303 extern const cl_F ffloor (const cl_R& x);
304
305 // fceiling2(x) liefert (fceiling x), wo x eine reelle Zahl ist.
306 extern const cl_R_fdiv_t fceiling2 (const cl_R& x);
307 extern const cl_F fceiling (const cl_R& x);
308
309 // ftruncate2(x) liefert (ftruncate x), wo x eine reelle Zahl ist.
310 extern const cl_R_fdiv_t ftruncate2 (const cl_R& x);
311 extern const cl_F ftruncate (const cl_R& x);
312
313 // fround2(x) liefert (fround x), wo x eine reelle Zahl ist.
314 extern const cl_R_fdiv_t fround2 (const cl_R& x);
315 extern const cl_F fround (const cl_R& x);
316
317 // ffloor2(x,y) liefert (ffloor x y), wo x und y reelle Zahlen sind.
318 extern const cl_R_fdiv_t ffloor2 (const cl_R& x, const cl_R& y);
319 extern const cl_F ffloor (const cl_R& x, const cl_R& y);
320
321 // fceiling2(x,y) liefert (fceiling x y), wo x und y reelle Zahlen sind.
322 extern const cl_R_fdiv_t fceiling2 (const cl_R& x, const cl_R& y);
323 extern const cl_F fceiling (const cl_R& x, const cl_R& y);
324
325 // ftruncate2(x,y) liefert (ftruncate x y), wo x und y reelle Zahlen sind.
326 extern const cl_R_fdiv_t ftruncate2 (const cl_R& x, const cl_R& y);
327 extern const cl_F ftruncate (const cl_R& x, const cl_R& y);
328
329 // fround2(x,y) liefert (fround x y), wo x und y reelle Zahlen sind.
330 extern const cl_R_fdiv_t fround2 (const cl_R& x, const cl_R& y);
331 extern const cl_F fround (const cl_R& x, const cl_R& y);
332
333
334 // mod(x,y) = (mod x y), wo x und y reelle Zahlen sind.
335 extern const cl_R mod (const cl_R& x, const cl_R& y);
336
337 // rem(x,y) = (rem x y), wo x und y reelle Zahlen sind.
338 extern const cl_R rem (const cl_R& x, const cl_R& y);
339
340
341 // rational(x) liefert (rational x), wo x eine reelle Zahl ist.
342 extern const cl_RA rational (const cl_R& x);
343 // Spezialfall:
344 inline const cl_RA rational (const cl_RA& x) { return x; }
345
346
347 // equal(x,y) vergleicht zwei reelle Zahlen x und y auf Gleichheit.
348 extern bool equal (const cl_R& x, const cl_R& y);
349 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
350 extern uint32 equal_hashcode (const cl_R& x);
351
352 // compare(x,y) vergleicht zwei reelle Zahlen x und y.
353 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
354 extern cl_signean compare (const cl_R& x, const cl_R& y);
355
356 inline bool operator== (const cl_R& x, const cl_R& y)
357         { return equal(x,y); }
358 inline bool operator!= (const cl_R& x, const cl_R& y)
359         { return !equal(x,y); }
360 inline bool operator<= (const cl_R& x, const cl_R& y)
361         { return compare(x,y)<=0; }
362 inline bool operator< (const cl_R& x, const cl_R& y)
363         { return compare(x,y)<0; }
364 inline bool operator>= (const cl_R& x, const cl_R& y)
365         { return compare(x,y)>=0; }
366 inline bool operator> (const cl_R& x, const cl_R& y)
367         { return compare(x,y)>0; }
368
369 // max(x,y) liefert (max x y), wo x und y reelle Zahlen sind.
370 extern const cl_R max (const cl_R& x, const cl_R& y);
371
372 // min(x,y) liefert (min x y), wo x und y reelle Zahlen sind.
373 extern const cl_R min (const cl_R& x, const cl_R& y);
374
375 // signum(x) liefert (signum x), wo x eine reelle Zahl ist.
376 extern const cl_R signum (const cl_R& x);
377
378 // sqrt(x) = (sqrt x) zieht die Wurzel aus einer reellen Zahl x >=0.
379 extern const cl_R sqrt (const cl_R& x);
380 // sqrt(x) = (sqrt x) zieht die Wurzel aus einer rationalen Zahl x >=0.
381 extern const cl_R sqrt (const cl_RA& x);
382
383 // (expt x y), wo x eine reelle Zahl und y ein Integer ist.
384 extern const cl_R expt (const cl_R& x, sintL y);
385 extern const cl_R expt (const cl_R& x, const cl_I& y);
386
387 // rationalize(x) liefert (rationalize x), wo x eine reelle Zahl ist.
388 extern const cl_RA rationalize (const cl_R& x);
389
390
391 // Konversion zu einem C "float".
392 extern float float_approx (const cl_R& x);
393
394 // Konversion zu einem C "double".
395 extern double double_approx (const cl_R& x);
396
397
398 // Transcendental functions
399
400
401 // atan(x,y) liefert zu zwei reellen Zahlen x, y den Winkel von (x,y)
402 // in Polarkoordinaten. Ergebnis rational nur, wenn x>0 und y=0.
403 extern const cl_R atan (const cl_R& x, const cl_R& y);
404 // Spezialfall: y Float -> Ergebnis Float
405 inline const cl_F atan (const cl_R& x, const cl_F& y)
406         { return The(cl_F)(atan(x,The(cl_R)(y))); }
407 // Dem C++-Compiler muß man nun auch das Folgende sagen:
408 inline const cl_R atan (const cl_R& x, const int y)
409         { return atan(x,cl_I(y)); }
410 inline const cl_R atan (const cl_R& x, const unsigned int y)
411         { return atan(x,cl_I(y)); }
412 inline const cl_R atan (const cl_R& x, const long y)
413         { return atan(x,cl_I(y)); }
414 inline const cl_R atan (const cl_R& x, const unsigned long y)
415         { return atan(x,cl_I(y)); }
416
417 // atan(x) liefert den Arctan einer reellen Zahl x.
418 // Ergebnis rational nur, wenn x=0.
419 extern const cl_R atan (const cl_R& x);
420 // Spezialfall: x Float -> Ergebnis Float
421 inline const cl_F atan (const cl_F& x) { return The(cl_F)(atan(The(cl_R)(x))); }
422 // Dem C++-Compiler muß man nun auch das Folgende sagen:
423 inline const cl_R atan (const int x) { return atan(cl_I(x)); }
424 inline const cl_R atan (const unsigned int x) { return atan(cl_I(x)); }
425 inline const cl_R atan (const long x) { return atan(cl_I(x)); }
426 inline const cl_R atan (const unsigned long x) { return atan(cl_I(x)); }
427
428 // sin(x) liefert den Sinus (sin x) einer reellen Zahl x.
429 extern const cl_R sin (const cl_R& x);
430 // Dem C++-Compiler muß man nun auch das Folgende sagen:
431 inline const cl_R sin (const int x) { return sin(cl_I(x)); }
432 inline const cl_R sin (const unsigned int x) { return sin(cl_I(x)); }
433 inline const cl_R sin (const long x) { return sin(cl_I(x)); }
434 inline const cl_R sin (const unsigned long x) { return sin(cl_I(x)); }
435
436 // cos(x) liefert den Cosinus (cos x) einer reellen Zahl x.
437 extern const cl_R cos (const cl_R& x);
438 // Dem C++-Compiler muß man nun auch das Folgende sagen:
439 inline const cl_R cos (const int x) { return cos(cl_I(x)); }
440 inline const cl_R cos (const unsigned int x) { return cos(cl_I(x)); }
441 inline const cl_R cos (const long x) { return cos(cl_I(x)); }
442 inline const cl_R cos (const unsigned long x) { return cos(cl_I(x)); }
443
444 // cos_sin(x) liefert ((cos x),(sin x)), beide Werte.
445 extern const cos_sin_t cos_sin (const cl_R& x);
446
447 // tan(x) liefert den Tangens (tan x) einer reellen Zahl x.
448 extern const cl_R tan (const cl_R& x);
449 // Dem C++-Compiler muß man nun auch das Folgende sagen:
450 inline const cl_R tan (const int x) { return tan(cl_I(x)); }
451 inline const cl_R tan (const unsigned int x) { return tan(cl_I(x)); }
452 inline const cl_R tan (const long x) { return tan(cl_I(x)); }
453 inline const cl_R tan (const unsigned long x) { return tan(cl_I(x)); }
454
455 // ln(x) liefert zu einer reellen Zahl x>0 die Zahl ln(x).
456 extern const cl_R ln (const cl_R& x);
457 // Dem C++-Compiler muß man nun auch das Folgende sagen:
458 inline const cl_R ln (const int x) { return ln(cl_I(x)); }
459 inline const cl_R ln (const unsigned int x) { return ln(cl_I(x)); }
460 inline const cl_R ln (const long x) { return ln(cl_I(x)); }
461 inline const cl_R ln (const unsigned long x) { return ln(cl_I(x)); }
462
463 // log(a,b) liefert zu reellen Zahlen a>0, b>0 die Zahl
464 // log(a,b)=ln(a)/ln(b).
465 // Ergebnis rational nur, wenn a=1 oder a und b rational.
466 extern const cl_R log (const cl_R& a, const cl_R& b);
467
468 // exp(x) liefert zu einer reellen Zahl x die Zahl exp(x).
469 extern const cl_R exp (const cl_R& x);
470 // Dem C++-Compiler muß man nun auch das Folgende sagen:
471 inline const cl_R exp (const int x) { return exp(cl_I(x)); }
472 inline const cl_R exp (const unsigned int x) { return exp(cl_I(x)); }
473 inline const cl_R exp (const long x) { return exp(cl_I(x)); }
474 inline const cl_R exp (const unsigned long x) { return exp(cl_I(x)); }
475
476 // sinh(x) liefert zu einer reellen Zahl x die Zahl sinh(x).
477 extern const cl_R sinh (const cl_R& x);
478 // Dem C++-Compiler muß man nun auch das Folgende sagen:
479 inline const cl_R sinh (const int x) { return sinh(cl_I(x)); }
480 inline const cl_R sinh (const unsigned int x) { return sinh(cl_I(x)); }
481 inline const cl_R sinh (const long x) { return sinh(cl_I(x)); }
482 inline const cl_R sinh (const unsigned long x) { return sinh(cl_I(x)); }
483
484 // cosh(x) liefert zu einer reellen Zahl x die Zahl cosh(x).
485 extern const cl_R cosh (const cl_R& x);
486 // Dem C++-Compiler muß man nun auch das Folgende sagen:
487 inline const cl_R cosh (const int x) { return cosh(cl_I(x)); }
488 inline const cl_R cosh (const unsigned int x) { return cosh(cl_I(x)); }
489 inline const cl_R cosh (const long x) { return cosh(cl_I(x)); }
490 inline const cl_R cosh (const unsigned long x) { return cosh(cl_I(x)); }
491
492 // cosh_sinh(x) liefert ((cosh x),(sinh x)), beide Werte.
493 extern const cosh_sinh_t cosh_sinh (const cl_R& x);
494
495 // tanh(x) liefert zu einer reellen Zahl x die Zahl tanh(x).
496 extern const cl_R tanh (const cl_R& x);
497 // Dem C++-Compiler muß man nun auch das Folgende sagen:
498 inline const cl_R tanh (const int x) { return tanh(cl_I(x)); }
499 inline const cl_R tanh (const unsigned int x) { return tanh(cl_I(x)); }
500 inline const cl_R tanh (const long x) { return tanh(cl_I(x)); }
501 inline const cl_R tanh (const unsigned long x) { return tanh(cl_I(x)); }
502
503
504 // random_R(randomstate,n) liefert zu einer reellen Zahl n>0 eine Zufallszahl
505 // x mit 0 <= x < n.
506 extern const cl_R random_R (random_state& randomstate, const cl_R& n);
507
508 inline const cl_R random_R (const cl_R& n)
509         { return random_R(default_random_state,n); }
510
511
512 // This could be optimized to use in-place operations.
513 inline cl_R& operator+= (cl_R& x, const cl_R& y) { return x = x + y; }
514 inline cl_F& operator+= (cl_F& x, const cl_R& y) { return x = x + y; }
515 inline cl_F& operator+= (cl_F& x, const cl_RA& y) { return x = x + y; }
516 inline cl_F& operator+= (cl_F& x, const cl_I& y) { return x = x + y; }
517 inline cl_R& operator+= (cl_R& x, const int y) { return x = x + y; }
518 inline cl_R& operator+= (cl_R& x, const unsigned int y) { return x = x + y; }
519 inline cl_R& operator+= (cl_R& x, const long y) { return x = x + y; }
520 inline cl_R& operator+= (cl_R& x, const unsigned long y) { return x = x + y; }
521 inline cl_R& operator+= (cl_R& x, const long long y) { return x = x + y; }
522 inline cl_R& operator+= (cl_R& x, const unsigned long long y) { return x = x + y; }
523 inline cl_F& operator+= (cl_R& x, const float y) { return static_cast<cl_F&>(x = x + y); }
524 inline cl_F& operator+= (cl_R& x, const double y) { return static_cast<cl_F&>(x = x + y); }
525 inline cl_F& operator+= (cl_F& x, const int y) { return x = x + y; }
526 inline cl_F& operator+= (cl_F& x, const unsigned int y) { return x = x + y; }
527 inline cl_F& operator+= (cl_F& x, const long y) { return x = x + y; }
528 inline cl_F& operator+= (cl_F& x, const unsigned long y) { return x = x + y; }
529 inline cl_F& operator+= (cl_F& x, const long long y) { return x = x + y; }
530 inline cl_F& operator+= (cl_F& x, const unsigned long long y) { return x = x + y; }
531 inline cl_R& operator++ /* prefix */ (cl_R& x) { return x = plus1(x); }
532 inline void operator++ /* postfix */ (cl_R& x, int dummy) { (void)dummy; x = plus1(x); }
533 inline cl_R& operator-= (cl_R& x, const cl_R& y) { return x = x - y; }
534 inline cl_F& operator-= (cl_F& x, const cl_R& y) { return x = x - y; }
535 inline cl_F& operator-= (cl_F& x, const cl_RA& y) { return x = x - y; }
536 inline cl_F& operator-= (cl_F& x, const cl_I& y) { return x = x - y; }
537 inline cl_R& operator-= (cl_R& x, const int y) { return x = x - y; }
538 inline cl_R& operator-= (cl_R& x, const unsigned int y) { return x = x - y; }
539 inline cl_R& operator-= (cl_R& x, const long y) { return x = x - y; }
540 inline cl_R& operator-= (cl_R& x, const unsigned long y) { return x = x - y; }
541 inline cl_R& operator-= (cl_R& x, const long long y) { return x = x - y; }
542 inline cl_R& operator-= (cl_R& x, const unsigned long long y) { return x = x - y; }
543 inline cl_F& operator-= (cl_R& x, const float y) { return static_cast<cl_F&>(x = x - y); }
544 inline cl_F& operator-= (cl_R& x, const double y) { return static_cast<cl_F&>(x = x - y); }
545 inline cl_F& operator-= (cl_F& x, const int y) { return x = x - y; }
546 inline cl_F& operator-= (cl_F& x, const unsigned int y) { return x = x - y; }
547 inline cl_F& operator-= (cl_F& x, const long y) { return x = x - y; }
548 inline cl_F& operator-= (cl_F& x, const unsigned long y) { return x = x - y; }
549 inline cl_F& operator-= (cl_F& x, const long long y) { return x = x - y; }
550 inline cl_F& operator-= (cl_F& x, const unsigned long long y) { return x = x - y; }
551 inline cl_R& operator-- /* prefix */ (cl_R& x) { return x = minus1(x); }
552 inline void operator-- /* postfix */ (cl_R& x, int dummy) { (void)dummy; x = minus1(x); }
553 inline cl_R& operator*= (cl_R& x, const cl_R& y) { return x = x * y; }
554 inline cl_R& operator*= (cl_R& x, const int y) { return x = x * y; }
555 inline cl_R& operator*= (cl_R& x, const unsigned int y) { return x = x * y; }
556 inline cl_R& operator*= (cl_R& x, const long y) { return x = x * y; }
557 inline cl_R& operator*= (cl_R& x, const unsigned long y) { return x = x * y; }
558 inline cl_R& operator*= (cl_R& x, const long long y) { return x = x * y; }
559 inline cl_R& operator*= (cl_R& x, const unsigned long long y) { return x = x * y; }
560 inline cl_R& operator*= (cl_R& x, const float y) { return x = x * y; }
561 inline cl_R& operator*= (cl_R& x, const double y) { return x = x * y; }
562 inline cl_R& operator/= (cl_R& x, const cl_R& y) { return x = x / y; }
563 inline cl_F& operator/= (cl_F& x, const cl_R& y) { return x = x / y; }
564 inline cl_F& operator/= (cl_F& x, const cl_RA& y) { return x = x / y; }
565 inline cl_F& operator/= (cl_F& x, const cl_I& y) { return x = x / y; }
566 inline cl_R& operator/= (cl_R& x, const int y) { return x = x / y; }
567 inline cl_R& operator/= (cl_R& x, const unsigned int y) { return x = x / y; }
568 inline cl_R& operator/= (cl_R& x, const long y) { return x = x / y; }
569 inline cl_R& operator/= (cl_R& x, const unsigned long y) { return x = x / y; }
570 inline cl_R& operator/= (cl_R& x, const long long y) { return x = x / y; }
571 inline cl_R& operator/= (cl_R& x, const unsigned long long y) { return x = x / y; }
572 inline cl_R& operator/= (cl_R& x, const float y) { return x = x / y; }
573 inline cl_R& operator/= (cl_R& x, const double y) { return x = x / y; }
574 inline cl_F& operator/= (cl_F& x, const int y) { return x = x / y; }
575 inline cl_F& operator/= (cl_F& x, const unsigned int y) { return x = x / y; }
576 inline cl_F& operator/= (cl_F& x, const long y) { return x = x / y; }
577 inline cl_F& operator/= (cl_F& x, const unsigned long y) { return x = x / y; }
578 inline cl_F& operator/= (cl_F& x, const long long y) { return x = x / y; }
579 inline cl_F& operator/= (cl_F& x, const unsigned long long y) { return x = x / y; }
580
581
582 // Complex operations, trivial for reals
583
584 inline const cl_R realpart (const cl_R& x)
585 {
586         return x;
587 }
588 inline const cl_R imagpart (const cl_R& x)
589 {
590         (void)x; // unused x
591         return 0;
592 }
593 inline const cl_R conjugate (const cl_R& x)
594 {
595         return x;
596 }
597
598
599 // Debugging support.
600 #ifdef CL_DEBUG
601 extern int cl_R_debug_module;
602 CL_FORCE_LINK(cl_R_debug_dummy, cl_R_debug_module)
603 #endif
604
605 }  // namespace cln
606
607 #endif /* _CL_REAL_H */