]> www.ginac.de Git - cln.git/blob - include/cln/float.h
2006-05-30 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
[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 float x, const cl_F& y)
176         { return cl_F(x) + y; }
177 inline const cl_F operator+ (const double x, const cl_F& y)
178         { return cl_F(x) + y; }
179 inline const cl_F operator+ (const cl_F& x, const int y)
180         { return x + cl_I(y); }
181 inline const cl_F operator+ (const cl_F& x, const unsigned int y)
182         { return x + cl_I(y); }
183 inline const cl_F operator+ (const cl_F& x, const long y)
184         { return x + cl_I(y); }
185 inline const cl_F operator+ (const cl_F& x, const unsigned long y)
186         { return x + cl_I(y); }
187 inline const cl_F operator+ (const cl_F& x, const float y)
188         { return x + cl_F(y); }
189 inline const cl_F operator+ (const cl_F& x, const double y)
190         { return x + cl_F(y); }
191
192 // Liefert (- x y), wo x und y Floats sind.
193 extern const cl_F operator- (const cl_F& x, const cl_F& y);
194 // The C++ compilers could hardly guess the following:
195 inline const cl_F operator- (const cl_RA& x, const cl_F& y)
196         { return cl_float(x,y) - y; }
197 inline const cl_F operator- (const cl_I& x, const cl_F& y)
198         { return cl_float(x,y) - y; }
199 inline const cl_F operator- (const cl_F& x, const cl_RA& y)
200         { return x - cl_float(y,x); }
201 inline const cl_F operator- (const cl_F& x, const cl_I& y)
202         { return x - cl_float(y,x); }
203 // Dem C++-Compiler muß man nun auch das Folgende sagen:
204 inline const cl_F operator- (const int x, const cl_F& y)
205         { return cl_I(x) - y; }
206 inline const cl_F operator- (const unsigned int x, const cl_F& y)
207         { return cl_I(x) - y; }
208 inline const cl_F operator- (const long x, const cl_F& y)
209         { return cl_I(x) - y; }
210 inline const cl_F operator- (const unsigned long x, const cl_F& y)
211         { return cl_I(x) - y; }
212 inline const cl_F operator- (const float x, const cl_F& y)
213         { return cl_F(x) - y; }
214 inline const cl_F operator- (const double x, const cl_F& y)
215         { return cl_F(x) - y; }
216 inline const cl_F operator- (const cl_F& x, const int y)
217         { return x - cl_I(y); }
218 inline const cl_F operator- (const cl_F& x, const unsigned int y)
219         { return x - cl_I(y); }
220 inline const cl_F operator- (const cl_F& x, const long y)
221         { return x - cl_I(y); }
222 inline const cl_F operator- (const cl_F& x, const unsigned long y)
223         { return x - cl_I(y); }
224 inline const cl_F operator- (const cl_F& x, const float y)
225         { return x - cl_F(y); }
226 inline const cl_F operator- (const cl_F& x, const double y)
227         { return x - cl_F(y); }
228
229 // Liefert (* x y), wo x und y Floats sind.
230 extern const cl_F operator* (const cl_F& x, const cl_F& y);
231 // Spezialfall x oder y Integer oder rationale Zahl.
232 inline const cl_R operator* (const cl_F& x, const cl_I& y)
233 {
234         extern const cl_R cl_F_I_mul (const cl_F&, const cl_I&);
235         return cl_F_I_mul(x,y);
236 }
237 inline const cl_R operator* (const cl_I& x, const cl_F& y)
238 {
239         extern const cl_R cl_F_I_mul (const cl_F&, const cl_I&);
240         return cl_F_I_mul(y,x);
241 }
242 inline const cl_R operator* (const cl_F& x, const cl_RA& y)
243 {
244         extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
245         return cl_F_RA_mul(x,y);
246 }
247 inline const cl_R operator* (const cl_RA& x, const cl_F& y)
248 {
249         extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
250         return cl_F_RA_mul(y,x);
251 }
252 // Dem C++-Compiler muß man nun auch das Folgende sagen:
253 inline const cl_R operator* (const int x, const cl_F& y)
254         { return cl_I(x) * y; }
255 inline const cl_R operator* (const unsigned int x, const cl_F& y)
256         { return cl_I(x) * y; }
257 inline const cl_R operator* (const long x, const cl_F& y)
258         { return cl_I(x) * y; }
259 inline const cl_R operator* (const unsigned long x, const cl_F& y)
260         { return cl_I(x) * y; }
261 inline const cl_F operator* (const float x, const cl_F& y)
262         { return cl_F(x) * y; }
263 inline const cl_F operator* (const double x, const cl_F& y)
264         { return cl_F(x) * y; }
265 inline const cl_R operator* (const cl_F& x, const int y)
266         { return x * cl_I(y); }
267 inline const cl_R operator* (const cl_F& x, const unsigned int y)
268         { return x * cl_I(y); }
269 inline const cl_R operator* (const cl_F& x, const long y)
270         { return x * cl_I(y); }
271 inline const cl_R operator* (const cl_F& x, const unsigned long y)
272         { return x * cl_I(y); }
273 inline const cl_F operator* (const cl_F& x, const float y)
274         { return x * cl_F(y); }
275 inline const cl_F operator* (const cl_F& x, const double y)
276         { return x * cl_F(y); }
277
278 // Liefert (* x x), wo x ein Float ist.
279 extern const cl_F square (const cl_F& x);
280
281 // Liefert (/ x y), wo x und y Floats sind.
282 extern const cl_F operator/ (const cl_F& x, const cl_F& y);
283 // Liefert (/ x y), wo x und y ein Float und eine rationale Zahl sind.
284 extern const cl_F operator/ (const cl_F& x, const cl_RA& y);
285 extern const cl_F operator/ (const cl_F& x, const cl_I& y);
286 extern const cl_R operator/ (const cl_RA& x, const cl_F& y);
287 extern const cl_R operator/ (const cl_I& x, const cl_F& y);
288 // The C++ compilers could hardly guess the following:
289 inline const cl_F operator/ (const cl_F& x, const int y)
290         { return x / cl_I(y); }
291 inline const cl_F operator/ (const cl_F& x, const unsigned int y)
292         { return x / cl_I(y); }
293 inline const cl_F operator/ (const cl_F& x, const long y)
294         { return x / cl_I(y); }
295 inline const cl_F operator/ (const cl_F& x, const unsigned long y)
296         { return x / cl_I(y); }
297 inline const cl_F operator/ (const cl_F& x, const float y)
298         { return x / cl_F(y); }
299 inline const cl_F operator/ (const cl_F& x, const double y)
300         { return x / cl_F(y); }
301 inline const cl_R operator/ (const int x, const cl_F& y)
302         { return cl_I(x) / y; }
303 inline const cl_R operator/ (const unsigned int x, const cl_F& y)
304         { return cl_I(x) / y; }
305 inline const cl_R operator/ (const long x, const cl_F& y)
306         { return cl_I(x) / y; }
307 inline const cl_R operator/ (const unsigned long x, const cl_F& y)
308         { return cl_I(x) / y; }
309 inline const cl_F operator/ (const float x, const cl_F& y)
310         { return cl_F(x) / y; }
311 inline const cl_F operator/ (const double x, const cl_F& y)
312         { return cl_F(x) / y; }
313
314 // Liefert (abs x), wo x ein Float ist.
315 extern const cl_F abs (const cl_F& x);
316
317 // Liefert zu einem Float x>=0 : (sqrt x), ein Float.
318 extern const cl_F sqrt (const cl_F& x);
319
320 // recip(x) liefert (/ x), wo x ein Float ist.
321 extern const cl_F recip (const cl_F& x);
322
323 // (1+ x), wo x ein Float ist.
324 inline const cl_F plus1 (const cl_F& x) // { return x + cl_I(1); }
325 {
326         return x + cl_float(1,x);
327 }
328
329 // (1- x), wo x ein Float ist.
330 inline const cl_F minus1 (const cl_F& x) // { return x + cl_I(-1); }
331 {
332         return x + cl_float(-1,x);
333 }
334
335 // compare(x,y) vergleicht zwei Floats x und y.
336 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
337 extern cl_signean compare (const cl_F& x, const cl_F& y);
338
339 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
340 extern uint32 equal_hashcode (const cl_F& x);
341
342 inline bool operator== (const cl_F& x, const cl_F& y)
343         { return compare(x,y)==0; }
344 inline bool operator!= (const cl_F& x, const cl_F& y)
345         { return compare(x,y)!=0; }
346 inline bool operator<= (const cl_F& x, const cl_F& y)
347         { return compare(x,y)<=0; }
348 inline bool operator< (const cl_F& x, const cl_F& y)
349         { return compare(x,y)<0; }
350 inline bool operator>= (const cl_F& x, const cl_F& y)
351         { return compare(x,y)>=0; }
352 inline bool operator> (const cl_F& x, const cl_F& y)
353         { return compare(x,y)>0; }
354
355
356 // ffloor(x) liefert (ffloor x), wo x ein Float ist.
357 extern const cl_F ffloor (const cl_F& x);
358
359 // fceiling(x) liefert (fceiling x), wo x ein Float ist.
360 extern const cl_F fceiling (const cl_F& x);
361
362 // ftruncate(x) liefert (ftruncate x), wo x ein Float ist.
363 extern const cl_F ftruncate (const cl_F& x);
364
365 // fround(x) liefert (fround x), wo x ein Float ist.
366 extern const cl_F fround (const cl_F& x);
367
368
369 // Return type for frounding operators.
370 // x / y  --> (q,r) with x = y*q+r.
371 struct cl_F_fdiv_t {
372         cl_F quotient;
373         cl_F remainder;
374 // Constructor.
375         cl_F_fdiv_t () {}
376         cl_F_fdiv_t (const cl_F& q, const cl_F& r) : quotient(q), remainder(r) {}
377 };
378
379 // ffloor2(x) liefert (ffloor x), wo x ein F ist.
380 extern const cl_F_fdiv_t ffloor2 (const cl_F& x);
381
382 // fceiling2(x) liefert (fceiling x), wo x ein F ist.
383 extern const cl_F_fdiv_t fceiling2 (const cl_F& x);
384
385 // ftruncate2(x) liefert (ftruncate x), wo x ein F ist.
386 extern const cl_F_fdiv_t ftruncate2 (const cl_F& x);
387
388 // fround2(x) liefert (fround x), wo x ein F ist.
389 extern const cl_F_fdiv_t fround2 (const cl_F& x);
390
391
392 // Return type for rounding operators.
393 // x / y  --> (q,r) with x = y*q+r.
394 struct cl_F_div_t {
395         cl_I quotient;
396         cl_F remainder;
397 // Constructor.
398         cl_F_div_t () {}
399         cl_F_div_t (const cl_I& q, const cl_F& r) : quotient(q), remainder(r) {}
400 };
401
402 // floor2(x) liefert (floor x), wo x ein F ist.
403 extern const cl_F_div_t floor2 (const cl_F& x);
404 extern const cl_I floor1 (const cl_F& x);
405
406 // ceiling2(x) liefert (ceiling x), wo x ein F ist.
407 extern const cl_F_div_t ceiling2 (const cl_F& x);
408 extern const cl_I ceiling1 (const cl_F& x);
409
410 // truncate2(x) liefert (truncate x), wo x ein F ist.
411 extern const cl_F_div_t truncate2 (const cl_F& x);
412 extern const cl_I truncate1 (const cl_F& x);
413
414 // round2(x) liefert (round x), wo x ein F ist.
415 extern const cl_F_div_t round2 (const cl_F& x);
416 extern const cl_I round1 (const cl_F& x);
417
418 // floor2(x,y) liefert (floor x y), wo x und y Floats sind.
419 extern const cl_F_div_t floor2 (const cl_F& x, const cl_F& y);
420 inline const cl_I floor1 (const cl_F& x, const cl_F& y) { return floor1(x/y); }
421
422 // ceiling2(x,y) liefert (ceiling x y), wo x und y Floats sind.
423 extern const cl_F_div_t ceiling2 (const cl_F& x, const cl_F& y);
424 inline const cl_I ceiling1 (const cl_F& x, const cl_F& y) { return ceiling1(x/y); }
425
426 // truncate2(x,y) liefert (truncate x y), wo x und y Floats sind.
427 extern const cl_F_div_t truncate2 (const cl_F& x, const cl_F& y);
428 inline const cl_I truncate1 (const cl_F& x, const cl_F& y) { return truncate1(x/y); }
429
430 // round2(x,y) liefert (round x y), wo x und y Floats sind.
431 extern const cl_F_div_t round2 (const cl_F& x, const cl_F& y);
432 inline const cl_I round1 (const cl_F& x, const cl_F& y) { return round1(x/y); }
433
434
435 // Return type for decode_float:
436 struct decoded_float {
437         cl_F mantissa;
438         cl_I exponent;
439         cl_F sign;
440 // Constructor.
441         decoded_float () {}
442         decoded_float (const cl_F& m, const cl_I& e, const cl_F& s) : mantissa(m), exponent(e), sign(s) {}
443 };
444
445 // decode_float(x) liefert zu einem Float x: (decode-float x).
446 // x = 0.0 liefert (0.0, 0, 1.0).
447 // x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
448 extern const decoded_float decode_float (const cl_F& x);
449
450 // float_exponent(x) liefert zu einem Float x:
451 // den Exponenten von (decode-float x).
452 // x = 0.0 liefert 0.
453 // x = (-1)^s * 2^e * m liefert e.
454 extern sintL float_exponent (const cl_F& x);
455
456 // float_radix(x) liefert (float-radix x), wo x ein Float ist.
457 inline sintL float_radix (const cl_F& x)
458 {
459         (void)x; // unused x
460         return 2;
461 }
462
463 // float_sign(x) liefert (float-sign x), wo x ein Float ist.
464 extern const cl_F float_sign (const cl_F& x);
465
466 // float_sign(x,y) liefert (float-sign x y), wo x und y Floats sind.
467 extern const cl_F float_sign (const cl_F& x, const cl_F& y);
468
469 // float_digits(x) liefert (float-digits x), wo x ein Float ist.
470 // < ergebnis: ein uintC >0
471 extern uintC float_digits (const cl_F& x);
472
473 // float_precision(x) liefert (float-precision x), wo x ein Float ist.
474 // < ergebnis: ein uintC >=0
475 extern uintC float_precision (const cl_F& x);
476
477 // Returns the floating point format of a float.
478 inline float_format_t float_format (const cl_F& x)
479         { return (float_format_t) float_digits(x); }
480
481
482 // integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
483 // x = 0.0 liefert (0, 0, 1).
484 // x = (-1)^s * 2^e * m bei Float-Precision p liefert
485 //   (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
486 extern const cl_idecoded_float integer_decode_float (const cl_F& x);
487
488
489 // rational(x) liefert (rational x), wo x ein Float ist.
490 extern const cl_RA rational (const cl_F& x);
491
492
493 // scale_float(x,delta) liefert x*2^delta, wo x ein Float ist.
494 extern const cl_F scale_float (const cl_F& x, sintC delta);
495 extern const cl_F scale_float (const cl_F& x, const cl_I& delta);
496
497
498 // max(x,y) liefert (max x y), wo x und y Floats sind.
499 extern const cl_F max (const cl_F& x, const cl_F& y);
500
501 // min(x,y) liefert (min x y), wo x und y Floats sind.
502 extern const cl_F min (const cl_F& x, const cl_F& y);
503
504 // signum(x) liefert (signum x), wo x ein Float ist.
505 extern const cl_F signum (const cl_F& x);
506
507
508 // Returns the largest (most positive) floating point number in float format f.
509 extern const cl_F most_positive_float (float_format_t f);
510 //CL_REQUIRE(cl_F_mostpos)
511
512 // Returns the smallest (most negative) floating point number in float format f.
513 extern const cl_F most_negative_float (float_format_t f);
514 //CL_REQUIRE(cl_F_mostneg)
515
516 // Returns the least positive floating point number (i.e. > 0 but closest to 0)
517 // in float format f.
518 extern const cl_F least_positive_float (float_format_t f);
519 //CL_REQUIRE(cl_F_leastpos)
520
521 // Returns the least negative floating point number (i.e. < 0 but closest to 0)
522 // in float format f.
523 extern const cl_F least_negative_float (float_format_t f);
524 //CL_REQUIRE(cl_F_leastneg)
525
526 // Returns the smallest floating point number e > 0 such that 1+e != 1.
527 extern const cl_F float_epsilon (float_format_t f);
528 //CL_REQUIRE(cl_F_epspos)
529
530 // Returns the smallest floating point number e > 0 such that 1-e != 1.
531 extern const cl_F float_negative_epsilon (float_format_t f);
532 //CL_REQUIRE(cl_F_epsneg)
533
534
535 // Konversion zu einem C "float".
536 extern float float_approx (const cl_F& x);
537
538 // Konversion zu einem C "double".
539 extern double double_approx (const cl_F& x);
540
541
542 // Transcendental functions
543
544
545 // pi(y) liefert die Zahl pi im selben Float-Format wie y.
546 // > y: ein Float
547 extern const cl_F pi (const cl_F& y);
548
549 // pi(y) liefert die Zahl pi im Float-Format f.
550 // > f: eine Float-Format-Spezifikation
551 extern const cl_F pi (float_format_t f);
552
553 // pi() liefert die Zahl pi im Default-Float-Format.
554 extern const cl_F pi (void);
555
556 //CL_REQUIRE(cl_F_pi_var)
557
558
559 // sin(x) liefert den Sinus (sin x) eines Float x.
560 extern const cl_F sin (const cl_F& x);
561
562 // cos(x) liefert den Cosinus (cos x) eines Float x.
563 extern const cl_F cos (const cl_F& x);
564
565 // Return type for cos_sin():
566 struct cos_sin_t {
567         cl_R cos;
568         cl_R sin;
569 // Constructor:
570         cos_sin_t (const cl_R& u, const cl_R& v) : cos (u), sin (v) {}
571 };
572
573 // cos_sin(x) liefert ((cos x),(sin x)), beide Werte.
574 extern const cos_sin_t cos_sin (const cl_F& x);
575
576 // tan(x) liefert den Tangens (tan x) eines Float x.
577 extern const cl_F tan (const cl_F& x);
578
579
580 // exp1(y) liefert die Zahl e = exp(1) im selben Float-Format wie y.
581 // > y: ein Float
582 extern const cl_F exp1 (const cl_F& y);
583
584 // exp1(y) liefert die Zahl e = exp(1) im Float-Format f.
585 // > f: eine Float-Format-Spezifikation
586 extern const cl_F exp1 (float_format_t f);
587
588 // exp1() liefert die Zahl e = exp(1) im Default-Float-Format.
589 extern const cl_F exp1 (void);
590
591 //CL_REQUIRE(cl_F_exp1_var)
592
593
594 // ln(x) liefert zu einem Float x>0 die Zahl ln(x).
595 extern const cl_F ln (const cl_F& x);
596 // Spezialfall: x Long-Float -> Ergebnis Long-Float
597 inline const cl_LF ln (const cl_LF& x) { return The(cl_LF)(ln(The(cl_F)(x))); }
598
599 // exp(x) liefert zu einem Float x die Zahl exp(x).
600 extern const cl_F exp (const cl_F& x);
601
602 // sinh(x) liefert zu einem Float x die Zahl sinh(x).
603 extern const cl_F sinh (const cl_F& x);
604
605 // cosh(x) liefert zu einem Float x die Zahl cosh(x).
606 extern const cl_F cosh (const cl_F& x);
607
608 // Return type for cosh_sinh():
609 struct cosh_sinh_t {
610         cl_R cosh;
611         cl_R sinh;
612 // Constructor:
613         cosh_sinh_t (const cl_R& u, const cl_R& v) : cosh (u), sinh (v) {}
614 };
615
616 // cosh_sinh(x) liefert ((cosh x),(sinh x)), beide Werte.
617 extern const cosh_sinh_t cosh_sinh (const cl_F& x);
618
619 // tanh(x) liefert zu einem Float x die Zahl tanh(x).
620 extern const cl_F tanh (const cl_F& x);
621
622
623 // eulerconst(y) liefert die Eulersche Konstante
624 // im selben Float-Format wie y.
625 // > y: ein Float
626 extern const cl_F eulerconst (const cl_F& y);
627
628 // eulerconst(y) liefert die Eulersche Konstante im Float-Format f.
629 // > f: eine Float-Format-Spezifikation
630 extern const cl_F eulerconst (float_format_t f);
631
632 // eulerconst() liefert die Eulersche Konstante im Default-Float-Format.
633 extern const cl_F eulerconst (void);
634
635 //CL_REQUIRE(cl_F_eulerconst_var)
636
637
638 // catalanconst(y) liefert die Catalansche Konstante
639 // im selben Float-Format wie y.
640 // > y: ein Float
641 extern const cl_F catalanconst (const cl_F& y);
642
643 // catalanconst(y) liefert die Catalansche Konstante im Float-Format f.
644 // > f: eine Float-Format-Spezifikation
645 extern const cl_F catalanconst (float_format_t f);
646
647 // catalanconst() liefert die Catalansche Konstante im Default-Float-Format.
648 extern const cl_F catalanconst (void);
649
650 //CL_REQUIRE(cl_F_catalanconst_var)
651
652
653 // zeta(s) returns the Riemann zeta function at s>1.
654 extern const cl_F zeta (int s, const cl_F& y);
655 extern const cl_F zeta (int s, float_format_t f);
656 extern const cl_F zeta (int s);
657
658
659 // random_F(randomstate,n) liefert zu einem Float n>0 ein zufälliges
660 // Float x mit 0 <= x < n.
661 // > randomstate: ein Random-State, wird verändert
662 extern const cl_F random_F (random_state& randomstate, const cl_F& n);
663
664 inline const cl_F random_F (const cl_F& n)
665         { return random_F(default_random_state,n); }
666
667
668 #ifdef WANT_OBFUSCATING_OPERATORS
669 // This could be optimized to use in-place operations.
670 inline cl_F& operator+= (cl_F& x, const cl_F& y) { return x = x + y; }
671 inline cl_F& operator+= (cl_F& x, const float y) { return x = x + y; }
672 inline cl_F& operator+= (cl_F& x, const double y) { return x = x + y; }
673 inline cl_F& operator++ /* prefix */ (cl_F& x) { return x = plus1(x); }
674 inline void operator++ /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = plus1(x); }
675 inline cl_F& operator-= (cl_F& x, const cl_F& y) { return x = x - y; }
676 inline cl_F& operator-= (cl_F& x, const float y) { return x = x - y; }
677 inline cl_F& operator-= (cl_F& x, const double y) { return x = x - y; }
678 inline cl_F& operator-- /* prefix */ (cl_F& x) { return x = minus1(x); }
679 inline void operator-- /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = minus1(x); }
680 inline cl_F& operator*= (cl_F& x, const cl_F& y) { return x = x * y; }
681 inline cl_F& operator*= (cl_F& x, const float y) { return x = x * y; }
682 inline cl_F& operator*= (cl_F& x, const double y) { return x = x * y; }
683 inline cl_F& operator/= (cl_F& x, const cl_F& y) { return x = x / y; }
684 inline cl_F& operator/= (cl_F& x, const float y) { return x = x / y; }
685 inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; }
686 #endif
687
688
689 CL_REQUIRE(cl_ieee)
690
691
692 // If this is true, floating point underflow returns zero instead of an error.
693 extern cl_boolean cl_inhibit_floating_point_underflow;
694
695 }  // namespace cln
696
697 #endif /* _CL_FLOAT_H */