Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 08:08:31

0001 // Public long float operations.
0002 
0003 #ifndef _CL_LFLOAT_H
0004 #define _CL_LFLOAT_H
0005 
0006 #include "cln/number.h"
0007 #include "cln/lfloat_class.h"
0008 #include "cln/integer_class.h"
0009 #include "cln/float.h"
0010 
0011 namespace cln {
0012 
0013 CL_DEFINE_AS_CONVERSION(cl_LF)
0014 
0015 
0016 // Liefert zu einem Long-Float x : (- x), ein LF.
0017 extern const cl_LF operator- (const cl_LF& x);
0018 
0019 // compare(x,y) vergleicht zwei Long-Floats x und y.
0020 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
0021 extern cl_signean compare (const cl_LF& x, const cl_LF& y);
0022 
0023 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
0024 extern uint32 equal_hashcode (const cl_LF& x);
0025 
0026 inline bool operator== (const cl_LF& x, const cl_LF& y)
0027     { return compare(x,y)==0; }
0028 inline bool operator!= (const cl_LF& x, const cl_LF& y)
0029     { return compare(x,y)!=0; }
0030 inline bool operator<= (const cl_LF& x, const cl_LF& y)
0031     { return compare(x,y)<=0; }
0032 inline bool operator< (const cl_LF& x, const cl_LF& y)
0033     { return compare(x,y)<0; }
0034 inline bool operator>= (const cl_LF& x, const cl_LF& y)
0035     { return compare(x,y)>=0; }
0036 inline bool operator> (const cl_LF& x, const cl_LF& y)
0037     { return compare(x,y)>0; }
0038 
0039 // minusp(x) == (< x 0)
0040 extern bool minusp (const cl_LF& x);
0041 
0042 // zerop(x) stellt fest, ob ein Long-Float x = 0.0 ist.
0043 extern bool zerop (const cl_LF& x);
0044 
0045 // plusp(x) == (> x 0)
0046 extern bool plusp (const cl_LF& x);
0047 
0048 // Liefert zu zwei Long-Float x und y : (+ x y), ein LF.
0049 extern const cl_LF operator+ (const cl_LF& x, const cl_LF& y);
0050 
0051 // Liefert zu zwei Long-Float x und y : (- x y), ein LF.
0052 extern const cl_LF operator- (const cl_LF& x, const cl_LF& y);
0053 
0054 // Liefert zu zwei Long-Float x und y : (* x y), ein LF.
0055 extern const cl_LF operator* (const cl_LF& x, const cl_LF& y);
0056 // Spezialfall x oder y Integer oder rationale Zahl.
0057 inline const cl_R operator* (const cl_LF& x, const cl_I& y)
0058 {
0059     extern const cl_R cl_LF_I_mul (const cl_LF&, const cl_I&);
0060     return cl_LF_I_mul(x,y);
0061 }
0062 inline const cl_R operator* (const cl_I& x, const cl_LF& y)
0063 {
0064     extern const cl_R cl_LF_I_mul (const cl_LF&, const cl_I&);
0065     return cl_LF_I_mul(y,x);
0066 }
0067 inline const cl_R operator* (const cl_LF& x, const cl_RA& y)
0068 {
0069     extern const cl_R cl_LF_RA_mul (const cl_LF&, const cl_RA&);
0070     return cl_LF_RA_mul(x,y);
0071 }
0072 inline const cl_R operator* (const cl_RA& x, const cl_LF& y)
0073 {
0074     extern const cl_R cl_LF_RA_mul (const cl_LF&, const cl_RA&);
0075     return cl_LF_RA_mul(y,x);
0076 }
0077 // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int * cl_LF' u.ä.):
0078 inline const cl_R operator* (const int x, const cl_LF& y)
0079     { return cl_I(x) * y; }
0080 inline const cl_R operator* (const unsigned int x, const cl_LF& y)
0081     { return cl_I(x) * y; }
0082 inline const cl_R operator* (const long x, const cl_LF& y)
0083     { return cl_I(x) * y; }
0084 inline const cl_R operator* (const unsigned long x, const cl_LF& y)
0085     { return cl_I(x) * y; }
0086 inline const cl_R operator* (const long long x, const cl_LF& y)
0087     { return cl_I(x) * y; }
0088 inline const cl_R operator* (const unsigned long long x, const cl_LF& y)
0089     { return cl_I(x) * y; }
0090 inline const cl_R operator* (const cl_LF& x, const int y)
0091     { return x * cl_I(y); }
0092 inline const cl_R operator* (const cl_LF& x, const unsigned int y)
0093     { return x * cl_I(y); }
0094 inline const cl_R operator* (const cl_LF& x, const long y)
0095     { return x * cl_I(y); }
0096 inline const cl_R operator* (const cl_LF& x, const unsigned long y)
0097     { return x * cl_I(y); }
0098 inline const cl_R operator* (const cl_LF& x, const long long y)
0099     { return x * cl_I(y); }
0100 inline const cl_R operator* (const cl_LF& x, const unsigned long long y)
0101     { return x * cl_I(y); }
0102 // Spezialfall x = y.
0103 // Liefert zu einem Long-Float x : (* x x), ein LF.
0104 extern const cl_LF square (const cl_LF& x);
0105 
0106 // Liefert zu zwei Long-Float x und y : (/ x y), ein LF.
0107 extern const cl_LF operator/ (const cl_LF& x, const cl_LF& y);
0108 // Spezialfall x oder y Integer oder rationale Zahl.
0109 inline const cl_LF operator/ (const cl_LF& x, const cl_I& y)
0110 {
0111     extern const cl_LF cl_LF_I_div (const cl_LF& x, const cl_I& y);
0112     return cl_LF_I_div(x,y);
0113 }
0114 inline const cl_R operator/ (const cl_I& x, const cl_LF& y)
0115 {
0116     extern const cl_R cl_I_LF_div (const cl_I& x, const cl_LF& y);
0117     return cl_I_LF_div(x,y);
0118 }
0119 inline const cl_LF operator/ (const cl_LF& x, const cl_RA& y)
0120 {
0121     extern const cl_LF cl_LF_RA_div (const cl_LF& x, const cl_RA& y);
0122     return cl_LF_RA_div(x,y);
0123 }
0124 inline const cl_R operator/ (const cl_RA& x, const cl_LF& y)
0125 {
0126     extern const cl_R cl_RA_LF_div (const cl_RA& x, const cl_LF& y);
0127     return cl_RA_LF_div(x,y);
0128 }
0129 // Dem C++-Compiler muß man nun auch das Folgende sagen:
0130 inline const cl_LF operator/ (const cl_LF& x, const int y)
0131     { return x / cl_I(y); }
0132 inline const cl_LF operator/ (const cl_LF& x, const unsigned int y)
0133     { return x / cl_I(y); }
0134 inline const cl_LF operator/ (const cl_LF& x, const long y)
0135     { return x / cl_I(y); }
0136 inline const cl_LF operator/ (const cl_LF& x, const unsigned long y)
0137     { return x / cl_I(y); }
0138 inline const cl_LF operator/ (const cl_LF& x, const long long y)
0139     { return x / cl_I(y); }
0140 inline const cl_LF operator/ (const cl_LF& x, const unsigned long long y)
0141     { return x / cl_I(y); }
0142 inline const cl_R operator/ (const int x, const cl_LF& y)
0143     { return cl_I(x) / y; }
0144 inline const cl_R operator/ (const unsigned int x, const cl_LF& y)
0145     { return cl_I(x) / y; }
0146 inline const cl_R operator/ (const long x, const cl_LF& y)
0147     { return cl_I(x) / y; }
0148 inline const cl_R operator/ (const unsigned long x, const cl_LF& y)
0149     { return cl_I(x) / y; }
0150 inline const cl_R operator/ (const long long x, const cl_LF& y)
0151     { return cl_I(x) / y; }
0152 inline const cl_R operator/ (const unsigned long long x, const cl_LF& y)
0153     { return cl_I(x) / y; }
0154 
0155 // Liefert zu einem Long-Float x>=0 : (sqrt x), ein LF.
0156 extern const cl_LF sqrt (const cl_LF& x);
0157 
0158 // recip(x) liefert (/ x), wo x ein Long-Float ist.
0159 extern const cl_LF recip (const cl_LF& x);
0160 
0161 // abs(x) liefert (abs x), wo x ein Long-Float ist.
0162 extern const cl_LF abs (const cl_LF& x);
0163 
0164 
0165 // (1+ x), wo x ein Long-Float ist.
0166 extern const cl_LF plus1 (const cl_LF& x);
0167 
0168 // (1- x), wo x ein Long-Float ist.
0169 extern const cl_LF minus1 (const cl_LF& x);
0170 
0171 
0172 // ffloor(x) liefert (ffloor x), wo x ein LF ist.
0173 extern const cl_LF ffloor (const cl_LF& x);
0174 
0175 // fceiling(x) liefert (fceiling x), wo x ein LF ist.
0176 extern const cl_LF fceiling (const cl_LF& x);
0177 
0178 // ftruncate(x) liefert (ftruncate x), wo x ein LF ist.
0179 extern const cl_LF ftruncate (const cl_LF& x);
0180 
0181 // fround(x) liefert (fround x), wo x ein LF ist.
0182 extern const cl_LF fround (const cl_LF& x);
0183 
0184 
0185 // Return type for frounding operators.
0186 // x / y  --> (q,r) with x = y*q+r.
0187 struct cl_LF_fdiv_t {
0188     cl_LF quotient;
0189     cl_LF remainder;
0190 // Constructor.
0191     cl_LF_fdiv_t () {}
0192     cl_LF_fdiv_t (const cl_LF& q, const cl_LF& r) : quotient(q), remainder(r) {}
0193 };
0194 
0195 // ffloor2(x) liefert (ffloor x), wo x ein LF ist.
0196 inline const cl_LF_fdiv_t ffloor2 (const cl_LF& x)
0197 {
0198     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0199     cl_LF q = ffloor(x);
0200     return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
0201 }
0202 
0203 // fceiling2(x) liefert (fceiling x), wo x ein LF ist.
0204 inline const cl_LF_fdiv_t fceiling2 (const cl_LF& x)
0205 {
0206     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0207     cl_LF q = fceiling(x);
0208     return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
0209 }
0210 
0211 // ftruncate2(x) liefert (ftruncate x), wo x ein LF ist.
0212 inline const cl_LF_fdiv_t ftruncate2 (const cl_LF& x)
0213 {
0214     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0215     cl_LF q = ftruncate(x);
0216     return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
0217 }
0218 
0219 // fround2(x) liefert (fround x), wo x ein LF ist.
0220 inline const cl_LF_fdiv_t fround2 (const cl_LF& x)
0221 {
0222     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0223     cl_LF q = fround(x);
0224     return cl_LF_fdiv_t(q,LF_LF_minus_LF(x,q));
0225 }
0226 
0227 
0228 // Return type for rounding operators.
0229 // x / y  --> (q,r) with x = y*q+r.
0230 struct cl_LF_div_t {
0231     cl_I quotient;
0232     cl_LF remainder;
0233 // Constructor.
0234     cl_LF_div_t () {}
0235     cl_LF_div_t (const cl_I& q, const cl_LF& r) : quotient(q), remainder(r) {}
0236 };
0237 
0238 // floor2(x) liefert (floor x), wo x ein LF ist.
0239 inline const cl_LF_div_t floor2 (const cl_LF& x)
0240 {
0241     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0242     extern const cl_I cl_LF_to_I (const cl_LF& x);
0243     cl_LF q = ffloor(x);
0244     return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
0245 }
0246 inline const cl_I floor1 (const cl_LF& x)
0247 {
0248     extern const cl_I cl_LF_to_I (const cl_LF& x);
0249     return cl_LF_to_I(ffloor(x));
0250 }
0251 
0252 // ceiling2(x) liefert (ceiling x), wo x ein LF ist.
0253 inline const cl_LF_div_t ceiling2 (const cl_LF& x)
0254 {
0255     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0256     extern const cl_I cl_LF_to_I (const cl_LF& x);
0257     cl_LF q = fceiling(x);
0258     return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
0259 }
0260 inline const cl_I ceiling1 (const cl_LF& x)
0261 {
0262     extern const cl_I cl_LF_to_I (const cl_LF& x);
0263     return cl_LF_to_I(fceiling(x));
0264 }
0265 
0266 // truncate2(x) liefert (truncate x), wo x ein LF ist.
0267 inline const cl_LF_div_t truncate2 (const cl_LF& x)
0268 {
0269     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0270     extern const cl_I cl_LF_to_I (const cl_LF& x);
0271     cl_LF q = ftruncate(x);
0272     return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
0273 }
0274 inline const cl_I truncate1 (const cl_LF& x)
0275 {
0276     extern const cl_I cl_LF_to_I (const cl_LF& x);
0277     return cl_LF_to_I(ftruncate(x));
0278 }
0279 
0280 // round2(x) liefert (round x), wo x ein LF ist.
0281 inline const cl_LF_div_t round2 (const cl_LF& x)
0282 {
0283     extern const cl_LF LF_LF_minus_LF (const cl_LF&, const cl_LF&);
0284     extern const cl_I cl_LF_to_I (const cl_LF& x);
0285     cl_LF q = fround(x);
0286     return cl_LF_div_t(cl_LF_to_I(q),LF_LF_minus_LF(x,q));
0287 }
0288 inline const cl_I round1 (const cl_LF& x)
0289 {
0290     extern const cl_I cl_LF_to_I (const cl_LF& x);
0291     return cl_LF_to_I(fround(x));
0292 }
0293 
0294 // floor2(x,y) liefert (floor x y).
0295 extern const cl_LF_div_t floor2 (const cl_LF& x, const cl_LF& y);
0296 inline const cl_I floor1 (const cl_LF& x, const cl_LF& y) { return floor1(x/y); }
0297 
0298 // ceiling2(x,y) liefert (ceiling x y).
0299 extern const cl_LF_div_t ceiling2 (const cl_LF& x, const cl_LF& y);
0300 inline const cl_I ceiling1 (const cl_LF& x, const cl_LF& y) { return ceiling1(x/y); }
0301 
0302 // truncate2(x,y) liefert (truncate x y).
0303 extern const cl_LF_div_t truncate2 (const cl_LF& x, const cl_LF& y);
0304 inline const cl_I truncate1 (const cl_LF& x, const cl_LF& y) { return truncate1(x/y); }
0305 
0306 // round2(x,y) liefert (round x y).
0307 extern const cl_LF_div_t round2 (const cl_LF& x, const cl_LF& y);
0308 inline const cl_I round1 (const cl_LF& x, const cl_LF& y) { return round1(x/y); }
0309 
0310 
0311 // cl_float(x,y) returns a long float if y is a long float.
0312 inline const cl_LF cl_float (const cl_F& x, const cl_LF& y)
0313 {
0314     extern const cl_F cl_float (const cl_F& x, const cl_F& y);
0315     return The(cl_LF)(cl_float(x,(const cl_F&)y));
0316 }
0317 inline const cl_LF cl_float (const cl_I& x, const cl_LF& y)
0318 {
0319     extern const cl_F cl_float (const cl_I& x, const cl_F& y);
0320     return The(cl_LF)(cl_float(x,(const cl_F&)y));
0321 }
0322 inline const cl_LF cl_float (const cl_RA& x, const cl_LF& y)
0323 {
0324     extern const cl_F cl_float (const cl_RA& x, const cl_F& y);
0325     return The(cl_LF)(cl_float(x,(const cl_F&)y));
0326 }
0327 inline const cl_LF cl_float (int x, const cl_LF& y)
0328     { return cl_float(cl_I(x),y); }
0329 inline const cl_LF cl_float (unsigned int x, const cl_LF& y)
0330     { return cl_float(cl_I(x),y); }
0331 
0332 
0333 // Return type for decode_float:
0334 struct decoded_lfloat {
0335     cl_LF mantissa;
0336     cl_I exponent;
0337     cl_LF sign;
0338 // Constructor.
0339     decoded_lfloat () {}
0340     decoded_lfloat (const cl_LF& m, const cl_I& e, const cl_LF& s) : mantissa(m), exponent(e), sign(s) {}
0341 };
0342 
0343 // decode_float(x) liefert zu einem Float x: (decode-float x).
0344 // x = 0.0 liefert (0.0, 0, 1.0).
0345 // x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
0346 extern const decoded_lfloat decode_float (const cl_LF& x);
0347 
0348 // float_exponent(x) liefert zu einem Float x:
0349 // den Exponenten von (decode-float x).
0350 // x = 0.0 liefert 0.
0351 // x = (-1)^s * 2^e * m liefert e.
0352 extern sintE float_exponent (const cl_LF& x);
0353 
0354 // float_radix(x) liefert (float-radix x), wo x ein Float ist.
0355 inline sintL float_radix (const cl_LF& x)
0356 {
0357     (void)x; // unused x
0358     return 2;
0359 }
0360 
0361 // float_sign(x) liefert (float-sign x), wo x ein Float ist.
0362 extern const cl_LF float_sign (const cl_LF& x);
0363 
0364 // float_digits(x) liefert (float-digits x), wo x ein Float ist.
0365 // < ergebnis: ein uintC >0
0366 extern uintC float_digits (const cl_LF& x);
0367 
0368 // float_precision(x) liefert (float-precision x), wo x ein Float ist.
0369 // < ergebnis: ein uintC >=0
0370 extern uintC float_precision (const cl_LF& x);
0371 
0372 
0373 // integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
0374 // x = 0.0 liefert (0, 0, 1).
0375 // x = (-1)^s * 2^e * m bei Float-Precision p liefert
0376 //   (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
0377 extern const cl_idecoded_float integer_decode_float (const cl_LF& x);
0378 
0379 
0380 // scale_float(x,delta) liefert x*2^delta, wo x ein LF ist.
0381 extern const cl_LF scale_float (const cl_LF& x, sintC delta);
0382 extern const cl_LF scale_float (const cl_LF& x, const cl_I& delta);
0383 
0384 
0385 // max(x,y) liefert (max x y), wo x und y Floats sind.
0386 extern const cl_LF max (const cl_LF& x, const cl_LF& y);
0387 
0388 // min(x,y) liefert (min x y), wo x und y Floats sind.
0389 extern const cl_LF min (const cl_LF& x, const cl_LF& y);
0390 
0391 // signum(x) liefert (signum x), wo x ein Float ist.
0392 extern const cl_LF signum (const cl_LF& x);
0393 
0394 
0395 // Konversion zu einem C "float".
0396 extern float float_approx (const cl_LF& x);
0397 
0398 // Konversion zu einem C "double".
0399 extern double double_approx (const cl_LF& x);
0400 
0401 
0402 // This could be optimized to use in-place operations.
0403 inline cl_LF& operator+= (cl_LF& x, const cl_LF& y) { return x = x + y; }
0404 inline cl_LF& operator++ /* prefix */ (cl_LF& x) { return x = plus1(x); }
0405 inline void operator++ /* postfix */ (cl_LF& x, int dummy) { (void)dummy; x = plus1(x); }
0406 inline cl_LF& operator-= (cl_LF& x, const cl_LF& y) { return x = x - y; }
0407 inline cl_LF& operator-- /* prefix */ (cl_LF& x) { return x = minus1(x); }
0408 inline void operator-- /* postfix */ (cl_LF& x, int dummy) { (void)dummy; x = minus1(x); }
0409 inline cl_LF& operator*= (cl_LF& x, const cl_LF& y) { return x = x * y; }
0410 inline cl_LF& operator/= (cl_LF& x, const cl_LF& y) { return x = x / y; }
0411 
0412 
0413 // Runtime typing support.
0414 extern cl_class cl_class_lfloat;
0415 
0416 
0417 // Debugging support.
0418 #ifdef CL_DEBUG
0419 extern int cl_LF_debug_module;
0420 CL_FORCE_LINK(cl_LF_debug_dummy, cl_LF_debug_module)
0421 #endif
0422 
0423 }  // namespace cln
0424 
0425 #endif /* _CL_LFLOAT_H */