File indexing completed on 2026-05-19 08:08:31
0001
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
0017 extern const cl_LF operator- (const cl_LF& x);
0018
0019
0020
0021 extern cl_signean compare (const cl_LF& x, const cl_LF& y);
0022
0023
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
0040 extern bool minusp (const cl_LF& x);
0041
0042
0043 extern bool zerop (const cl_LF& x);
0044
0045
0046 extern bool plusp (const cl_LF& x);
0047
0048
0049 extern const cl_LF operator+ (const cl_LF& x, const cl_LF& y);
0050
0051
0052 extern const cl_LF operator- (const cl_LF& x, const cl_LF& y);
0053
0054
0055 extern const cl_LF operator* (const cl_LF& x, const cl_LF& y);
0056
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
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
0103
0104 extern const cl_LF square (const cl_LF& x);
0105
0106
0107 extern const cl_LF operator/ (const cl_LF& x, const cl_LF& y);
0108
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
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
0156 extern const cl_LF sqrt (const cl_LF& x);
0157
0158
0159 extern const cl_LF recip (const cl_LF& x);
0160
0161
0162 extern const cl_LF abs (const cl_LF& x);
0163
0164
0165
0166 extern const cl_LF plus1 (const cl_LF& x);
0167
0168
0169 extern const cl_LF minus1 (const cl_LF& x);
0170
0171
0172
0173 extern const cl_LF ffloor (const cl_LF& x);
0174
0175
0176 extern const cl_LF fceiling (const cl_LF& x);
0177
0178
0179 extern const cl_LF ftruncate (const cl_LF& x);
0180
0181
0182 extern const cl_LF fround (const cl_LF& x);
0183
0184
0185
0186
0187 struct cl_LF_fdiv_t {
0188 cl_LF quotient;
0189 cl_LF remainder;
0190
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
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
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
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
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
0229
0230 struct cl_LF_div_t {
0231 cl_I quotient;
0232 cl_LF remainder;
0233
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
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
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
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
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
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
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
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
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
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
0334 struct decoded_lfloat {
0335 cl_LF mantissa;
0336 cl_I exponent;
0337 cl_LF sign;
0338
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
0344
0345
0346 extern const decoded_lfloat decode_float (const cl_LF& x);
0347
0348
0349
0350
0351
0352 extern sintE float_exponent (const cl_LF& x);
0353
0354
0355 inline sintL float_radix (const cl_LF& x)
0356 {
0357 (void)x;
0358 return 2;
0359 }
0360
0361
0362 extern const cl_LF float_sign (const cl_LF& x);
0363
0364
0365
0366 extern uintC float_digits (const cl_LF& x);
0367
0368
0369
0370 extern uintC float_precision (const cl_LF& x);
0371
0372
0373
0374
0375
0376
0377 extern const cl_idecoded_float integer_decode_float (const cl_LF& x);
0378
0379
0380
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
0386 extern const cl_LF max (const cl_LF& x, const cl_LF& y);
0387
0388
0389 extern const cl_LF min (const cl_LF& x, const cl_LF& y);
0390
0391
0392 extern const cl_LF signum (const cl_LF& x);
0393
0394
0395
0396 extern float float_approx (const cl_LF& x);
0397
0398
0399 extern double double_approx (const cl_LF& x);
0400
0401
0402
0403 inline cl_LF& operator+= (cl_LF& x, const cl_LF& y) { return x = x + y; }
0404 inline cl_LF& operator++ (cl_LF& x) { return x = plus1(x); }
0405 inline void operator++ (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-- (cl_LF& x) { return x = minus1(x); }
0408 inline void operator-- (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
0414 extern cl_class cl_class_lfloat;
0415
0416
0417
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 }
0424
0425 #endif