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