]> www.ginac.de Git - cln.git/blob - include/cln/float.h
Ensure that makeinfo ≥ 6.8 checks the @menu structure.
[cln.git] / include / cln / float.h
1 // Public float operations.
2
3 #ifndef _CL_FLOAT_H
4 #define _CL_FLOAT_H
5
6 #include "cln/number.h"
7 #include "cln/float_class.h"
8 #include "cln/floatformat.h"
9 #include "cln/random.h"
10 #include "cln/integer_class.h"
11 #include "cln/sfloat_class.h"
12 #include "cln/ffloat_class.h"
13 #include "cln/dfloat_class.h"
14 #include "cln/lfloat_class.h"
15 #include "cln/exception.h"
16
17 namespace cln {
18
19 CL_DEFINE_AS_CONVERSION(cl_F)
20
21
22 // Return type for integer_decode_float:
23 struct cl_idecoded_float {
24         cl_I mantissa;
25         cl_I exponent;
26         cl_I sign;
27 // Constructor.
28         cl_idecoded_float () {}
29         cl_idecoded_float (const cl_I& m, const cl_I& e, const cl_I& s) : mantissa(m), exponent(e), sign(s) {}
30 };
31
32
33 // zerop(x) testet, ob (= x 0).
34 extern bool zerop (const cl_F& x);
35
36 // minusp(x) testet, ob (< x 0).
37 extern bool minusp (const cl_F& x);
38
39 // plusp(x) testet, ob (> x 0).
40 extern bool plusp (const cl_F& x);
41
42
43 // cl_F_to_SF(x) wandelt ein Float x in ein Short-Float um und rundet dabei.
44 extern const cl_SF cl_F_to_SF (const cl_F& x);
45
46 // cl_F_to_FF(x) wandelt ein Float x in ein Single-Float um und rundet dabei.
47 extern const cl_FF cl_F_to_FF (const cl_F& x);
48
49 // cl_F_to_DF(x) wandelt ein Float x in ein Double-Float um und rundet dabei.
50 extern const cl_DF cl_F_to_DF (const cl_F& x);
51
52 // cl_F_to_LF(x,len) wandelt ein Float x in ein Long-Float mit len Digits um
53 // und rundet dabei.
54 // > uintC len: gewünschte Anzahl Digits, >=LF_minlen
55 extern const cl_LF cl_F_to_LF (const cl_F& x, uintC len);
56
57
58 // The default float format used when converting rational numbers to floats.
59 extern float_format_t default_float_format;
60
61 // Returns the smallest float format which guarantees at least n decimal digits
62 // in the mantissa (after the decimal point).
63 extern float_format_t float_format (uintE n);
64
65 // cl_float(x,y) wandelt ein Float x in das Float-Format des Floats y um
66 // und rundet dabei nötigenfalls.
67 // > x,y: Floats
68 // < ergebnis: (float x y)
69 extern const cl_F cl_float (const cl_F& x, const cl_F& y);
70
71 // cl_float(x,f) wandelt ein Float x in das Float-Format f um
72 // und rundet dabei nötigenfalls.
73 // > x: ein Float
74 // > f: eine Float-Format-Spezifikation
75 // < ergebnis: (float x f)
76 extern const cl_F cl_float (const cl_F& x, float_format_t f);
77
78 // cl_float(x) wandelt eine reelle Zahl x in ein Float um
79 // und rundet dabei nötigenfalls.
80 // > x: eine reelle Zahl
81 // < ergebnis: (float x)
82 // Abhängig von default_float_format.
83 inline const cl_F cl_float (const cl_F& x) { return x; }
84
85 // cl_float(x,y) wandelt ein Integer x in das Float-Format des Floats y um
86 // und rundet dabei nötigenfalls.
87 // > x: ein Integer
88 // > y: ein Float
89 // < ergebnis: (float x y)
90 extern const cl_F cl_float (const cl_I& x, const cl_F& y);
91
92 // cl_float(x,y) wandelt ein Integer x in das Float-Format f um
93 // und rundet dabei nötigenfalls.
94 // > x: ein Integer
95 // > f: eine Float-Format-Spezifikation
96 // < ergebnis: (float x f)
97 extern const cl_F cl_float (const cl_I& x, float_format_t f);
98
99 // cl_float(x) wandelt ein Integer x in ein Float um und rundet dabei.
100 // > x: ein Integer
101 // < ergebnis: (float x)
102 // Abhängig von default_float_format.
103 extern const cl_F cl_float (const cl_I& x);
104
105 // cl_float(x,y) wandelt eine rationale Zahl x in das Float-Format des
106 // Floats y um und rundet dabei nötigenfalls.
107 // > x: eine rationale Zahl
108 // > y: ein Float
109 // < ergebnis: (float x y)
110 extern const cl_F cl_float (const cl_RA& x, const cl_F& y);
111
112 // cl_float(x,y) wandelt eine rationale Zahl x in das Float-Format f um
113 // und rundet dabei nötigenfalls.
114 // > x: eine rationale Zahl
115 // > f: eine Float-Format-Spezifikation
116 // < ergebnis: (float x f)
117 extern const cl_F cl_float (const cl_RA& x, float_format_t f);
118
119 // cl_float(x) wandelt eine rationale Zahl x in ein Float um und rundet dabei.
120 // > x: eine rationale Zahl
121 // < ergebnis: (float x)
122 // Abhängig von default_float_format.
123 extern const cl_F cl_float (const cl_RA& x);
124
125 // The C++ compilers are not clever enough to guess this:
126 inline const cl_F cl_float (int x, const cl_F& y)
127         { return cl_float(cl_I(x),y); }
128 inline const cl_F cl_float (unsigned int x, const cl_F& y)
129         { return cl_float(cl_I(x),y); }
130 inline const cl_F cl_float (int x, float_format_t y)
131         { return cl_float(cl_I(x),y); }
132 inline const cl_F cl_float (unsigned int x, float_format_t y)
133         { return cl_float(cl_I(x),y); }
134 inline const cl_F cl_float (int x)
135         { return cl_float(cl_I(x)); }
136 inline const cl_F cl_float (unsigned int x)
137         { return cl_float(cl_I(x)); }
138 // The C++ compilers could hardly guess the following:
139 inline const cl_F cl_float (float x, const cl_F& y)
140         { return cl_float(cl_FF(x),y); }
141 inline const cl_F cl_float (double x, const cl_F& y)
142         { return cl_float(cl_DF(x),y); }
143 inline const cl_F cl_float (float x, float_format_t y)
144         { return cl_float(cl_FF(x),y); }
145 inline const cl_F cl_float (double x, float_format_t y)
146         { return cl_float(cl_DF(x),y); }
147 inline const cl_F cl_float (float x)
148         { return cl_float(cl_FF(x)); }
149 inline const cl_F cl_float (double x)
150         { return cl_float(cl_DF(x)); }
151
152
153 // Liefert (- x), wo x ein Float ist.
154 extern const cl_F operator- (const cl_F& x);
155
156 // Liefert (+ x y), wo x und y Floats sind.
157 extern const cl_F operator+ (const cl_F& x, const cl_F& y);
158 // The C++ compilers could hardly guess the following:
159 inline const cl_F operator+ (const cl_RA& x, const cl_F& y)
160         { return cl_float(x,y) + y; }
161 inline const cl_F operator+ (const cl_I& x, const cl_F& y)
162         { return cl_float(x,y) + y; }
163 inline const cl_F operator+ (const cl_F& x, const cl_RA& y)
164         { return x + cl_float(y,x); }
165 inline const cl_F operator+ (const cl_F& x, const cl_I& y)
166         { return x + cl_float(y,x); }
167 // Dem C++-Compiler muß man nun auch das Folgende sagen:
168 inline const cl_F operator+ (const int x, const cl_F& y)
169         { return cl_I(x) + y; }
170 inline const cl_F operator+ (const unsigned int x, const cl_F& y)
171         { return cl_I(x) + y; }
172 inline const cl_F operator+ (const long x, const cl_F& y)
173         { return cl_I(x) + y; }
174 inline const cl_F operator+ (const unsigned long x, const cl_F& y)
175         { return cl_I(x) + y; }
176 inline const cl_F operator+ (const long long x, const cl_F& y)
177         { return cl_I(x) + y; }
178 inline const cl_F operator+ (const unsigned long long x, const cl_F& y)
179         { return cl_I(x) + y; }
180 inline const cl_F operator+ (const float x, const cl_F& y)
181         { return cl_F(x) + y; }
182 inline const cl_F operator+ (const double x, const cl_F& y)
183         { return cl_F(x) + y; }
184 inline const cl_F operator+ (const cl_F& x, const int y)
185         { return x + cl_I(y); }
186 inline const cl_F operator+ (const cl_F& x, const unsigned int y)
187         { return x + cl_I(y); }
188 inline const cl_F operator+ (const cl_F& x, const long y)
189         { return x + cl_I(y); }
190 inline const cl_F operator+ (const cl_F& x, const unsigned long y)
191         { return x + cl_I(y); }
192 inline const cl_F operator+ (const cl_F& x, const long long y)
193         { return x + cl_I(y); }
194 inline const cl_F operator+ (const cl_F& x, const unsigned long long y)
195         { return x + cl_I(y); }
196 inline const cl_F operator+ (const cl_F& x, const float y)
197         { return x + cl_F(y); }
198 inline const cl_F operator+ (const cl_F& x, const double y)
199         { return x + cl_F(y); }
200
201 // Liefert (- x y), wo x und y Floats sind.
202 extern const cl_F operator- (const cl_F& x, const cl_F& y);
203 // The C++ compilers could hardly guess the following:
204 inline const cl_F operator- (const cl_RA& x, const cl_F& y)
205         { return cl_float(x,y) - y; }
206 inline const cl_F operator- (const cl_I& x, const cl_F& y)
207         { return cl_float(x,y) - y; }
208 inline const cl_F operator- (const cl_F& x, const cl_RA& y)
209         { return x - cl_float(y,x); }
210 inline const cl_F operator- (const cl_F& x, const cl_I& y)
211         { return x - cl_float(y,x); }
212 // Dem C++-Compiler muß man nun auch das Folgende sagen:
213 inline const cl_F operator- (const int x, const cl_F& y)
214         { return cl_I(x) - y; }
215 inline const cl_F operator- (const unsigned int x, const cl_F& y)
216         { return cl_I(x) - y; }
217 inline const cl_F operator- (const long x, const cl_F& y)
218         { return cl_I(x) - y; }
219 inline const cl_F operator- (const unsigned long x, const cl_F& y)
220         { return cl_I(x) - y; }
221 inline const cl_F operator- (const long long x, const cl_F& y)
222         { return cl_I(x) - y; }
223 inline const cl_F operator- (const unsigned long long x, const cl_F& y)
224         { return cl_I(x) - y; }
225 inline const cl_F operator- (const float x, const cl_F& y)
226         { return cl_F(x) - y; }
227 inline const cl_F operator- (const double x, const cl_F& y)
228         { return cl_F(x) - y; }
229 inline const cl_F operator- (const cl_F& x, const int y)
230         { return x - cl_I(y); }
231 inline const cl_F operator- (const cl_F& x, const unsigned int y)
232         { return x - cl_I(y); }
233 inline const cl_F operator- (const cl_F& x, const long y)
234         { return x - cl_I(y); }
235 inline const cl_F operator- (const cl_F& x, const unsigned long y)
236         { return x - cl_I(y); }
237 inline const cl_F operator- (const cl_F& x, const long long y)
238         { return x - cl_I(y); }
239 inline const cl_F operator- (const cl_F& x, const unsigned long long y)
240         { return x - cl_I(y); }
241 inline const cl_F operator- (const cl_F& x, const float y)
242         { return x - cl_F(y); }
243 inline const cl_F operator- (const cl_F& x, const double y)
244         { return x - cl_F(y); }
245
246 // Liefert (* x y), wo x und y Floats sind.
247 extern const cl_F operator* (const cl_F& x, const cl_F& y);
248 // Spezialfall x oder y Integer oder rationale Zahl.
249 inline const cl_R operator* (const cl_F& x, const cl_I& y)
250 {
251         extern const cl_R cl_F_I_mul (const cl_F&, const cl_I&);
252         return cl_F_I_mul(x,y);
253 }
254 inline const cl_R operator* (const cl_I& x, const cl_F& y)
255 {
256         extern const cl_R cl_F_I_mul (const cl_F&, const cl_I&);
257         return cl_F_I_mul(y,x);
258 }
259 inline const cl_R operator* (const cl_F& x, const cl_RA& y)
260 {
261         extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
262         return cl_F_RA_mul(x,y);
263 }
264 inline const cl_R operator* (const cl_RA& x, const cl_F& y)
265 {
266         extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
267         return cl_F_RA_mul(y,x);
268 }
269 // Dem C++-Compiler muß man nun auch das Folgende sagen:
270 inline const cl_R operator* (const int x, const cl_F& y)
271         { return cl_I(x) * y; }
272 inline const cl_R operator* (const unsigned int x, const cl_F& y)
273         { return cl_I(x) * y; }
274 inline const cl_R operator* (const long x, const cl_F& y)
275         { return cl_I(x) * y; }
276 inline const cl_R operator* (const unsigned long x, const cl_F& y)
277         { return cl_I(x) * y; }
278 inline const cl_R operator* (const long long x, const cl_F& y)
279         { return cl_I(x) * y; }
280 inline const cl_R operator* (const unsigned long long x, const cl_F& y)
281         { return cl_I(x) * y; }
282 inline const cl_F operator* (const float x, const cl_F& y)
283         { return cl_F(x) * y; }
284 inline const cl_F operator* (const double x, const cl_F& y)
285         { return cl_F(x) * y; }
286 inline const cl_R operator* (const cl_F& x, const int y)
287         { return x * cl_I(y); }
288 inline const cl_R operator* (const cl_F& x, const unsigned int y)
289         { return x * cl_I(y); }
290 inline const cl_R operator* (const cl_F& x, const long y)
291         { return x * cl_I(y); }
292 inline const cl_R operator* (const cl_F& x, const unsigned long y)
293         { return x * cl_I(y); }
294 inline const cl_R operator* (const cl_F& x, const long long y)
295         { return x * cl_I(y); }
296 inline const cl_R operator* (const cl_F& x, const unsigned long long y)
297         { return x * cl_I(y); }
298 inline const cl_F operator* (const cl_F& x, const float y)
299         { return x * cl_F(y); }
300 inline const cl_F operator* (const cl_F& x, const double y)
301         { return x * cl_F(y); }
302
303 // Liefert (* x x), wo x ein Float ist.
304 extern const cl_F square (const cl_F& x);
305
306 // Liefert (/ x y), wo x und y Floats sind.
307 extern const cl_F operator/ (const cl_F& x, const cl_F& y);
308 // Liefert (/ x y), wo x und y ein Float und eine rationale Zahl sind.
309 extern const cl_F operator/ (const cl_F& x, const cl_RA& y);
310 extern const cl_F operator/ (const cl_F& x, const cl_I& y);
311 extern const cl_R operator/ (const cl_RA& x, const cl_F& y);
312 extern const cl_R operator/ (const cl_I& x, const cl_F& y);
313 // The C++ compilers could hardly guess the following:
314 inline const cl_F operator/ (const cl_F& x, const int y)
315         { return x / cl_I(y); }
316 inline const cl_F operator/ (const cl_F& x, const unsigned int y)
317         { return x / cl_I(y); }
318 inline const cl_F operator/ (const cl_F& x, const long y)
319         { return x / cl_I(y); }
320 inline const cl_F operator/ (const cl_F& x, const unsigned long y)
321         { return x / cl_I(y); }
322 inline const cl_F operator/ (const cl_F& x, const long long y)
323         { return x / cl_I(y); }
324 inline const cl_F operator/ (const cl_F& x, const unsigned long long y)
325         { return x / cl_I(y); }
326 inline const cl_F operator/ (const cl_F& x, const float y)
327         { return x / cl_F(y); }
328 inline const cl_F operator/ (const cl_F& x, const double y)
329         { return x / cl_F(y); }
330 inline const cl_R operator/ (const int x, const cl_F& y)
331         { return cl_I(x) / y; }
332 inline const cl_R operator/ (const unsigned int x, const cl_F& y)
333         { return cl_I(x) / y; }
334 inline const cl_R operator/ (const long x, const cl_F& y)
335         { return cl_I(x) / y; }
336 inline const cl_R operator/ (const unsigned long x, const cl_F& y)
337         { return cl_I(x) / y; }
338 inline const cl_R operator/ (const long long x, const cl_F& y)
339         { return cl_I(x) / y; }
340 inline const cl_R operator/ (const unsigned long long x, const cl_F& y)
341         { return cl_I(x) / y; }
342 inline const cl_F operator/ (const float x, const cl_F& y)
343         { return cl_F(x) / y; }
344 inline const cl_F operator/ (const double x, const cl_F& y)
345         { return cl_F(x) / y; }
346
347 // Liefert (abs x), wo x ein Float ist.
348 extern const cl_F abs (const cl_F& x);
349
350 // Liefert zu einem Float x>=0 : (sqrt x), ein Float.
351 extern const cl_F sqrt (const cl_F& x);
352
353 // recip(x) liefert (/ x), wo x ein Float ist.
354 extern const cl_F recip (const cl_F& x);
355
356 // (1+ x), wo x ein Float ist.
357 inline const cl_F plus1 (const cl_F& x) // { return x + cl_I(1); }
358 {
359         return x + cl_float(1,x);
360 }
361
362 // (1- x), wo x ein Float ist.
363 inline const cl_F minus1 (const cl_F& x) // { return x + cl_I(-1); }
364 {
365         return x + cl_float(-1,x);
366 }
367
368 // compare(x,y) vergleicht zwei Floats x und y.
369 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
370 extern cl_signean compare (const cl_F& x, const cl_F& y);
371
372 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
373 extern uint32 equal_hashcode (const cl_F& x);
374
375 inline bool operator== (const cl_F& x, const cl_F& y)
376         { return compare(x,y)==0; }
377 inline bool operator!= (const cl_F& x, const cl_F& y)
378         { return compare(x,y)!=0; }
379 inline bool operator<= (const cl_F& x, const cl_F& y)
380         { return compare(x,y)<=0; }
381 inline bool operator< (const cl_F& x, const cl_F& y)
382         { return compare(x,y)<0; }
383 inline bool operator>= (const cl_F& x, const cl_F& y)
384         { return compare(x,y)>=0; }
385 inline bool operator> (const cl_F& x, const cl_F& y)
386         { return compare(x,y)>0; }
387
388
389 // ffloor(x) liefert (ffloor x), wo x ein Float ist.
390 extern const cl_F ffloor (const cl_F& x);
391
392 // fceiling(x) liefert (fceiling x), wo x ein Float ist.
393 extern const cl_F fceiling (const cl_F& x);
394
395 // ftruncate(x) liefert (ftruncate x), wo x ein Float ist.
396 extern const cl_F ftruncate (const cl_F& x);
397
398 // fround(x) liefert (fround x), wo x ein Float ist.
399 extern const cl_F fround (const cl_F& x);
400
401
402 // Return type for frounding operators.
403 // x / y  --> (q,r) with x = y*q+r.
404 struct cl_F_fdiv_t {
405         cl_F quotient;
406         cl_F remainder;
407 // Constructor.
408         cl_F_fdiv_t () {}
409         cl_F_fdiv_t (const cl_F& q, const cl_F& r) : quotient(q), remainder(r) {}
410 };
411
412 // ffloor2(x) liefert (ffloor x), wo x ein F ist.
413 extern const cl_F_fdiv_t ffloor2 (const cl_F& x);
414
415 // fceiling2(x) liefert (fceiling x), wo x ein F ist.
416 extern const cl_F_fdiv_t fceiling2 (const cl_F& x);
417
418 // ftruncate2(x) liefert (ftruncate x), wo x ein F ist.
419 extern const cl_F_fdiv_t ftruncate2 (const cl_F& x);
420
421 // fround2(x) liefert (fround x), wo x ein F ist.
422 extern const cl_F_fdiv_t fround2 (const cl_F& x);
423
424
425 // Return type for rounding operators.
426 // x / y  --> (q,r) with x = y*q+r.
427 struct cl_F_div_t {
428         cl_I quotient;
429         cl_F remainder;
430 // Constructor.
431         cl_F_div_t () {}
432         cl_F_div_t (const cl_I& q, const cl_F& r) : quotient(q), remainder(r) {}
433 };
434
435 // floor2(x) liefert (floor x), wo x ein F ist.
436 extern const cl_F_div_t floor2 (const cl_F& x);
437 extern const cl_I floor1 (const cl_F& x);
438
439 // ceiling2(x) liefert (ceiling x), wo x ein F ist.
440 extern const cl_F_div_t ceiling2 (const cl_F& x);
441 extern const cl_I ceiling1 (const cl_F& x);
442
443 // truncate2(x) liefert (truncate x), wo x ein F ist.
444 extern const cl_F_div_t truncate2 (const cl_F& x);
445 extern const cl_I truncate1 (const cl_F& x);
446
447 // round2(x) liefert (round x), wo x ein F ist.
448 extern const cl_F_div_t round2 (const cl_F& x);
449 extern const cl_I round1 (const cl_F& x);
450
451 // floor2(x,y) liefert (floor x y), wo x und y Floats sind.
452 extern const cl_F_div_t floor2 (const cl_F& x, const cl_F& y);
453 inline const cl_I floor1 (const cl_F& x, const cl_F& y) { return floor1(x/y); }
454
455 // ceiling2(x,y) liefert (ceiling x y), wo x und y Floats sind.
456 extern const cl_F_div_t ceiling2 (const cl_F& x, const cl_F& y);
457 inline const cl_I ceiling1 (const cl_F& x, const cl_F& y) { return ceiling1(x/y); }
458
459 // truncate2(x,y) liefert (truncate x y), wo x und y Floats sind.
460 extern const cl_F_div_t truncate2 (const cl_F& x, const cl_F& y);
461 inline const cl_I truncate1 (const cl_F& x, const cl_F& y) { return truncate1(x/y); }
462
463 // round2(x,y) liefert (round x y), wo x und y Floats sind.
464 extern const cl_F_div_t round2 (const cl_F& x, const cl_F& y);
465 inline const cl_I round1 (const cl_F& x, const cl_F& y) { return round1(x/y); }
466
467
468 // Return type for decode_float:
469 struct decoded_float {
470         cl_F mantissa;
471         cl_I exponent;
472         cl_F sign;
473 // Constructor.
474         decoded_float () {}
475         decoded_float (const cl_F& m, const cl_I& e, const cl_F& s) : mantissa(m), exponent(e), sign(s) {}
476 };
477
478 // decode_float(x) liefert zu einem Float x: (decode-float x).
479 // x = 0.0 liefert (0.0, 0, 1.0).
480 // x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
481 extern const decoded_float decode_float (const cl_F& x);
482
483 // float_exponent(x) liefert zu einem Float x:
484 // den Exponenten von (decode-float x).
485 // x = 0.0 liefert 0.
486 // x = (-1)^s * 2^e * m liefert e.
487 extern sintE float_exponent (const cl_F& x);
488
489 // float_radix(x) liefert (float-radix x), wo x ein Float ist.
490 inline sintL float_radix (const cl_F& x)
491 {
492         (void)x; // unused x
493         return 2;
494 }
495
496 // float_sign(x) liefert (float-sign x), wo x ein Float ist.
497 extern const cl_F float_sign (const cl_F& x);
498
499 // float_sign(x,y) liefert (float-sign x y), wo x und y Floats sind.
500 extern const cl_F float_sign (const cl_F& x, const cl_F& y);
501
502 // float_digits(x) liefert (float-digits x), wo x ein Float ist.
503 // < ergebnis: ein uintC >0
504 extern uintC float_digits (const cl_F& x);
505
506 // float_precision(x) liefert (float-precision x), wo x ein Float ist.
507 // < ergebnis: ein uintC >=0
508 extern uintC float_precision (const cl_F& x);
509
510 // Returns the floating point format of a float.
511 inline float_format_t float_format (const cl_F& x)
512         { return (float_format_t) float_digits(x); }
513
514
515 // integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
516 // x = 0.0 liefert (0, 0, 1).
517 // x = (-1)^s * 2^e * m bei Float-Precision p liefert
518 //   (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
519 extern const cl_idecoded_float integer_decode_float (const cl_F& x);
520
521
522 // rational(x) liefert (rational x), wo x ein Float ist.
523 extern const cl_RA rational (const cl_F& x);
524
525
526 // scale_float(x,delta) liefert x*2^delta, wo x ein Float ist.
527 extern const cl_F scale_float (const cl_F& x, sintC delta);
528 extern const cl_F scale_float (const cl_F& x, const cl_I& delta);
529
530
531 // max(x,y) liefert (max x y), wo x und y Floats sind.
532 extern const cl_F max (const cl_F& x, const cl_F& y);
533
534 // min(x,y) liefert (min x y), wo x und y Floats sind.
535 extern const cl_F min (const cl_F& x, const cl_F& y);
536
537 // signum(x) liefert (signum x), wo x ein Float ist.
538 extern const cl_F signum (const cl_F& x);
539
540
541 // Returns the largest (most positive) floating point number in float format f.
542 extern const cl_F most_positive_float (float_format_t f);
543
544 // Returns the smallest (most negative) floating point number in float format f.
545 extern const cl_F most_negative_float (float_format_t f);
546
547 // Returns the least positive floating point number (i.e. > 0 but closest to 0)
548 // in float format f.
549 extern const cl_F least_positive_float (float_format_t f);
550
551 // Returns the least negative floating point number (i.e. < 0 but closest to 0)
552 // in float format f.
553 extern const cl_F least_negative_float (float_format_t f);
554
555 // Returns the smallest floating point number e > 0 such that 1+e != 1.
556 extern const cl_F float_epsilon (float_format_t f);
557
558 // Returns the smallest floating point number e > 0 such that 1-e != 1.
559 extern const cl_F float_negative_epsilon (float_format_t f);
560
561
562 // Konversion zu einem C "float".
563 extern float float_approx (const cl_F& x);
564
565 // Konversion zu einem C "double".
566 extern double double_approx (const cl_F& x);
567
568
569 // Transcendental functions
570
571
572 // pi(y) liefert die Zahl pi im selben Float-Format wie y.
573 // > y: ein Float
574 extern const cl_F pi (const cl_F& y);
575
576 // pi(y) liefert die Zahl pi im Float-Format f.
577 // > f: eine Float-Format-Spezifikation
578 extern const cl_F pi (float_format_t f);
579
580 // pi() liefert die Zahl pi im Default-Float-Format.
581 extern const cl_F pi (void);
582
583
584 // sin(x) liefert den Sinus (sin x) eines Float x.
585 extern const cl_F sin (const cl_F& x);
586
587 // cos(x) liefert den Cosinus (cos x) eines Float x.
588 extern const cl_F cos (const cl_F& x);
589
590 // Return type for cos_sin():
591 struct cos_sin_t {
592         cl_R cos;
593         cl_R sin;
594 // Constructor:
595         cos_sin_t () {}
596         cos_sin_t (const cl_R& u, const cl_R& v) : cos (u), sin (v) {}
597 };
598
599 // cos_sin(x) liefert ((cos x),(sin x)), beide Werte.
600 extern const cos_sin_t cos_sin (const cl_F& x);
601
602 // tan(x) liefert den Tangens (tan x) eines Float x.
603 extern const cl_F tan (const cl_F& x);
604
605
606 // exp1(y) liefert die Zahl e = exp(1) im selben Float-Format wie y.
607 // > y: ein Float
608 extern const cl_F exp1 (const cl_F& y);
609
610 // exp1(y) liefert die Zahl e = exp(1) im Float-Format f.
611 // > f: eine Float-Format-Spezifikation
612 extern const cl_F exp1 (float_format_t f);
613
614 // exp1() liefert die Zahl e = exp(1) im Default-Float-Format.
615 extern const cl_F exp1 (void);
616
617
618 // ln(x) liefert zu einem Float x>0 die Zahl ln(x).
619 extern const cl_F ln (const cl_F& x);
620 // Spezialfall: x Long-Float -> Ergebnis Long-Float
621 inline const cl_LF ln (const cl_LF& x) { return The(cl_LF)(ln(The(cl_F)(x))); }
622
623 // exp(x) liefert zu einem Float x die Zahl exp(x).
624 extern const cl_F exp (const cl_F& x);
625
626 // sinh(x) liefert zu einem Float x die Zahl sinh(x).
627 extern const cl_F sinh (const cl_F& x);
628
629 // cosh(x) liefert zu einem Float x die Zahl cosh(x).
630 extern const cl_F cosh (const cl_F& x);
631
632 // Return type for cosh_sinh():
633 struct cosh_sinh_t {
634         cl_R cosh;
635         cl_R sinh;
636 // Constructor:
637         cosh_sinh_t () {}
638         cosh_sinh_t (const cl_R& u, const cl_R& v) : cosh (u), sinh (v) {}
639 };
640
641 // cosh_sinh(x) liefert ((cosh x),(sinh x)), beide Werte.
642 extern const cosh_sinh_t cosh_sinh (const cl_F& x);
643
644 // tanh(x) liefert zu einem Float x die Zahl tanh(x).
645 extern const cl_F tanh (const cl_F& x);
646
647
648 // eulerconst(y) liefert die Eulersche Konstante
649 // im selben Float-Format wie y.
650 // > y: ein Float
651 extern const cl_F eulerconst (const cl_F& y);
652
653 // eulerconst(y) liefert die Eulersche Konstante im Float-Format f.
654 // > f: eine Float-Format-Spezifikation
655 extern const cl_F eulerconst (float_format_t f);
656
657 // eulerconst() liefert die Eulersche Konstante im Default-Float-Format.
658 extern const cl_F eulerconst (void);
659
660 // catalanconst(y) liefert die Catalansche Konstante
661 // im selben Float-Format wie y.
662 // > y: ein Float
663 extern const cl_F catalanconst (const cl_F& y);
664
665 // catalanconst(y) liefert die Catalansche Konstante im Float-Format f.
666 // > f: eine Float-Format-Spezifikation
667 extern const cl_F catalanconst (float_format_t f);
668
669 // catalanconst() liefert die Catalansche Konstante im Default-Float-Format.
670 extern const cl_F catalanconst (void);
671
672 // zeta(s) returns the Riemann zeta function at s>1.
673 extern const cl_F zeta (int s, const cl_F& y);
674 extern const cl_F zeta (int s, float_format_t f);
675 extern const cl_F zeta (int s);
676
677
678 // random_F(randomstate,n) liefert zu einem Float n>0 ein zufälliges
679 // Float x mit 0 <= x < n.
680 // > randomstate: ein Random-State, wird verändert
681 extern const cl_F random_F (random_state& randomstate, const cl_F& n);
682
683 inline const cl_F random_F (const cl_F& n)
684         { return random_F(default_random_state,n); }
685
686
687 // This could be optimized to use in-place operations.
688 inline cl_F& operator+= (cl_F& x, const cl_F& y) { return x = x + y; }
689 inline cl_F& operator+= (cl_F& x, const float y) { return x = x + y; }
690 inline cl_F& operator+= (cl_F& x, const double y) { return x = x + y; }
691 inline cl_F& operator++ /* prefix */ (cl_F& x) { return x = plus1(x); }
692 inline void operator++ /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = plus1(x); }
693 inline cl_F& operator-= (cl_F& x, const cl_F& y) { return x = x - y; }
694 inline cl_F& operator-= (cl_F& x, const float y) { return x = x - y; }
695 inline cl_F& operator-= (cl_F& x, const double y) { return x = x - y; }
696 inline cl_F& operator-- /* prefix */ (cl_F& x) { return x = minus1(x); }
697 inline void operator-- /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = minus1(x); }
698 inline cl_F& operator*= (cl_F& x, const cl_F& y) { return x = x * y; }
699 inline cl_F& operator*= (cl_F& x, const float y) { return x = x * y; }
700 inline cl_F& operator*= (cl_F& x, const double y) { return x = x * y; }
701 inline cl_F& operator/= (cl_F& x, const cl_F& y) { return x = x / y; }
702 inline cl_F& operator/= (cl_F& x, const float y) { return x = x / y; }
703 inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; }
704
705 // Thrown when a floating-point exception occurs.
706 class floating_point_exception : public runtime_exception {
707 public:
708         explicit floating_point_exception(const std::string & what)
709                 : runtime_exception(what) {}
710 };
711
712 // Thrown when NaN occurs.
713 class floating_point_nan_exception : public floating_point_exception {
714 public:
715         floating_point_nan_exception();
716 };
717
718 // Thrown when overflow occurs.
719 class floating_point_overflow_exception : public floating_point_exception {
720 public:
721         floating_point_overflow_exception();
722 };
723
724 // Thrown when underflow occurs.
725 class floating_point_underflow_exception : public floating_point_exception {
726 public:
727         floating_point_underflow_exception();
728 };
729
730
731
732
733 // If this is true, floating point underflow returns zero instead of throwing an exception.
734 extern bool cl_inhibit_floating_point_underflow;
735
736 }  // namespace cln
737
738 #endif /* _CL_FLOAT_H */