Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Public float operations.
0002 
0003 #ifndef _CL_FLOAT_H
0004 #define _CL_FLOAT_H
0005 
0006 #include "cln/number.h"
0007 #include "cln/float_class.h"
0008 #include "cln/floatformat.h"
0009 #include "cln/random.h"
0010 #include "cln/integer_class.h"
0011 #include "cln/sfloat_class.h"
0012 #include "cln/ffloat_class.h"
0013 #include "cln/dfloat_class.h"
0014 #include "cln/lfloat_class.h"
0015 #include "cln/exception.h"
0016 
0017 namespace cln {
0018 
0019 CL_DEFINE_AS_CONVERSION(cl_F)
0020 
0021 
0022 // Return type for integer_decode_float:
0023 struct cl_idecoded_float {
0024     cl_I mantissa;
0025     cl_I exponent;
0026     cl_I sign;
0027 // Constructor.
0028     cl_idecoded_float () {}
0029     cl_idecoded_float (const cl_I& m, const cl_I& e, const cl_I& s) : mantissa(m), exponent(e), sign(s) {}
0030 };
0031 
0032 
0033 // zerop(x) testet, ob (= x 0).
0034 extern bool zerop (const cl_F& x);
0035 
0036 // minusp(x) testet, ob (< x 0).
0037 extern bool minusp (const cl_F& x);
0038 
0039 // plusp(x) testet, ob (> x 0).
0040 extern bool plusp (const cl_F& x);
0041 
0042 
0043 // cl_F_to_SF(x) wandelt ein Float x in ein Short-Float um und rundet dabei.
0044 extern const cl_SF cl_F_to_SF (const cl_F& x);
0045 
0046 // cl_F_to_FF(x) wandelt ein Float x in ein Single-Float um und rundet dabei.
0047 extern const cl_FF cl_F_to_FF (const cl_F& x);
0048 
0049 // cl_F_to_DF(x) wandelt ein Float x in ein Double-Float um und rundet dabei.
0050 extern const cl_DF cl_F_to_DF (const cl_F& x);
0051 
0052 // cl_F_to_LF(x,len) wandelt ein Float x in ein Long-Float mit len Digits um
0053 // und rundet dabei.
0054 // > uintC len: gewünschte Anzahl Digits, >=LF_minlen
0055 extern const cl_LF cl_F_to_LF (const cl_F& x, uintC len);
0056 
0057 
0058 // The default float format used when converting rational numbers to floats.
0059 extern float_format_t default_float_format;
0060 
0061 // Returns the smallest float format which guarantees at least n decimal digits
0062 // in the mantissa (after the decimal point).
0063 extern float_format_t float_format (uintE n);
0064 
0065 // cl_float(x,y) wandelt ein Float x in das Float-Format des Floats y um
0066 // und rundet dabei nötigenfalls.
0067 // > x,y: Floats
0068 // < ergebnis: (float x y)
0069 extern const cl_F cl_float (const cl_F& x, const cl_F& y);
0070 
0071 // cl_float(x,f) wandelt ein Float x in das Float-Format f um
0072 // und rundet dabei nötigenfalls.
0073 // > x: ein Float
0074 // > f: eine Float-Format-Spezifikation
0075 // < ergebnis: (float x f)
0076 extern const cl_F cl_float (const cl_F& x, float_format_t f);
0077 
0078 // cl_float(x) wandelt eine reelle Zahl x in ein Float um
0079 // und rundet dabei nötigenfalls.
0080 // > x: eine reelle Zahl
0081 // < ergebnis: (float x)
0082 // Abhängig von default_float_format.
0083 inline const cl_F cl_float (const cl_F& x) { return x; }
0084 
0085 // cl_float(x,y) wandelt ein Integer x in das Float-Format des Floats y um
0086 // und rundet dabei nötigenfalls.
0087 // > x: ein Integer
0088 // > y: ein Float
0089 // < ergebnis: (float x y)
0090 extern const cl_F cl_float (const cl_I& x, const cl_F& y);
0091 
0092 // cl_float(x,y) wandelt ein Integer x in das Float-Format f um
0093 // und rundet dabei nötigenfalls.
0094 // > x: ein Integer
0095 // > f: eine Float-Format-Spezifikation
0096 // < ergebnis: (float x f)
0097 extern const cl_F cl_float (const cl_I& x, float_format_t f);
0098 
0099 // cl_float(x) wandelt ein Integer x in ein Float um und rundet dabei.
0100 // > x: ein Integer
0101 // < ergebnis: (float x)
0102 // Abhängig von default_float_format.
0103 extern const cl_F cl_float (const cl_I& x);
0104 
0105 // cl_float(x,y) wandelt eine rationale Zahl x in das Float-Format des
0106 // Floats y um und rundet dabei nötigenfalls.
0107 // > x: eine rationale Zahl
0108 // > y: ein Float
0109 // < ergebnis: (float x y)
0110 extern const cl_F cl_float (const cl_RA& x, const cl_F& y);
0111 
0112 // cl_float(x,y) wandelt eine rationale Zahl x in das Float-Format f um
0113 // und rundet dabei nötigenfalls.
0114 // > x: eine rationale Zahl
0115 // > f: eine Float-Format-Spezifikation
0116 // < ergebnis: (float x f)
0117 extern const cl_F cl_float (const cl_RA& x, float_format_t f);
0118 
0119 // cl_float(x) wandelt eine rationale Zahl x in ein Float um und rundet dabei.
0120 // > x: eine rationale Zahl
0121 // < ergebnis: (float x)
0122 // Abhängig von default_float_format.
0123 extern const cl_F cl_float (const cl_RA& x);
0124 
0125 // The C++ compilers are not clever enough to guess this:
0126 inline const cl_F cl_float (int x, const cl_F& y)
0127     { return cl_float(cl_I(x),y); }
0128 inline const cl_F cl_float (unsigned int x, const cl_F& y)
0129     { return cl_float(cl_I(x),y); }
0130 inline const cl_F cl_float (int x, float_format_t y)
0131     { return cl_float(cl_I(x),y); }
0132 inline const cl_F cl_float (unsigned int x, float_format_t y)
0133     { return cl_float(cl_I(x),y); }
0134 inline const cl_F cl_float (int x)
0135     { return cl_float(cl_I(x)); }
0136 inline const cl_F cl_float (unsigned int x)
0137     { return cl_float(cl_I(x)); }
0138 // The C++ compilers could hardly guess the following:
0139 inline const cl_F cl_float (float x, const cl_F& y)
0140     { return cl_float(cl_FF(x),y); }
0141 inline const cl_F cl_float (double x, const cl_F& y)
0142     { return cl_float(cl_DF(x),y); }
0143 inline const cl_F cl_float (float x, float_format_t y)
0144     { return cl_float(cl_FF(x),y); }
0145 inline const cl_F cl_float (double x, float_format_t y)
0146     { return cl_float(cl_DF(x),y); }
0147 inline const cl_F cl_float (float x)
0148     { return cl_float(cl_FF(x)); }
0149 inline const cl_F cl_float (double x)
0150     { return cl_float(cl_DF(x)); }
0151 
0152 
0153 // Liefert (- x), wo x ein Float ist.
0154 extern const cl_F operator- (const cl_F& x);
0155 
0156 // Liefert (+ x y), wo x und y Floats sind.
0157 extern const cl_F operator+ (const cl_F& x, const cl_F& y);
0158 // The C++ compilers could hardly guess the following:
0159 inline const cl_F operator+ (const cl_RA& x, const cl_F& y)
0160     { return cl_float(x,y) + y; }
0161 inline const cl_F operator+ (const cl_I& x, const cl_F& y)
0162     { return cl_float(x,y) + y; }
0163 inline const cl_F operator+ (const cl_F& x, const cl_RA& y)
0164     { return x + cl_float(y,x); }
0165 inline const cl_F operator+ (const cl_F& x, const cl_I& y)
0166     { return x + cl_float(y,x); }
0167 // Dem C++-Compiler muß man nun auch das Folgende sagen:
0168 inline const cl_F operator+ (const int x, const cl_F& y)
0169     { return cl_I(x) + y; }
0170 inline const cl_F operator+ (const unsigned int x, const cl_F& y)
0171     { return cl_I(x) + y; }
0172 inline const cl_F operator+ (const long x, const cl_F& y)
0173     { return cl_I(x) + y; }
0174 inline const cl_F operator+ (const unsigned long x, const cl_F& y)
0175     { return cl_I(x) + y; }
0176 inline const cl_F operator+ (const long long x, const cl_F& y)
0177     { return cl_I(x) + y; }
0178 inline const cl_F operator+ (const unsigned long long x, const cl_F& y)
0179     { return cl_I(x) + y; }
0180 inline const cl_F operator+ (const float x, const cl_F& y)
0181     { return cl_F(x) + y; }
0182 inline const cl_F operator+ (const double x, const cl_F& y)
0183     { return cl_F(x) + y; }
0184 inline const cl_F operator+ (const cl_F& x, const int y)
0185     { return x + cl_I(y); }
0186 inline const cl_F operator+ (const cl_F& x, const unsigned int y)
0187     { return x + cl_I(y); }
0188 inline const cl_F operator+ (const cl_F& x, const long y)
0189     { return x + cl_I(y); }
0190 inline const cl_F operator+ (const cl_F& x, const unsigned long y)
0191     { return x + cl_I(y); }
0192 inline const cl_F operator+ (const cl_F& x, const long long y)
0193     { return x + cl_I(y); }
0194 inline const cl_F operator+ (const cl_F& x, const unsigned long long y)
0195     { return x + cl_I(y); }
0196 inline const cl_F operator+ (const cl_F& x, const float y)
0197     { return x + cl_F(y); }
0198 inline const cl_F operator+ (const cl_F& x, const double y)
0199     { return x + cl_F(y); }
0200 
0201 // Liefert (- x y), wo x und y Floats sind.
0202 extern const cl_F operator- (const cl_F& x, const cl_F& y);
0203 // The C++ compilers could hardly guess the following:
0204 inline const cl_F operator- (const cl_RA& x, const cl_F& y)
0205     { return cl_float(x,y) - y; }
0206 inline const cl_F operator- (const cl_I& x, const cl_F& y)
0207     { return cl_float(x,y) - y; }
0208 inline const cl_F operator- (const cl_F& x, const cl_RA& y)
0209     { return x - cl_float(y,x); }
0210 inline const cl_F operator- (const cl_F& x, const cl_I& y)
0211     { return x - cl_float(y,x); }
0212 // Dem C++-Compiler muß man nun auch das Folgende sagen:
0213 inline const cl_F operator- (const int x, const cl_F& y)
0214     { return cl_I(x) - y; }
0215 inline const cl_F operator- (const unsigned int x, const cl_F& y)
0216     { return cl_I(x) - y; }
0217 inline const cl_F operator- (const long x, const cl_F& y)
0218     { return cl_I(x) - y; }
0219 inline const cl_F operator- (const unsigned long x, const cl_F& y)
0220     { return cl_I(x) - y; }
0221 inline const cl_F operator- (const long long x, const cl_F& y)
0222     { return cl_I(x) - y; }
0223 inline const cl_F operator- (const unsigned long long x, const cl_F& y)
0224     { return cl_I(x) - y; }
0225 inline const cl_F operator- (const float x, const cl_F& y)
0226     { return cl_F(x) - y; }
0227 inline const cl_F operator- (const double x, const cl_F& y)
0228     { return cl_F(x) - y; }
0229 inline const cl_F operator- (const cl_F& x, const int y)
0230     { return x - cl_I(y); }
0231 inline const cl_F operator- (const cl_F& x, const unsigned int y)
0232     { return x - cl_I(y); }
0233 inline const cl_F operator- (const cl_F& x, const long y)
0234     { return x - cl_I(y); }
0235 inline const cl_F operator- (const cl_F& x, const unsigned long y)
0236     { return x - cl_I(y); }
0237 inline const cl_F operator- (const cl_F& x, const long long y)
0238     { return x - cl_I(y); }
0239 inline const cl_F operator- (const cl_F& x, const unsigned long long y)
0240     { return x - cl_I(y); }
0241 inline const cl_F operator- (const cl_F& x, const float y)
0242     { return x - cl_F(y); }
0243 inline const cl_F operator- (const cl_F& x, const double y)
0244     { return x - cl_F(y); }
0245 
0246 // Liefert (* x y), wo x und y Floats sind.
0247 extern const cl_F operator* (const cl_F& x, const cl_F& y);
0248 // Spezialfall x oder y Integer oder rationale Zahl.
0249 inline const cl_R operator* (const cl_F& x, const cl_I& y)
0250 {
0251     extern const cl_R cl_F_I_mul (const cl_F&, const cl_I&);
0252     return cl_F_I_mul(x,y);
0253 }
0254 inline const cl_R operator* (const cl_I& x, const cl_F& y)
0255 {
0256     extern const cl_R cl_F_I_mul (const cl_F&, const cl_I&);
0257     return cl_F_I_mul(y,x);
0258 }
0259 inline const cl_R operator* (const cl_F& x, const cl_RA& y)
0260 {
0261     extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
0262     return cl_F_RA_mul(x,y);
0263 }
0264 inline const cl_R operator* (const cl_RA& x, const cl_F& y)
0265 {
0266     extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
0267     return cl_F_RA_mul(y,x);
0268 }
0269 // Dem C++-Compiler muß man nun auch das Folgende sagen:
0270 inline const cl_R operator* (const int x, const cl_F& y)
0271     { return cl_I(x) * y; }
0272 inline const cl_R operator* (const unsigned int x, const cl_F& y)
0273     { return cl_I(x) * y; }
0274 inline const cl_R operator* (const long x, const cl_F& y)
0275     { return cl_I(x) * y; }
0276 inline const cl_R operator* (const unsigned long x, const cl_F& y)
0277     { return cl_I(x) * y; }
0278 inline const cl_R operator* (const long long x, const cl_F& y)
0279     { return cl_I(x) * y; }
0280 inline const cl_R operator* (const unsigned long long x, const cl_F& y)
0281     { return cl_I(x) * y; }
0282 inline const cl_F operator* (const float x, const cl_F& y)
0283     { return cl_F(x) * y; }
0284 inline const cl_F operator* (const double x, const cl_F& y)
0285     { return cl_F(x) * y; }
0286 inline const cl_R operator* (const cl_F& x, const int y)
0287     { return x * cl_I(y); }
0288 inline const cl_R operator* (const cl_F& x, const unsigned int y)
0289     { return x * cl_I(y); }
0290 inline const cl_R operator* (const cl_F& x, const long y)
0291     { return x * cl_I(y); }
0292 inline const cl_R operator* (const cl_F& x, const unsigned long y)
0293     { return x * cl_I(y); }
0294 inline const cl_R operator* (const cl_F& x, const long long y)
0295     { return x * cl_I(y); }
0296 inline const cl_R operator* (const cl_F& x, const unsigned long long y)
0297     { return x * cl_I(y); }
0298 inline const cl_F operator* (const cl_F& x, const float y)
0299     { return x * cl_F(y); }
0300 inline const cl_F operator* (const cl_F& x, const double y)
0301     { return x * cl_F(y); }
0302 
0303 // Liefert (* x x), wo x ein Float ist.
0304 extern const cl_F square (const cl_F& x);
0305 
0306 // Liefert (/ x y), wo x und y Floats sind.
0307 extern const cl_F operator/ (const cl_F& x, const cl_F& y);
0308 // Liefert (/ x y), wo x und y ein Float und eine rationale Zahl sind.
0309 extern const cl_F operator/ (const cl_F& x, const cl_RA& y);
0310 extern const cl_F operator/ (const cl_F& x, const cl_I& y);
0311 extern const cl_R operator/ (const cl_RA& x, const cl_F& y);
0312 extern const cl_R operator/ (const cl_I& x, const cl_F& y);
0313 // The C++ compilers could hardly guess the following:
0314 inline const cl_F operator/ (const cl_F& x, const int y)
0315     { return x / cl_I(y); }
0316 inline const cl_F operator/ (const cl_F& x, const unsigned int y)
0317     { return x / cl_I(y); }
0318 inline const cl_F operator/ (const cl_F& x, const long y)
0319     { return x / cl_I(y); }
0320 inline const cl_F operator/ (const cl_F& x, const unsigned long y)
0321     { return x / cl_I(y); }
0322 inline const cl_F operator/ (const cl_F& x, const long long y)
0323     { return x / cl_I(y); }
0324 inline const cl_F operator/ (const cl_F& x, const unsigned long long y)
0325     { return x / cl_I(y); }
0326 inline const cl_F operator/ (const cl_F& x, const float y)
0327     { return x / cl_F(y); }
0328 inline const cl_F operator/ (const cl_F& x, const double y)
0329     { return x / cl_F(y); }
0330 inline const cl_R operator/ (const int x, const cl_F& y)
0331     { return cl_I(x) / y; }
0332 inline const cl_R operator/ (const unsigned int x, const cl_F& y)
0333     { return cl_I(x) / y; }
0334 inline const cl_R operator/ (const long x, const cl_F& y)
0335     { return cl_I(x) / y; }
0336 inline const cl_R operator/ (const unsigned long x, const cl_F& y)
0337     { return cl_I(x) / y; }
0338 inline const cl_R operator/ (const long long x, const cl_F& y)
0339     { return cl_I(x) / y; }
0340 inline const cl_R operator/ (const unsigned long long x, const cl_F& y)
0341     { return cl_I(x) / y; }
0342 inline const cl_F operator/ (const float x, const cl_F& y)
0343     { return cl_F(x) / y; }
0344 inline const cl_F operator/ (const double x, const cl_F& y)
0345     { return cl_F(x) / y; }
0346 
0347 // Liefert (abs x), wo x ein Float ist.
0348 extern const cl_F abs (const cl_F& x);
0349 
0350 // Liefert zu einem Float x>=0 : (sqrt x), ein Float.
0351 extern const cl_F sqrt (const cl_F& x);
0352 
0353 // recip(x) liefert (/ x), wo x ein Float ist.
0354 extern const cl_F recip (const cl_F& x);
0355 
0356 // (1+ x), wo x ein Float ist.
0357 inline const cl_F plus1 (const cl_F& x) // { return x + cl_I(1); }
0358 {
0359     return x + cl_float(1,x);
0360 }
0361 
0362 // (1- x), wo x ein Float ist.
0363 inline const cl_F minus1 (const cl_F& x) // { return x + cl_I(-1); }
0364 {
0365     return x + cl_float(-1,x);
0366 }
0367 
0368 // compare(x,y) vergleicht zwei Floats x und y.
0369 // Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
0370 extern cl_signean compare (const cl_F& x, const cl_F& y);
0371 
0372 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
0373 extern uint32 equal_hashcode (const cl_F& x);
0374 
0375 inline bool operator== (const cl_F& x, const cl_F& y)
0376     { return compare(x,y)==0; }
0377 inline bool operator!= (const cl_F& x, const cl_F& y)
0378     { return compare(x,y)!=0; }
0379 inline bool operator<= (const cl_F& x, const cl_F& y)
0380     { return compare(x,y)<=0; }
0381 inline bool operator< (const cl_F& x, const cl_F& y)
0382     { return compare(x,y)<0; }
0383 inline bool operator>= (const cl_F& x, const cl_F& y)
0384     { return compare(x,y)>=0; }
0385 inline bool operator> (const cl_F& x, const cl_F& y)
0386     { return compare(x,y)>0; }
0387 
0388 
0389 // ffloor(x) liefert (ffloor x), wo x ein Float ist.
0390 extern const cl_F ffloor (const cl_F& x);
0391 
0392 // fceiling(x) liefert (fceiling x), wo x ein Float ist.
0393 extern const cl_F fceiling (const cl_F& x);
0394 
0395 // ftruncate(x) liefert (ftruncate x), wo x ein Float ist.
0396 extern const cl_F ftruncate (const cl_F& x);
0397 
0398 // fround(x) liefert (fround x), wo x ein Float ist.
0399 extern const cl_F fround (const cl_F& x);
0400 
0401 
0402 // Return type for frounding operators.
0403 // x / y  --> (q,r) with x = y*q+r.
0404 struct cl_F_fdiv_t {
0405     cl_F quotient;
0406     cl_F remainder;
0407 // Constructor.
0408     cl_F_fdiv_t () {}
0409     cl_F_fdiv_t (const cl_F& q, const cl_F& r) : quotient(q), remainder(r) {}
0410 };
0411 
0412 // ffloor2(x) liefert (ffloor x), wo x ein F ist.
0413 extern const cl_F_fdiv_t ffloor2 (const cl_F& x);
0414 
0415 // fceiling2(x) liefert (fceiling x), wo x ein F ist.
0416 extern const cl_F_fdiv_t fceiling2 (const cl_F& x);
0417 
0418 // ftruncate2(x) liefert (ftruncate x), wo x ein F ist.
0419 extern const cl_F_fdiv_t ftruncate2 (const cl_F& x);
0420 
0421 // fround2(x) liefert (fround x), wo x ein F ist.
0422 extern const cl_F_fdiv_t fround2 (const cl_F& x);
0423 
0424 
0425 // Return type for rounding operators.
0426 // x / y  --> (q,r) with x = y*q+r.
0427 struct cl_F_div_t {
0428     cl_I quotient;
0429     cl_F remainder;
0430 // Constructor.
0431     cl_F_div_t () {}
0432     cl_F_div_t (const cl_I& q, const cl_F& r) : quotient(q), remainder(r) {}
0433 };
0434 
0435 // floor2(x) liefert (floor x), wo x ein F ist.
0436 extern const cl_F_div_t floor2 (const cl_F& x);
0437 extern const cl_I floor1 (const cl_F& x);
0438 
0439 // ceiling2(x) liefert (ceiling x), wo x ein F ist.
0440 extern const cl_F_div_t ceiling2 (const cl_F& x);
0441 extern const cl_I ceiling1 (const cl_F& x);
0442 
0443 // truncate2(x) liefert (truncate x), wo x ein F ist.
0444 extern const cl_F_div_t truncate2 (const cl_F& x);
0445 extern const cl_I truncate1 (const cl_F& x);
0446 
0447 // round2(x) liefert (round x), wo x ein F ist.
0448 extern const cl_F_div_t round2 (const cl_F& x);
0449 extern const cl_I round1 (const cl_F& x);
0450 
0451 // floor2(x,y) liefert (floor x y), wo x und y Floats sind.
0452 extern const cl_F_div_t floor2 (const cl_F& x, const cl_F& y);
0453 inline const cl_I floor1 (const cl_F& x, const cl_F& y) { return floor1(x/y); }
0454 
0455 // ceiling2(x,y) liefert (ceiling x y), wo x und y Floats sind.
0456 extern const cl_F_div_t ceiling2 (const cl_F& x, const cl_F& y);
0457 inline const cl_I ceiling1 (const cl_F& x, const cl_F& y) { return ceiling1(x/y); }
0458 
0459 // truncate2(x,y) liefert (truncate x y), wo x und y Floats sind.
0460 extern const cl_F_div_t truncate2 (const cl_F& x, const cl_F& y);
0461 inline const cl_I truncate1 (const cl_F& x, const cl_F& y) { return truncate1(x/y); }
0462 
0463 // round2(x,y) liefert (round x y), wo x und y Floats sind.
0464 extern const cl_F_div_t round2 (const cl_F& x, const cl_F& y);
0465 inline const cl_I round1 (const cl_F& x, const cl_F& y) { return round1(x/y); }
0466 
0467 
0468 // Return type for decode_float:
0469 struct decoded_float {
0470     cl_F mantissa;
0471     cl_I exponent;
0472     cl_F sign;
0473 // Constructor.
0474     decoded_float () {}
0475     decoded_float (const cl_F& m, const cl_I& e, const cl_F& s) : mantissa(m), exponent(e), sign(s) {}
0476 };
0477 
0478 // decode_float(x) liefert zu einem Float x: (decode-float x).
0479 // x = 0.0 liefert (0.0, 0, 1.0).
0480 // x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
0481 extern const decoded_float decode_float (const cl_F& x);
0482 
0483 // float_exponent(x) liefert zu einem Float x:
0484 // den Exponenten von (decode-float x).
0485 // x = 0.0 liefert 0.
0486 // x = (-1)^s * 2^e * m liefert e.
0487 extern sintE float_exponent (const cl_F& x);
0488 
0489 // float_radix(x) liefert (float-radix x), wo x ein Float ist.
0490 inline sintL float_radix (const cl_F& x)
0491 {
0492     (void)x; // unused x
0493     return 2;
0494 }
0495 
0496 // float_sign(x) liefert (float-sign x), wo x ein Float ist.
0497 extern const cl_F float_sign (const cl_F& x);
0498 
0499 // float_sign(x,y) liefert (float-sign x y), wo x und y Floats sind.
0500 extern const cl_F float_sign (const cl_F& x, const cl_F& y);
0501 
0502 // float_digits(x) liefert (float-digits x), wo x ein Float ist.
0503 // < ergebnis: ein uintC >0
0504 extern uintC float_digits (const cl_F& x);
0505 
0506 // float_precision(x) liefert (float-precision x), wo x ein Float ist.
0507 // < ergebnis: ein uintC >=0
0508 extern uintC float_precision (const cl_F& x);
0509 
0510 // Returns the floating point format of a float.
0511 inline float_format_t float_format (const cl_F& x)
0512     { return (float_format_t) float_digits(x); }
0513 
0514 
0515 // integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
0516 // x = 0.0 liefert (0, 0, 1).
0517 // x = (-1)^s * 2^e * m bei Float-Precision p liefert
0518 //   (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
0519 extern const cl_idecoded_float integer_decode_float (const cl_F& x);
0520 
0521 
0522 // rational(x) liefert (rational x), wo x ein Float ist.
0523 extern const cl_RA rational (const cl_F& x);
0524 
0525 
0526 // scale_float(x,delta) liefert x*2^delta, wo x ein Float ist.
0527 extern const cl_F scale_float (const cl_F& x, sintC delta);
0528 extern const cl_F scale_float (const cl_F& x, const cl_I& delta);
0529 
0530 
0531 // max(x,y) liefert (max x y), wo x und y Floats sind.
0532 extern const cl_F max (const cl_F& x, const cl_F& y);
0533 
0534 // min(x,y) liefert (min x y), wo x und y Floats sind.
0535 extern const cl_F min (const cl_F& x, const cl_F& y);
0536 
0537 // signum(x) liefert (signum x), wo x ein Float ist.
0538 extern const cl_F signum (const cl_F& x);
0539 
0540 
0541 // Returns the largest (most positive) floating point number in float format f.
0542 extern const cl_F most_positive_float (float_format_t f);
0543 
0544 // Returns the smallest (most negative) floating point number in float format f.
0545 extern const cl_F most_negative_float (float_format_t f);
0546 
0547 // Returns the least positive floating point number (i.e. > 0 but closest to 0)
0548 // in float format f.
0549 extern const cl_F least_positive_float (float_format_t f);
0550 
0551 // Returns the least negative floating point number (i.e. < 0 but closest to 0)
0552 // in float format f.
0553 extern const cl_F least_negative_float (float_format_t f);
0554 
0555 // Returns the smallest floating point number e > 0 such that 1+e != 1.
0556 extern const cl_F float_epsilon (float_format_t f);
0557 
0558 // Returns the smallest floating point number e > 0 such that 1-e != 1.
0559 extern const cl_F float_negative_epsilon (float_format_t f);
0560 
0561 
0562 // Konversion zu einem C "float".
0563 extern float float_approx (const cl_F& x);
0564 
0565 // Konversion zu einem C "double".
0566 extern double double_approx (const cl_F& x);
0567 
0568 
0569 // Transcendental functions
0570 
0571 
0572 // pi(y) liefert die Zahl pi im selben Float-Format wie y.
0573 // > y: ein Float
0574 extern const cl_F pi (const cl_F& y);
0575 
0576 // pi(y) liefert die Zahl pi im Float-Format f.
0577 // > f: eine Float-Format-Spezifikation
0578 extern const cl_F pi (float_format_t f);
0579 
0580 // pi() liefert die Zahl pi im Default-Float-Format.
0581 extern const cl_F pi (void);
0582 
0583 
0584 // sin(x) liefert den Sinus (sin x) eines Float x.
0585 extern const cl_F sin (const cl_F& x);
0586 
0587 // cos(x) liefert den Cosinus (cos x) eines Float x.
0588 extern const cl_F cos (const cl_F& x);
0589 
0590 // Return type for cos_sin():
0591 struct cos_sin_t {
0592     cl_R cos;
0593     cl_R sin;
0594 // Constructor:
0595     cos_sin_t () {}
0596     cos_sin_t (const cl_R& u, const cl_R& v) : cos (u), sin (v) {}
0597 };
0598 
0599 // cos_sin(x) liefert ((cos x),(sin x)), beide Werte.
0600 extern const cos_sin_t cos_sin (const cl_F& x);
0601 
0602 // tan(x) liefert den Tangens (tan x) eines Float x.
0603 extern const cl_F tan (const cl_F& x);
0604 
0605 
0606 // exp1(y) liefert die Zahl e = exp(1) im selben Float-Format wie y.
0607 // > y: ein Float
0608 extern const cl_F exp1 (const cl_F& y);
0609 
0610 // exp1(y) liefert die Zahl e = exp(1) im Float-Format f.
0611 // > f: eine Float-Format-Spezifikation
0612 extern const cl_F exp1 (float_format_t f);
0613 
0614 // exp1() liefert die Zahl e = exp(1) im Default-Float-Format.
0615 extern const cl_F exp1 (void);
0616 
0617 
0618 // ln(x) liefert zu einem Float x>0 die Zahl ln(x).
0619 extern const cl_F ln (const cl_F& x);
0620 // Spezialfall: x Long-Float -> Ergebnis Long-Float
0621 inline const cl_LF ln (const cl_LF& x) { return The(cl_LF)(ln(The(cl_F)(x))); }
0622 
0623 // exp(x) liefert zu einem Float x die Zahl exp(x).
0624 extern const cl_F exp (const cl_F& x);
0625 
0626 // sinh(x) liefert zu einem Float x die Zahl sinh(x).
0627 extern const cl_F sinh (const cl_F& x);
0628 
0629 // cosh(x) liefert zu einem Float x die Zahl cosh(x).
0630 extern const cl_F cosh (const cl_F& x);
0631 
0632 // Return type for cosh_sinh():
0633 struct cosh_sinh_t {
0634     cl_R cosh;
0635     cl_R sinh;
0636 // Constructor:
0637     cosh_sinh_t () {}
0638     cosh_sinh_t (const cl_R& u, const cl_R& v) : cosh (u), sinh (v) {}
0639 };
0640 
0641 // cosh_sinh(x) liefert ((cosh x),(sinh x)), beide Werte.
0642 extern const cosh_sinh_t cosh_sinh (const cl_F& x);
0643 
0644 // tanh(x) liefert zu einem Float x die Zahl tanh(x).
0645 extern const cl_F tanh (const cl_F& x);
0646 
0647 
0648 // eulerconst(y) liefert die Eulersche Konstante
0649 // im selben Float-Format wie y.
0650 // > y: ein Float
0651 extern const cl_F eulerconst (const cl_F& y);
0652 
0653 // eulerconst(y) liefert die Eulersche Konstante im Float-Format f.
0654 // > f: eine Float-Format-Spezifikation
0655 extern const cl_F eulerconst (float_format_t f);
0656 
0657 // eulerconst() liefert die Eulersche Konstante im Default-Float-Format.
0658 extern const cl_F eulerconst (void);
0659 
0660 // catalanconst(y) liefert die Catalansche Konstante
0661 // im selben Float-Format wie y.
0662 // > y: ein Float
0663 extern const cl_F catalanconst (const cl_F& y);
0664 
0665 // catalanconst(y) liefert die Catalansche Konstante im Float-Format f.
0666 // > f: eine Float-Format-Spezifikation
0667 extern const cl_F catalanconst (float_format_t f);
0668 
0669 // catalanconst() liefert die Catalansche Konstante im Default-Float-Format.
0670 extern const cl_F catalanconst (void);
0671 
0672 // zeta(s) returns the Riemann zeta function at s>1.
0673 extern const cl_F zeta (int s, const cl_F& y);
0674 extern const cl_F zeta (int s, float_format_t f);
0675 extern const cl_F zeta (int s);
0676 
0677 
0678 // random_F(randomstate,n) liefert zu einem Float n>0 ein zufälliges
0679 // Float x mit 0 <= x < n.
0680 // > randomstate: ein Random-State, wird verändert
0681 extern const cl_F random_F (random_state& randomstate, const cl_F& n);
0682 
0683 inline const cl_F random_F (const cl_F& n)
0684     { return random_F(default_random_state,n); }
0685 
0686 
0687 // This could be optimized to use in-place operations.
0688 inline cl_F& operator+= (cl_F& x, const cl_F& y) { return x = x + y; }
0689 inline cl_F& operator+= (cl_F& x, const float y) { return x = x + y; }
0690 inline cl_F& operator+= (cl_F& x, const double y) { return x = x + y; }
0691 inline cl_F& operator++ /* prefix */ (cl_F& x) { return x = plus1(x); }
0692 inline void operator++ /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = plus1(x); }
0693 inline cl_F& operator-= (cl_F& x, const cl_F& y) { return x = x - y; }
0694 inline cl_F& operator-= (cl_F& x, const float y) { return x = x - y; }
0695 inline cl_F& operator-= (cl_F& x, const double y) { return x = x - y; }
0696 inline cl_F& operator-- /* prefix */ (cl_F& x) { return x = minus1(x); }
0697 inline void operator-- /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = minus1(x); }
0698 inline cl_F& operator*= (cl_F& x, const cl_F& y) { return x = x * y; }
0699 inline cl_F& operator*= (cl_F& x, const float y) { return x = x * y; }
0700 inline cl_F& operator*= (cl_F& x, const double y) { return x = x * y; }
0701 inline cl_F& operator/= (cl_F& x, const cl_F& y) { return x = x / y; }
0702 inline cl_F& operator/= (cl_F& x, const float y) { return x = x / y; }
0703 inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; }
0704 
0705 // Thrown when a floating-point exception occurs.
0706 class floating_point_exception : public runtime_exception {
0707 public:
0708     explicit floating_point_exception(const std::string & what)
0709         : runtime_exception(what) {}
0710 };
0711 
0712 // Thrown when NaN occurs.
0713 class floating_point_nan_exception : public floating_point_exception {
0714 public:
0715     floating_point_nan_exception();
0716 };
0717 
0718 // Thrown when overflow occurs.
0719 class floating_point_overflow_exception : public floating_point_exception {
0720 public:
0721     floating_point_overflow_exception();
0722 };
0723 
0724 // Thrown when underflow occurs.
0725 class floating_point_underflow_exception : public floating_point_exception {
0726 public:
0727     floating_point_underflow_exception();
0728 };
0729 
0730 
0731 
0732 
0733 // If this is true, floating point underflow returns zero instead of throwing an exception.
0734 extern bool cl_inhibit_floating_point_underflow;
0735 
0736 }  // namespace cln
0737 
0738 #endif /* _CL_FLOAT_H */