File indexing completed on 2026-05-19 08:08:32
0001
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
0017 extern const cl_SF operator- (const cl_SF& x);
0018
0019
0020
0021 extern cl_signean compare (const cl_SF& x, const cl_SF& y);
0022
0023
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
0040 extern bool minusp (const cl_SF& x);
0041
0042
0043 extern bool zerop (const cl_SF& x);
0044
0045
0046 extern bool plusp (const cl_SF& x);
0047
0048
0049 extern const cl_SF operator+ (const cl_SF& x, const cl_SF& y);
0050
0051
0052 extern const cl_SF operator- (const cl_SF& x, const cl_SF& y);
0053
0054
0055 extern const cl_SF operator* (const cl_SF& x, const cl_SF& y);
0056
0057
0058 inline const cl_SF square (const cl_SF& x) { return x*x; }
0059
0060
0061 extern const cl_SF operator/ (const cl_SF& x, const cl_SF& y);
0062
0063
0064 extern const cl_SF sqrt (const cl_SF& x);
0065
0066
0067 extern const cl_SF recip (const cl_SF& x);
0068
0069
0070 extern const cl_SF abs (const cl_SF& x);
0071
0072
0073
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
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
0089 extern const cl_SF ffloor (const cl_SF& x);
0090
0091
0092 extern const cl_SF fceiling (const cl_SF& x);
0093
0094
0095 extern const cl_SF ftruncate (const cl_SF& x);
0096
0097
0098 extern const cl_SF fround (const cl_SF& x);
0099
0100
0101
0102
0103 struct cl_SF_fdiv_t {
0104 cl_SF quotient;
0105 cl_SF remainder;
0106
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
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
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
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
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
0129
0130 struct cl_SF_div_t {
0131 cl_I quotient;
0132 cl_SF remainder;
0133
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
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
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
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
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
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
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
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
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
0208 struct decoded_sfloat {
0209 cl_SF mantissa;
0210 cl_I exponent;
0211 cl_SF sign;
0212
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
0218
0219
0220 extern const decoded_sfloat decode_float (const cl_SF& x);
0221
0222
0223
0224
0225
0226 extern sintE float_exponent (const cl_SF& x);
0227
0228
0229 inline sintL float_radix (const cl_SF& x)
0230 {
0231 (void)x;
0232 return 2;
0233 }
0234
0235
0236 extern const cl_SF float_sign (const cl_SF& x);
0237
0238
0239
0240 extern uintC float_digits (const cl_SF& x);
0241
0242
0243
0244 extern uintC float_precision (const cl_SF& x);
0245
0246
0247
0248
0249
0250
0251 extern const cl_idecoded_float integer_decode_float (const cl_SF& x);
0252
0253
0254
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
0260 extern const cl_SF max (const cl_SF& x, const cl_SF& y);
0261
0262
0263 extern const cl_SF min (const cl_SF& x, const cl_SF& y);
0264
0265
0266 extern const cl_SF signum (const cl_SF& x);
0267
0268
0269
0270 extern float float_approx (const cl_SF& x);
0271
0272
0273 extern double double_approx (const cl_SF& x);
0274
0275
0276
0277 inline cl_SF& operator+= (cl_SF& x, const cl_SF& y) { return x = x + y; }
0278 inline cl_SF& operator++ (cl_SF& x) { return x = plus1(x); }
0279 inline void operator++ (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-- (cl_SF& x) { return x = minus1(x); }
0282 inline void operator-- (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
0288 extern cl_class cl_class_sfloat;
0289 CL_FORCE_LINK(cl_SF_classes_dummy, cl_class_sfloat)
0290
0291
0292
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 }
0299
0300 #endif