]> www.ginac.de Git - cln.git/blob - include/cl_lfloat.h
- Added lots of @cindex to produce an index.
[cln.git] / include / cl_lfloat.h
1 // Public long float operations.
2
3 #ifndef _CL_LFLOAT_H
4 #define _CL_LFLOAT_H
5
6 #include "cl_number.h"
7 #include "cl_lfloat_class.h"
8 #include "cl_integer_class.h"
9 #include "cl_float.h"
10
11
12 CL_DEFINE_AS_CONVERSION(cl_LF)
13
14
15 // Liefert zu einem Long-Float x : (- x), ein LF.
16 extern const cl_LF operator- (const cl_LF& x);
17
18 // cl_compare(x,y) vergleicht zwei Long-Floats x und y.
19 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
20 extern cl_signean cl_compare (const cl_LF& x, const cl_LF& y);
21
22 // cl_equal_hashcode(x) liefert einen cl_equal-invarianten Hashcode für x.
23 extern uint32 cl_equal_hashcode (const cl_LF& x);
24
25 inline bool operator== (const cl_LF& x, const cl_LF& y)
26         { return cl_compare(x,y)==0; }
27 inline bool operator!= (const cl_LF& x, const cl_LF& y)
28         { return cl_compare(x,y)!=0; }
29 inline bool operator<= (const cl_LF& x, const cl_LF& y)
30         { return cl_compare(x,y)<=0; }
31 inline bool operator< (const cl_LF& x, const cl_LF& y)
32         { return cl_compare(x,y)<0; }
33 inline bool operator>= (const cl_LF& x, const cl_LF& y)
34         { return cl_compare(x,y)>=0; }
35 inline bool operator> (const cl_LF& x, const cl_LF& y)
36         { return cl_compare(x,y)>0; }
37
38 // minusp(x) == (< x 0)
39 extern cl_boolean minusp (const cl_LF& x);
40
41 // zerop(x) stellt fest, ob ein Long-Float x = 0.0 ist.
42 extern cl_boolean zerop (const cl_LF& x);
43
44 // plusp(x) == (> x 0)
45 extern cl_boolean plusp (const cl_LF& x);
46
47 // Liefert zu zwei Long-Float x und y : (+ x y), ein LF.
48 extern const cl_LF operator+ (const cl_LF& x, const cl_LF& y);
49
50 // Liefert zu zwei Long-Float x und y : (- x y), ein LF.
51 extern const cl_LF operator- (const cl_LF& x, const cl_LF& y);
52
53 // Liefert zu zwei Long-Float x und y : (* x y), ein LF.
54 extern const cl_LF operator* (const cl_LF& x, const cl_LF& y);
55 // Spezialfall x oder y Integer oder rationale Zahl.
56 inline const cl_R operator* (const cl_LF& x, const cl_I& y)
57 {
58         extern const cl_R cl_LF_I_mul (const cl_LF&, const cl_I&);
59         return cl_LF_I_mul(x,y);
60 }
61 inline const cl_R operator* (const cl_I& x, const cl_LF& y)
62 {
63         extern const cl_R cl_LF_I_mul (const cl_LF&, const cl_I&);
64         return cl_LF_I_mul(y,x);
65 }
66 inline const cl_R operator* (const cl_LF& x, const cl_RA& y)
67 {
68         extern const cl_R cl_LF_RA_mul (const cl_LF&, const cl_RA&);
69         return cl_LF_RA_mul(x,y);
70 }
71 inline const cl_R operator* (const cl_RA& x, const cl_LF& y)
72 {
73         extern const cl_R cl_LF_RA_mul (const cl_LF&, const cl_RA&);
74         return cl_LF_RA_mul(y,x);
75 }
76 // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int * cl_LF' u.ä.):
77 inline const cl_R operator* (const int x, const cl_LF& y)
78         { return cl_I(x) * y; }
79 inline const cl_R operator* (const unsigned int x, const cl_LF& y)
80         { return cl_I(x) * y; }
81 inline const cl_R operator* (const long x, const cl_LF& y)
82         { return cl_I(x) * y; }
83 inline const cl_R operator* (const unsigned long x, const cl_LF& y)
84         { return cl_I(x) * y; }
85 inline const cl_R operator* (const cl_LF& x, const int y)
86         { return x * cl_I(y); }
87 inline const cl_R operator* (const cl_LF& x, const unsigned int y)
88         { return x * cl_I(y); }
89 inline const cl_R operator* (const cl_LF& x, const long y)
90         { return x * cl_I(y); }
91 inline const cl_R operator* (const cl_LF& x, const unsigned long y)
92         { return x * cl_I(y); }
93 // Spezialfall x = y.
94 // Liefert zu einem Long-Float x : (* x x), ein LF.
95 extern const cl_LF square (const cl_LF& x);
96
97 // Liefert zu zwei Long-Float x und y : (/ x y), ein LF.
98 extern const cl_LF operator/ (const cl_LF& x, const cl_LF& y);
99 // Spezialfall x oder y Integer oder rationale Zahl.
100 inline const cl_LF operator/ (const cl_LF& x, const cl_I& y)
101 {
102         extern const cl_LF cl_LF_I_div (const cl_LF& x, const cl_I& y);
103         return cl_LF_I_div(x,y);
104 }
105 inline const cl_R operator/ (const cl_I& x, const cl_LF& y)
106 {
107         extern const cl_R cl_I_LF_div (const cl_I& x, const cl_LF& y);
108         return cl_I_LF_div(x,y);
109 }
110 inline const cl_LF operator/ (const cl_LF& x, const cl_RA& y)
111 {
112         extern const cl_LF cl_LF_RA_div (const cl_LF& x, const cl_RA& y);
113         return cl_LF_RA_div(x,y);
114 }
115 inline const cl_R operator/ (const cl_RA& x, const cl_LF& y)
116 {
117         extern const cl_R cl_RA_LF_div (const cl_RA& x, const cl_LF& y);
118         return cl_RA_LF_div(x,y);
119 }
120 // Dem C++-Compiler muß man nun auch das Folgende sagen:
121 inline const cl_LF operator/ (const cl_LF& x, const int y)
122         { return x / cl_I(y); }
123 inline const cl_LF operator/ (const cl_LF& x, const unsigned int y)
124         { return x / cl_I(y); }
125 inline const cl_LF operator/ (const cl_LF& x, const long y)
126         { return x / cl_I(y); }
127 inline const cl_LF operator/ (const cl_LF& x, const unsigned long y)
128         { return x / cl_I(y); }
129 inline const cl_R operator/ (const int x, const cl_LF& y)
130         { return cl_I(x) / y; }
131 inline const cl_R operator/ (const unsigned int x, const cl_LF& y)
132         { return cl_I(x) / y; }
133 inline const cl_R operator/ (const long x, const cl_LF& y)
134         { return cl_I(x) / y; }
135 inline const cl_R operator/ (const unsigned long x, const cl_LF& y)
136         { return cl_I(x) / y; }
137
138 // Liefert zu einem Long-Float x>=0 : (sqrt x), ein LF.
139 extern const cl_LF sqrt (const cl_LF& x);
140
141 // recip(x) liefert (/ x), wo x ein Long-Float ist.
142 extern const cl_LF recip (const cl_LF& x);
143
144 // abs(x) liefert (abs x), wo x ein Long-Float ist.
145 extern const cl_LF abs (const cl_LF& x);
146
147
148 // (1+ x), wo x ein Long-Float ist.
149 extern const cl_LF plus1 (const cl_LF& x);
150
151 // (1- x), wo x ein Long-Float ist.
152 extern const cl_LF minus1 (const cl_LF& x);
153
154
155 // ffloor(x) liefert (ffloor x), wo x ein LF ist.
156 extern const cl_LF ffloor (const cl_LF& x);
157
158 // fceiling(x) liefert (fceiling x), wo x ein LF ist.
159 extern const cl_LF fceiling (const cl_LF& x);
160
161 // ftruncate(x) liefert (ftruncate x), wo x ein LF ist.
162 extern const cl_LF ftruncate (const cl_LF& x);
163
164 // fround(x) liefert (fround x), wo x ein LF ist.
165 extern const cl_LF fround (const cl_LF& x);
166
167
168 // Return type for frounding operators.
169 // x / y  --> (q,r) with x = y*q+r.
170 struct cl_LF_fdiv_t {
171         cl_LF quotient;
172         cl_LF remainder;
173 // Constructor.
174         cl_LF_fdiv_t () {}
175         cl_LF_fdiv_t (const cl_LF& q, const cl_LF& r) : quotient(q), remainder(r) {}
176 };
177
178 // ffloor2(x) liefert (ffloor x), wo x ein LF ist.
179 inline const cl_LF_fdiv_t ffloor2 (const cl_LF& x)
180 {
181         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
182         cl_LF q = ffloor(x);
183         return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
184 }
185
186 // fceiling2(x) liefert (fceiling x), wo x ein LF ist.
187 inline const cl_LF_fdiv_t fceiling2 (const cl_LF& x)
188 {
189         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
190         cl_LF q = fceiling(x);
191         return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
192 }
193
194 // ftruncate2(x) liefert (ftruncate x), wo x ein LF ist.
195 inline const cl_LF_fdiv_t ftruncate2 (const cl_LF& x)
196 {
197         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
198         cl_LF q = ftruncate(x);
199         return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
200 }
201
202 // fround2(x) liefert (fround x), wo x ein LF ist.
203 inline const cl_LF_fdiv_t fround2 (const cl_LF& x)
204 {
205         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
206         cl_LF q = fround(x);
207         return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
208 }
209
210
211 // Return type for rounding operators.
212 // x / y  --> (q,r) with x = y*q+r.
213 struct cl_LF_div_t {
214         cl_I quotient;
215         cl_LF remainder;
216 // Constructor.
217         cl_LF_div_t () {}
218         cl_LF_div_t (const cl_I& q, const cl_LF& r) : quotient(q), remainder(r) {}
219 };
220
221 // floor2(x) liefert (floor x), wo x ein LF ist.
222 inline const cl_LF_div_t floor2 (const cl_LF& x)
223 {
224         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
225         extern const cl_I cl_LF_to_I (const cl_LF& x);
226         cl_LF q = ffloor(x);
227         return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
228 }
229 inline const cl_I floor1 (const cl_LF& x)
230 {
231         extern const cl_I cl_LF_to_I (const cl_LF& x);
232         return cl_LF_to_I(ffloor(x));
233 }
234
235 // ceiling2(x) liefert (ceiling x), wo x ein LF ist.
236 inline const cl_LF_div_t ceiling2 (const cl_LF& x)
237 {
238         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
239         extern const cl_I cl_LF_to_I (const cl_LF& x);
240         cl_LF q = fceiling(x);
241         return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
242 }
243 inline const cl_I ceiling1 (const cl_LF& x)
244 {
245         extern const cl_I cl_LF_to_I (const cl_LF& x);
246         return cl_LF_to_I(fceiling(x));
247 }
248
249 // truncate2(x) liefert (truncate x), wo x ein LF ist.
250 inline const cl_LF_div_t truncate2 (const cl_LF& x)
251 {
252         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
253         extern const cl_I cl_LF_to_I (const cl_LF& x);
254         cl_LF q = ftruncate(x);
255         return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
256 }
257 inline const cl_I truncate1 (const cl_LF& x)
258 {
259         extern const cl_I cl_LF_to_I (const cl_LF& x);
260         return cl_LF_to_I(ftruncate(x));
261 }
262
263 // round2(x) liefert (round x), wo x ein LF ist.
264 inline const cl_LF_div_t round2 (const cl_LF& x)
265 {
266         extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
267         extern const cl_I cl_LF_to_I (const cl_LF& x);
268         cl_LF q = fround(x);
269         return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
270 }
271 inline const cl_I round1 (const cl_LF& x)
272 {
273         extern const cl_I cl_LF_to_I (const cl_LF& x);
274         return cl_LF_to_I(fround(x));
275 }
276
277 // floor2(x,y) liefert (floor x y).
278 extern const cl_LF_div_t floor2 (const cl_LF& x, const cl_LF& y);
279 inline const cl_I floor1 (const cl_LF& x, const cl_LF& y) { return floor1(x/y); }
280
281 // ceiling2(x,y) liefert (ceiling x y).
282 extern const cl_LF_div_t ceiling2 (const cl_LF& x, const cl_LF& y);
283 inline const cl_I ceiling1 (const cl_LF& x, const cl_LF& y) { return ceiling1(x/y); }
284
285 // truncate2(x,y) liefert (truncate x y).
286 extern const cl_LF_div_t truncate2 (const cl_LF& x, const cl_LF& y);
287 inline const cl_I truncate1 (const cl_LF& x, const cl_LF& y) { return truncate1(x/y); }
288
289 // round2(x,y) liefert (round x y).
290 extern const cl_LF_div_t round2 (const cl_LF& x, const cl_LF& y);
291 inline const cl_I round1 (const cl_LF& x, const cl_LF& y) { return round1(x/y); }
292
293
294 // cl_float(x,y) returns a long float if y is a long float.
295 inline const cl_LF cl_float (const cl_F& x, const cl_LF& y)
296 {
297         extern const cl_F cl_float (const cl_F& x, const cl_F& y);
298         return The(cl_LF)(cl_float(x,(const cl_F&)y));
299 }
300 inline const cl_LF cl_float (const cl_I& x, const cl_LF& y)
301 {
302         extern const cl_F cl_float (const cl_I& x, const cl_F& y);
303         return The(cl_LF)(cl_float(x,(const cl_F&)y));
304 }
305 inline const cl_LF cl_float (const cl_RA& x, const cl_LF& y)
306 {
307         extern const cl_F cl_float (const cl_RA& x, const cl_F& y);
308         return The(cl_LF)(cl_float(x,(const cl_F&)y));
309 }
310 inline const cl_LF cl_float (int x, const cl_LF& y)
311         { return cl_float(cl_I(x),y); }
312 inline const cl_LF cl_float (unsigned int x, const cl_LF& y)
313         { return cl_float(cl_I(x),y); }
314
315
316 // Return type for decode_float:
317 struct cl_decoded_lfloat {
318         cl_LF mantissa;
319         cl_I exponent;
320         cl_LF sign;
321 // Constructor.
322         cl_decoded_lfloat () {}
323         cl_decoded_lfloat (const cl_LF& m, const cl_I& e, const cl_LF& s) : mantissa(m), exponent(e), sign(s) {}
324 };
325
326 // decode_float(x) liefert zu einem Float x: (decode-float x).
327 // x = 0.0 liefert (0.0, 0, 1.0).
328 // x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
329 extern const cl_decoded_lfloat decode_float (const cl_LF& x);
330
331 // float_exponent(x) liefert zu einem Float x:
332 // den Exponenten von (decode-float x).
333 // x = 0.0 liefert 0.
334 // x = (-1)^s * 2^e * m liefert e.
335 extern sintL float_exponent (const cl_LF& x);
336
337 // float_radix(x) liefert (float-radix x), wo x ein Float ist.
338 inline sintL float_radix (const cl_LF& x)
339 {
340         (void)x; // unused x
341         return 2;
342 }
343
344 // float_sign(x) liefert (float-sign x), wo x ein Float ist.
345 extern const cl_LF float_sign (const cl_LF& x);
346
347 // float_digits(x) liefert (float-digits x), wo x ein Float ist.
348 // < ergebnis: ein uintL >0
349 extern uintL float_digits (const cl_LF& x);
350
351 // float_precision(x) liefert (float-precision x), wo x ein Float ist.
352 // < ergebnis: ein uintL >=0
353 extern uintL float_precision (const cl_LF& x);
354
355
356 // integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
357 // x = 0.0 liefert (0, 0, 1).
358 // x = (-1)^s * 2^e * m bei Float-Precision p liefert
359 //   (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
360 extern const cl_idecoded_float integer_decode_float (const cl_LF& x);
361
362
363 // scale_float(x,delta) liefert x*2^delta, wo x ein LF ist.
364 extern const cl_LF scale_float (const cl_LF& x, sintL delta);
365 extern const cl_LF scale_float (const cl_LF& x, const cl_I& delta);
366
367
368 // max(x,y) liefert (max x y), wo x und y Floats sind.
369 extern const cl_LF max (const cl_LF& x, const cl_LF& y);
370
371 // min(x,y) liefert (min x y), wo x und y Floats sind.
372 extern const cl_LF min (const cl_LF& x, const cl_LF& y);
373
374 // signum(x) liefert (signum x), wo x ein Float ist.
375 extern const cl_LF signum (const cl_LF& x);
376
377
378 // Konversion zu einem C "float".
379 extern float cl_float_approx (const cl_LF& x);
380
381 // Konversion zu einem C "double".
382 extern double cl_double_approx (const cl_LF& x);
383
384
385 #ifdef WANT_OBFUSCATING_OPERATORS
386 // This could be optimized to use in-place operations.
387 inline cl_LF& operator+= (cl_LF& x, const cl_LF& y) { return x = x + y; }
388 inline cl_LF& operator++ /* prefix */ (cl_LF& x) { return x = plus1(x); }
389 inline void operator++ /* postfix */ (cl_LF& x, int dummy) { (void)dummy; x = plus1(x); }
390 inline cl_LF& operator-= (cl_LF& x, const cl_LF& y) { return x = x - y; }
391 inline cl_LF& operator-- /* prefix */ (cl_LF& x) { return x = minus1(x); }
392 inline void operator-- /* postfix */ (cl_LF& x, int dummy) { (void)dummy; x = minus1(x); }
393 inline cl_LF& operator*= (cl_LF& x, const cl_LF& y) { return x = x * y; }
394 inline cl_LF& operator/= (cl_LF& x, const cl_LF& y) { return x = x / y; }
395 #endif
396
397
398 // Runtime typing support.
399 extern cl_class cl_class_lfloat;
400
401
402 // Debugging support.
403 #ifdef CL_DEBUG
404 extern int cl_LF_debug_module;
405 static void* const cl_LF_debug_dummy[] = { &cl_LF_debug_dummy,
406         &cl_LF_debug_module
407 };
408 #endif
409
410
411 #endif /* _CL_LFLOAT_H */