]> www.ginac.de Git - cln.git/blob - src/float/lfloat/cl_LF.h
* */*: Remove cl_boolean, cl_true, and cl_false in favor of built-in
[cln.git] / src / float / lfloat / cl_LF.h
1 // cl_LF internals
2
3 #ifndef _CL_LF_H
4 #define _CL_LF_H
5
6 #include "cln/number.h"
7 #include "cln/lfloat_class.h"
8 #include "cln/integer_class.h"
9
10 namespace cln {
11
12 struct cl_heap_lfloat : cl_heap {
13         unsigned int len;       // length of mantissa (in digits)
14         int sign;               // sign (0 or -1)
15         uintE expo;             // exponent
16         uintD data[1];          // mantissa
17 };
18
19 // Minimum number of mantissa digits,
20 // so that a LF has not fewer mantissa bits than a DF.
21   #define LF_minlen  ceiling(53,intDsize)
22 // Exponent.
23 #if (intEsize==64)
24   #define LF_exp_low  1
25   #define LF_exp_mid  0x8000000000000000ULL
26   #define LF_exp_high 0xFFFFFFFFFFFFFFFFULL
27 #else
28   #define LF_exp_low  1
29   #define LF_exp_mid  0x80000000U
30   #define LF_exp_high 0xFFFFFFFFU
31 #endif
32
33 inline cl_heap_lfloat* TheLfloat (cl_heap_lfloat* p)
34         { return p; }
35 inline cl_heap_lfloat* TheLfloat (const cl_number& obj)
36         { return (cl_heap_lfloat*)(obj.pointer); }
37
38
39 // Liefert zu einem Long-Float x : (futruncate x), ein LF.
40 // x wird von der 0 weg zur nächsten ganzen Zahl gerundet.
41 extern const cl_LF futruncate (const cl_LF& x);
42
43 // shorten(x,len) verkürzt ein Long-Float x auf gegebene Länge len
44 // und rundet dabei.
45 // > cl_LF x: ein Long-FLoat
46 // > uintC len: gewünschte Länge (>= LF_minlen, < TheLfloat(x)->len)
47 // < cl_LF ergebnis: verkürztes Long-Float
48 extern const cl_LF shorten (const cl_LF& x, uintC len);
49
50 // extend(x,len) verlängert ein Long-Float x auf gegebene Länge len.
51 // > cl_LF x: ein Long-FLoat
52 // > uintC len: gewünschte Länge (> TheLfloat(x)->len)
53 // < cl_LF ergebnis: verlängertes Long-Float
54 extern const cl_LF extend (const cl_LF& x, uintC len);
55
56 // LF_to_LF(x,len) wandelt ein Long-Float x in ein Long-Float gegebener Länge
57 // len um und rundet dabei nötigenfalls.
58 // > cl_LF x: ein Long-FLoat
59 // > uintC len: gewünschte Länge (>= LF_minlen)
60 // < cl_LF ergebnis: Long-Float gegebener Länge
61 extern const cl_LF LF_to_LF (const cl_LF& x, uintC len);
62
63 // GEN_LF_OP2(arg1,arg2,LF_OP,ergebnis_zuweisung)
64 // generates the body of a LF operation with two arguments.
65 // LF_OP is only executed once both arguments have been converted to the same
66 // float format (the longer one of arg1 and arg2). The result is then
67 // converted the shorter of the two float formats.
68 #define GEN_LF_OP2(arg1,arg2,LF_OP,ergebnis_zuweisung)  \
69 {                                                                       \
70         var uintC len1 = TheLfloat(arg1)->len;                          \
71         var uintC len2 = TheLfloat(arg2)->len;                          \
72         if (len1==len2) /* gleich -> direkt ausführen */                \
73                 return LF_OP(arg1,arg2);                                \
74         elif (len1>len2) /* -> arg2 auf die Länge von arg1 bringen */   \
75                 return shorten(LF_OP(arg1,extend(arg2,len1)),len2);     \
76         else /* (len1<len2) -> arg1 auf die Länge von arg2 bringen */   \
77                 return shorten(LF_OP(extend(arg1,len2),arg2),len1);     \
78 }
79
80 // Liefert zu zwei gleichlangen Long-Float x und y : (+ x y), ein LF.
81 // LF_LF_plus_LF(x)
82 extern const cl_LF LF_LF_plus_LF (const cl_LF& x, const cl_LF& y);
83
84 // Liefert zu zwei gleichlangen Long-Float x und y : (- x y), ein LF.
85 // LF_LF_minus_LF(x)
86 extern const cl_LF LF_LF_minus_LF (const cl_LF& x, const cl_LF& y);
87
88 // Use this macro if ALL of your cl_LF operations (+, -, *, /) in the
89 // rest of your file ALWAYS get two operands of the same precision.
90 #define ALL_cl_LF_OPERATIONS_SAME_PRECISION()  \
91                                                                         \
92 inline const cl_LF operator+ (const cl_LF& x, const cl_LF& y)           \
93 {                                                                       \
94         return LF_LF_plus_LF(x,y);                                      \
95 }                                                                       \
96                                                                         \
97 inline const cl_LF operator- (const cl_LF& x, const cl_LF& y)           \
98 {                                                                       \
99         return LF_LF_minus_LF(x,y);                                     \
100 }
101
102 // LF_to_I(x) wandelt ein Long-Float x, das eine ganze Zahl darstellt,
103 // in ein Integer um.
104 extern const cl_I cl_LF_to_I (const cl_LF& x);
105
106 // cl_I_to_LF(x,len) wandelt ein Integer x in ein Long-Float um und rundet dabei.
107 extern const cl_LF cl_I_to_LF (const cl_I& x, uintC len);
108
109 // cl_RA_to_LF(x,len) wandelt eine rationale Zahl x in ein Long-Float um
110 // und rundet dabei.
111 extern const cl_LF cl_RA_to_LF (const cl_RA& x, uintC len);
112
113 // cl_LF_I_mul(x,y) multipliziert ein Long-Float x und ein Integer y.
114 extern const cl_R cl_LF_I_mul (const cl_LF& x, const cl_I& y);
115
116 // cl_LF_I_div(x,y) dividiert ein Long-Float x durch ein Integer y.
117 extern const cl_LF cl_LF_I_div (const cl_LF& x, const cl_I& y);
118
119 // cl_I_LF_div(x,y) dividiert ein Integer x durch ein Long-Float y.
120 extern const cl_R cl_I_LF_div (const cl_I& x, const cl_LF& y);
121
122 // cl_LF_RA_mul(x,y) multipliziert ein Long-Float x und eine rationale Zahl y.
123 extern const cl_R cl_LF_RA_mul (const cl_LF& x, const cl_RA& y);
124
125 // cl_LF_RA_div(x,y) dividiert ein Long-Float x durch eine rationale Zahl y.
126 extern const cl_LF cl_LF_RA_div (const cl_LF& x, const cl_RA& y);
127
128 // cl_RA_LF_div(x,y) dividiert eine rationale Zahl x durch ein Long-Float y.
129 extern const cl_R cl_RA_LF_div (const cl_RA& x, const cl_LF& y);
130
131 // Vergrößert eine Long-Float-Länge n, so daß aus d = intDsize*n
132 // mindestens d+sqrt(d)+2 wird.
133 extern uintC cl_LF_len_incsqrt (uintC len);
134
135 // Vergrößert eine Long-Float-Länge n, so daß aus d = intDsize*n
136 // mindestens d+sqrt(d)+2+(LF_exp_len-1) wird.
137 extern uintC cl_LF_len_incsqrtx (uintC len);
138
139 // cl_LF_shortenrelative(x,y) tries to reduce the size of x, such that one
140 // wouldn't notice it when adding x to y. y must be /= 0. More precisely,
141 // this returns a float approximation of x, such that 1 ulp(x) < 1 ulp(y).
142 extern const cl_LF cl_LF_shortenrelative (const cl_LF& x, const cl_LF& y);
143
144 // cl_LF_shortenwith(x,y) tries to reduce the size of x, such that still
145 // 1 ulp(x) < y. y must be >0.
146 extern const cl_LF cl_LF_shortenwith (const cl_LF& x, const cl_LF& y);
147
148 }  // namespace cln
149
150 #endif /* _CL_LF_H */