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