Back to home page

EIC code displayed by LXR

 
 

    


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

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