Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Public single float operations.
0002 
0003 #ifndef _CL_FFLOAT_H
0004 #define _CL_FFLOAT_H
0005 
0006 #include "cln/number.h"
0007 #include "cln/ffloat_class.h"
0008 #include "cln/integer_class.h"
0009 #include "cln/float.h"
0010 
0011 namespace cln {
0012 
0013 CL_DEFINE_AS_CONVERSION(cl_FF)
0014 
0015 
0016 // Liefert zu einem Single-Float x : (- x), ein FF.
0017 extern const cl_FF operator- (const cl_FF& x);
0018 
0019 // compare(x,y) vergleicht zwei Single-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_FF& x, const cl_FF& y);
0022 
0023 // equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
0024 extern uint32 equal_hashcode (const cl_FF& x);
0025 
0026 inline bool operator== (const cl_FF& x, const cl_FF& y)
0027     { return compare(x,y)==0; }
0028 inline bool operator!= (const cl_FF& x, const cl_FF& y)
0029     { return compare(x,y)!=0; }
0030 inline bool operator<= (const cl_FF& x, const cl_FF& y)
0031     { return compare(x,y)<=0; }
0032 inline bool operator< (const cl_FF& x, const cl_FF& y)
0033     { return compare(x,y)<0; }
0034 inline bool operator>= (const cl_FF& x, const cl_FF& y)
0035     { return compare(x,y)>=0; }
0036 inline bool operator> (const cl_FF& x, const cl_FF& y)
0037     { return compare(x,y)>0; }
0038 
0039 // minusp(x) == (< x 0)
0040 extern bool minusp (const cl_FF& x);
0041 
0042 // zerop(x) stellt fest, ob ein Single-Float x = 0.0 ist.
0043 extern bool zerop (const cl_FF& x);
0044 
0045 // plusp(x) == (> x 0)
0046 extern bool plusp (const cl_FF& x);
0047 
0048 // Liefert zu zwei Single-Float x und y : (+ x y), ein FF.
0049 extern const cl_FF operator+ (const cl_FF& x, const cl_FF& y);
0050 // The C++ compiler may hesitate to do these conversions of its own:
0051 inline const cl_FF operator+ (const cl_FF& x, const float y)
0052     { return x + cl_FF(y); }
0053 inline const cl_FF operator+ (const float x, const cl_FF& y)
0054     { return cl_FF(x) + y; }
0055 
0056 // Liefert zu zwei Single-Float x und y : (- x y), ein FF.
0057 extern const cl_FF operator- (const cl_FF& x, const cl_FF& y);
0058 // The C++ compiler may hesitate to do these conversions of its own:
0059 inline const cl_FF operator- (const cl_FF& x, const float y)
0060     { return x - cl_FF(y); }
0061 inline const cl_FF operator- (const float x, const cl_FF& y)
0062     { return cl_FF(x) - y; }
0063 
0064 // Liefert zu zwei Single-Float x und y : (* x y), ein FF.
0065 extern const cl_FF operator* (const cl_FF& x, const cl_FF& y);
0066 // The C++ compiler may hesitate to do these conversions of its own:
0067 inline const cl_FF operator* (const cl_FF& x, const float y)
0068     { return x * cl_FF(y); }
0069 inline const cl_FF operator* (const float x, const cl_FF& y)
0070     { return cl_FF(x) * y; }
0071 
0072 // Liefert zu einem Single-Float x : (* x x), ein FF.
0073 inline const cl_FF square (const cl_FF& x) { return x*x; }
0074 
0075 // Liefert zu zwei Single-Float x und y : (/ x y), ein FF.
0076 extern const cl_FF operator/ (const cl_FF& x, const cl_FF& y);
0077 // The C++ compiler may hesitate to do these conversions of its own:
0078 inline const cl_FF operator/ (const cl_FF& x, const float y)
0079     { return x / cl_FF(y); }
0080 inline const cl_FF operator/ (const float x, const cl_FF& y)
0081     { return cl_FF(x) / y; }
0082 
0083 // Liefert zu einem Single-Float x>=0 : (sqrt x), ein FF.
0084 extern const cl_FF sqrt (const cl_FF& x);
0085 
0086 // recip(x) liefert (/ x), wo x ein Single-Float ist.
0087 extern const cl_FF recip (const cl_FF& x);
0088 
0089 // abs(x) liefert (abs x), wo x ein Single-Float ist.
0090 extern const cl_FF abs (const cl_FF& x);
0091 
0092 
0093 // (1+ x), wo x ein Single-Float ist.
0094 inline const cl_FF plus1 (const cl_FF& x)
0095 {
0096     extern const cl_FF cl_I_to_FF (const cl_I&);
0097     return x + cl_I_to_FF(cl_I(1));
0098 }
0099 
0100 // (1- x), wo x ein Single-Float ist.
0101 inline const cl_FF minus1 (const cl_FF& x)
0102 {
0103     extern const cl_FF cl_I_to_FF (const cl_I&);
0104     return x + cl_I_to_FF(cl_I(-1));
0105 }
0106 
0107 
0108 // ffloor(x) liefert (ffloor x), wo x ein FF ist.
0109 extern const cl_FF ffloor (const cl_FF& x);
0110 
0111 // fceiling(x) liefert (fceiling x), wo x ein FF ist.
0112 extern const cl_FF fceiling (const cl_FF& x);
0113 
0114 // ftruncate(x) liefert (ftruncate x), wo x ein FF ist.
0115 extern const cl_FF ftruncate (const cl_FF& x);
0116 
0117 // fround(x) liefert (fround x), wo x ein FF ist.
0118 extern const cl_FF fround (const cl_FF& x);
0119 
0120 
0121 // Return type for frounding operators.
0122 // x / y  --> (q,r) with x = y*q+r.
0123 struct cl_FF_fdiv_t {
0124     cl_FF quotient;
0125     cl_FF remainder;
0126 // Constructor.
0127     cl_FF_fdiv_t () {}
0128     cl_FF_fdiv_t (const cl_FF& q, const cl_FF& r) : quotient(q), remainder(r) {}
0129 };
0130 
0131 // ffloor2(x) liefert (ffloor x), wo x ein FF ist.
0132 inline const cl_FF_fdiv_t ffloor2 (const cl_FF& x)
0133     { cl_FF q = ffloor(x); return cl_FF_fdiv_t(q,x-q); }
0134 
0135 // fceiling2(x) liefert (fceiling x), wo x ein FF ist.
0136 inline const cl_FF_fdiv_t fceiling2 (const cl_FF& x)
0137     { cl_FF q = fceiling(x); return cl_FF_fdiv_t(q,x-q); }
0138 
0139 // ftruncate2(x) liefert (ftruncate x), wo x ein FF ist.
0140 inline const cl_FF_fdiv_t ftruncate2 (const cl_FF& x)
0141     { cl_FF q = ftruncate(x); return cl_FF_fdiv_t(q,x-q); }
0142 
0143 // fround2(x) liefert (fround x), wo x ein FF ist.
0144 inline const cl_FF_fdiv_t fround2 (const cl_FF& x)
0145     { cl_FF q = fround(x); return cl_FF_fdiv_t(q,x-q); }
0146 
0147 
0148 // Return type for rounding operators.
0149 // x / y  --> (q,r) with x = y*q+r.
0150 struct cl_FF_div_t {
0151     cl_I quotient;
0152     cl_FF remainder;
0153 // Constructor.
0154     cl_FF_div_t () {}
0155     cl_FF_div_t (const cl_I& q, const cl_FF& r) : quotient(q), remainder(r) {}
0156 };
0157 
0158 // floor2(x) liefert (floor x), wo x ein FF ist.
0159 inline const cl_FF_div_t floor2 (const cl_FF& x)
0160 {
0161     extern const cl_I cl_FF_to_I (const cl_FF& x);
0162     cl_FF q = ffloor(x);
0163     return cl_FF_div_t(cl_FF_to_I(q),x-q);
0164 }
0165 inline const cl_I floor1 (const cl_FF& x)
0166 {
0167     extern const cl_I cl_FF_to_I (const cl_FF& x);
0168     return cl_FF_to_I(ffloor(x));
0169 }
0170 
0171 // ceiling2(x) liefert (ceiling x), wo x ein FF ist.
0172 inline const cl_FF_div_t ceiling2 (const cl_FF& x)
0173 {
0174     extern const cl_I cl_FF_to_I (const cl_FF& x);
0175     cl_FF q = fceiling(x);
0176     return cl_FF_div_t(cl_FF_to_I(q),x-q);
0177 }
0178 inline const cl_I ceiling1 (const cl_FF& x)
0179 {
0180     extern const cl_I cl_FF_to_I (const cl_FF& x);
0181     return cl_FF_to_I(fceiling(x));
0182 }
0183 
0184 // truncate2(x) liefert (truncate x), wo x ein FF ist.
0185 inline const cl_FF_div_t truncate2 (const cl_FF& x)
0186 {
0187     extern const cl_I cl_FF_to_I (const cl_FF& x);
0188     cl_FF q = ftruncate(x);
0189     return cl_FF_div_t(cl_FF_to_I(q),x-q);
0190 }
0191 inline const cl_I truncate1 (const cl_FF& x)
0192 {
0193     extern const cl_I cl_FF_to_I (const cl_FF& x);
0194     return cl_FF_to_I(ftruncate(x));
0195 }
0196 
0197 // round2(x) liefert (round x), wo x ein FF ist.
0198 inline const cl_FF_div_t round2 (const cl_FF& x)
0199 {
0200     extern const cl_I cl_FF_to_I (const cl_FF& x);
0201     cl_FF q = fround(x);
0202     return cl_FF_div_t(cl_FF_to_I(q),x-q);
0203 }
0204 inline const cl_I round1 (const cl_FF& x)
0205 {
0206     extern const cl_I cl_FF_to_I (const cl_FF& x);
0207     return cl_FF_to_I(fround(x));
0208 }
0209 
0210 // floor2(x,y) liefert (floor x y).
0211 extern const cl_FF_div_t floor2 (const cl_FF& x, const cl_FF& y);
0212 inline const cl_I floor1 (const cl_FF& x, const cl_FF& y) { return floor1(x/y); }
0213 
0214 // ceiling2(x,y) liefert (ceiling x y).
0215 extern const cl_FF_div_t ceiling2 (const cl_FF& x, const cl_FF& y);
0216 inline const cl_I ceiling1 (const cl_FF& x, const cl_FF& y) { return ceiling1(x/y); }
0217 
0218 // truncate2(x,y) liefert (truncate x y).
0219 extern const cl_FF_div_t truncate2 (const cl_FF& x, const cl_FF& y);
0220 inline const cl_I truncate1 (const cl_FF& x, const cl_FF& y) { return truncate1(x/y); }
0221 
0222 // round2(x,y) liefert (round x y).
0223 extern const cl_FF_div_t round2 (const cl_FF& x, const cl_FF& y);
0224 inline const cl_I round1 (const cl_FF& x, const cl_FF& y) { return round1(x/y); }
0225 
0226 
0227 // Return type for decode_float:
0228 struct decoded_ffloat {
0229     cl_FF mantissa;
0230     cl_I exponent;
0231     cl_FF sign;
0232 // Constructor.
0233     decoded_ffloat () {}
0234     decoded_ffloat (const cl_FF& m, const cl_I& e, const cl_FF& s) : mantissa(m), exponent(e), sign(s) {}
0235 };
0236 
0237 // decode_float(x) liefert zu einem Float x: (decode-float x).
0238 // x = 0.0 liefert (0.0, 0, 1.0).
0239 // x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
0240 extern const decoded_ffloat decode_float (const cl_FF& x);
0241 
0242 // float_exponent(x) liefert zu einem Float x:
0243 // den Exponenten von (decode-float x).
0244 // x = 0.0 liefert 0.
0245 // x = (-1)^s * 2^e * m liefert e.
0246 extern sintE float_exponent (const cl_FF& x);
0247 
0248 // float_radix(x) liefert (float-radix x), wo x ein Float ist.
0249 inline sintL float_radix (const cl_FF& x)
0250 {
0251     (void)x; // unused x
0252     return 2;
0253 }
0254 
0255 // float_sign(x) liefert (float-sign x), wo x ein Float ist.
0256 extern const cl_FF float_sign (const cl_FF& x);
0257 
0258 // float_digits(x) liefert (float-digits x), wo x ein Float ist.
0259 // < ergebnis: ein uintC >0
0260 extern uintC float_digits (const cl_FF& x);
0261 
0262 // float_precision(x) liefert (float-precision x), wo x ein Float ist.
0263 // < ergebnis: ein uintC >=0
0264 extern uintC float_precision (const cl_FF& x);
0265 
0266 
0267 // integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
0268 // x = 0.0 liefert (0, 0, 1).
0269 // x = (-1)^s * 2^e * m bei Float-Precision p liefert
0270 //   (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
0271 extern const cl_idecoded_float integer_decode_float (const cl_FF& x);
0272 
0273 
0274 // scale_float(x,delta) liefert x*2^delta, wo x ein FF ist.
0275 extern const cl_FF scale_float (const cl_FF& x, sintC delta);
0276 extern const cl_FF scale_float (const cl_FF& x, const cl_I& delta);
0277 
0278 
0279 // max(x,y) liefert (max x y), wo x und y Floats sind.
0280 extern const cl_FF max (const cl_FF& x, const cl_FF& y);
0281 
0282 // min(x,y) liefert (min x y), wo x und y Floats sind.
0283 extern const cl_FF min (const cl_FF& x, const cl_FF& y);
0284 
0285 // signum(x) liefert (signum x), wo x ein Float ist.
0286 extern const cl_FF signum (const cl_FF& x);
0287 
0288 
0289 // Konversion zu einem C "float".
0290 extern float float_approx (const cl_FF& x);
0291 
0292 // Konversion zu einem C "double".
0293 extern double double_approx (const cl_FF& x);
0294 
0295 
0296 // This could be optimized to use in-place operations.
0297 inline cl_FF& operator+= (cl_FF& x, const cl_FF& y) { return x = x + y; }
0298 inline cl_FF& operator+= (cl_FF& x, const float y) { return x = x + y; }
0299 inline cl_FF& operator++ /* prefix */ (cl_FF& x) { return x = plus1(x); }
0300 inline void operator++ /* postfix */ (cl_FF& x, int dummy) { (void)dummy; x = plus1(x); }
0301 inline cl_FF& operator-= (cl_FF& x, const cl_FF& y) { return x = x - y; }
0302 inline cl_FF& operator-= (cl_FF& x, const float y) { return x = x - y; }
0303 inline cl_FF& operator-- /* prefix */ (cl_FF& x) { return x = minus1(x); }
0304 inline void operator-- /* postfix */ (cl_FF& x, int dummy) { (void)dummy; x = minus1(x); }
0305 inline cl_FF& operator*= (cl_FF& x, const cl_FF& y) { return x = x * y; }
0306 inline cl_FF& operator*= (cl_FF& x, const float y) { return x = x * y; }
0307 inline cl_FF& operator/= (cl_FF& x, const cl_FF& y) { return x = x / y; }
0308 inline cl_FF& operator/= (cl_FF& x, const float y) { return x = x / y; }
0309 
0310 
0311 /* */
0312 
0313 
0314 // Runtime typing support.
0315 extern cl_class cl_class_ffloat;
0316 #ifdef CL_WIDE_POINTERS
0317 CL_FORCE_LINK(cl_FF_classes_dummy, cl_class_ffloat)
0318 #endif
0319 
0320 
0321 // Debugging support.
0322 #ifdef CL_DEBUG
0323 extern int cl_FF_debug_module;
0324 CL_FORCE_LINK(cl_FF_debug_dummy, cl_FF_debug_module)
0325 #endif
0326 
0327 }  // namespace cln
0328 
0329 #endif /* _CL_FFLOAT_H */