File indexing completed on 2026-05-19 08:08:32
0001
0002
0003 #ifndef _CL_RATIONAL_H
0004 #define _CL_RATIONAL_H
0005
0006 #include "cln/number.h"
0007 #include "cln/rational_class.h"
0008 #include "cln/integer_class.h"
0009 #include "cln/exception.h"
0010
0011 namespace cln {
0012
0013 CL_DEFINE_AS_CONVERSION(cl_RA)
0014
0015
0016
0017 extern const cl_I numerator (const cl_RA& r);
0018
0019
0020 extern const cl_I denominator (const cl_RA& r);
0021
0022
0023
0024 extern const cl_RA operator- (const cl_RA& r);
0025
0026
0027 extern const cl_RA operator+ (const cl_RA& r, const cl_RA& s);
0028
0029 inline const cl_RA operator+ (const int x, const cl_RA& y)
0030 { return cl_I(x) + y; }
0031 inline const cl_RA operator+ (const unsigned int x, const cl_RA& y)
0032 { return cl_I(x) + y; }
0033 inline const cl_RA operator+ (const long x, const cl_RA& y)
0034 { return cl_I(x) + y; }
0035 inline const cl_RA operator+ (const unsigned long x, const cl_RA& y)
0036 { return cl_I(x) + y; }
0037 inline const cl_RA operator+ (const long long x, const cl_RA& y)
0038 { return cl_I(x) + y; }
0039 inline const cl_RA operator+ (const unsigned long long x, const cl_RA& y)
0040 { return cl_I(x) + y; }
0041 inline const cl_RA operator+ (const cl_RA& x, const int y)
0042 { return x + cl_I(y); }
0043 inline const cl_RA operator+ (const cl_RA& x, const unsigned int y)
0044 { return x + cl_I(y); }
0045 inline const cl_RA operator+ (const cl_RA& x, const long y)
0046 { return x + cl_I(y); }
0047 inline const cl_RA operator+ (const cl_RA& x, const unsigned long y)
0048 { return x + cl_I(y); }
0049 inline const cl_RA operator+ (const cl_RA& x, const long long y)
0050 { return x + cl_I(y); }
0051 inline const cl_RA operator+ (const cl_RA& x, const unsigned long long y)
0052 { return x + cl_I(y); }
0053
0054
0055 extern const cl_RA operator- (const cl_RA& r, const cl_RA& s);
0056
0057 inline const cl_RA operator- (const int x, const cl_RA& y)
0058 { return cl_I(x) - y; }
0059 inline const cl_RA operator- (const unsigned int x, const cl_RA& y)
0060 { return cl_I(x) - y; }
0061 inline const cl_RA operator- (const long x, const cl_RA& y)
0062 { return cl_I(x) - y; }
0063 inline const cl_RA operator- (const unsigned long x, const cl_RA& y)
0064 { return cl_I(x) - y; }
0065 inline const cl_RA operator- (const long long x, const cl_RA& y)
0066 { return cl_I(x) - y; }
0067 inline const cl_RA operator- (const unsigned long long x, const cl_RA& y)
0068 { return cl_I(x) - y; }
0069 inline const cl_RA operator- (const cl_RA& x, const int y)
0070 { return x - cl_I(y); }
0071 inline const cl_RA operator- (const cl_RA& x, const unsigned int y)
0072 { return x - cl_I(y); }
0073 inline const cl_RA operator- (const cl_RA& x, const long y)
0074 { return x - cl_I(y); }
0075 inline const cl_RA operator- (const cl_RA& x, const unsigned long y)
0076 { return x - cl_I(y); }
0077 inline const cl_RA operator- (const cl_RA& x, const long long y)
0078 { return x - cl_I(y); }
0079 inline const cl_RA operator- (const cl_RA& x, const unsigned long long y)
0080 { return x - cl_I(y); }
0081
0082
0083 extern const cl_RA plus1 (const cl_RA& r);
0084
0085
0086 extern const cl_RA minus1 (const cl_RA& r);
0087
0088
0089 extern const cl_RA abs (const cl_RA& r);
0090
0091
0092 extern bool equal (const cl_RA& r, const cl_RA& s);
0093
0094 extern uint32 equal_hashcode (const cl_RA& r);
0095
0096
0097
0098 extern cl_signean compare (const cl_RA& r, const cl_RA& s);
0099
0100 inline bool operator== (const cl_RA& x, const cl_RA& y)
0101 { return equal(x,y); }
0102 inline bool operator!= (const cl_RA& x, const cl_RA& y)
0103 { return !equal(x,y); }
0104 inline bool operator<= (const cl_RA& x, const cl_RA& y)
0105 { return compare(x,y)<=0; }
0106 inline bool operator< (const cl_RA& x, const cl_RA& y)
0107 { return compare(x,y)<0; }
0108 inline bool operator>= (const cl_RA& x, const cl_RA& y)
0109 { return compare(x,y)>=0; }
0110 inline bool operator> (const cl_RA& x, const cl_RA& y)
0111 { return compare(x,y)>0; }
0112
0113
0114 extern bool minusp (const cl_RA& x);
0115
0116
0117 extern bool zerop (const cl_RA& x);
0118
0119
0120 extern bool plusp (const cl_RA& x);
0121
0122
0123 extern const cl_RA recip (const cl_RA& r);
0124
0125
0126 extern const cl_RA operator* (const cl_RA& r, const cl_RA& s);
0127
0128 inline const cl_RA operator* (const int x, const cl_RA& y)
0129 { return cl_I(x) * y; }
0130 inline const cl_RA operator* (const unsigned int x, const cl_RA& y)
0131 { return cl_I(x) * y; }
0132 inline const cl_RA operator* (const long x, const cl_RA& y)
0133 { return cl_I(x) * y; }
0134 inline const cl_RA operator* (const unsigned long x, const cl_RA& y)
0135 { return cl_I(x) * y; }
0136 inline const cl_RA operator* (const long long x, const cl_RA& y)
0137 { return cl_I(x) * y; }
0138 inline const cl_RA operator* (const unsigned long long x, const cl_RA& y)
0139 { return cl_I(x) * y; }
0140 inline const cl_RA operator* (const cl_RA& x, const int y)
0141 { return x * cl_I(y); }
0142 inline const cl_RA operator* (const cl_RA& x, const unsigned int y)
0143 { return x * cl_I(y); }
0144 inline const cl_RA operator* (const cl_RA& x, const long y)
0145 { return x * cl_I(y); }
0146 inline const cl_RA operator* (const cl_RA& x, const unsigned long y)
0147 { return x * cl_I(y); }
0148 inline const cl_RA operator* (const cl_RA& x, const long long y)
0149 { return x * cl_I(y); }
0150 inline const cl_RA operator* (const cl_RA& x, const unsigned long long y)
0151 { return x * cl_I(y); }
0152
0153
0154 extern const cl_RA square (const cl_RA& r);
0155
0156
0157 extern const cl_RA operator/ (const cl_RA& r, const cl_RA& s);
0158
0159 inline const cl_RA operator/ (const int x, const cl_RA& y)
0160 { return cl_I(x) / y; }
0161 inline const cl_RA operator/ (const unsigned int x, const cl_RA& y)
0162 { return cl_I(x) / y; }
0163 inline const cl_RA operator/ (const long x, const cl_RA& y)
0164 { return cl_I(x) / y; }
0165 inline const cl_RA operator/ (const unsigned long x, const cl_RA& y)
0166 { return cl_I(x) / y; }
0167 inline const cl_RA operator/ (const long long x, const cl_RA& y)
0168 { return cl_I(x) / y; }
0169 inline const cl_RA operator/ (const unsigned long long x, const cl_RA& y)
0170 { return cl_I(x) / y; }
0171 inline const cl_RA operator/ (const cl_RA& x, const int y)
0172 { return x / cl_I(y); }
0173 inline const cl_RA operator/ (const cl_RA& x, const unsigned int y)
0174 { return x / cl_I(y); }
0175 inline const cl_RA operator/ (const cl_RA& x, const long y)
0176 { return x / cl_I(y); }
0177 inline const cl_RA operator/ (const cl_RA& x, const unsigned long y)
0178 { return x / cl_I(y); }
0179 inline const cl_RA operator/ (const cl_RA& x, const long long y)
0180 { return x / cl_I(y); }
0181 inline const cl_RA operator/ (const cl_RA& x, const unsigned long long y)
0182 { return x / cl_I(y); }
0183
0184
0185
0186 struct cl_RA_div_t {
0187 cl_I quotient;
0188 cl_RA remainder;
0189
0190 cl_RA_div_t () {}
0191 cl_RA_div_t (const cl_I& q, const cl_RA& r) : quotient(q), remainder(r) {}
0192 };
0193
0194
0195
0196
0197
0198
0199 extern const cl_RA_div_t floor2 (const cl_RA& x);
0200 extern const cl_I floor1 (const cl_RA& x);
0201
0202
0203
0204
0205
0206
0207 extern const cl_RA_div_t ceiling2 (const cl_RA& x);
0208 extern const cl_I ceiling1 (const cl_RA& x);
0209
0210
0211
0212
0213
0214
0215 extern const cl_RA_div_t truncate2 (const cl_RA& x);
0216 extern const cl_I truncate1 (const cl_RA& x);
0217
0218
0219
0220
0221
0222
0223 extern const cl_RA_div_t round2 (const cl_RA& x);
0224 extern const cl_I round1 (const cl_RA& x);
0225
0226
0227 extern const cl_RA_div_t floor2 (const cl_RA& x, const cl_RA& y);
0228 extern const cl_I floor1 (const cl_RA& x, const cl_RA& y);
0229
0230
0231 extern const cl_RA_div_t ceiling2 (const cl_RA& x, const cl_RA& y);
0232 extern const cl_I ceiling1 (const cl_RA& x, const cl_RA& y);
0233
0234
0235 extern const cl_RA_div_t truncate2 (const cl_RA& x, const cl_RA& y);
0236 extern const cl_I truncate1 (const cl_RA& x, const cl_RA& y);
0237
0238
0239 extern const cl_RA_div_t round2 (const cl_RA& x, const cl_RA& y);
0240 extern const cl_I round1 (const cl_RA& x, const cl_RA& y);
0241
0242
0243 extern const cl_RA max (const cl_RA& x, const cl_RA& y);
0244
0245
0246 extern const cl_RA min (const cl_RA& x, const cl_RA& y);
0247
0248
0249 extern const cl_RA signum (const cl_RA& x);
0250
0251
0252 extern const cl_RA expt_pos (const cl_RA& x, uintL y);
0253 extern const cl_RA expt_pos (const cl_RA& x, const cl_I& y);
0254
0255
0256 extern const cl_RA expt (const cl_RA& x, sintL y);
0257 extern const cl_RA expt (const cl_RA& x, const cl_I& y);
0258
0259
0260
0261
0262
0263
0264
0265 extern bool sqrtp (const cl_RA& x, cl_RA* w);
0266
0267
0268
0269
0270
0271
0272
0273
0274 extern bool rootp (const cl_RA& x, uintL n, cl_RA* w);
0275 extern bool rootp (const cl_RA& x, const cl_I& n, cl_RA* w);
0276
0277
0278
0279
0280
0281
0282
0283
0284 extern bool logp (const cl_I& a, const cl_I& b, cl_RA* l);
0285
0286
0287
0288
0289
0290
0291
0292
0293 extern bool logp (const cl_RA& a, const cl_RA& b, cl_RA* l);
0294
0295
0296 extern float float_approx (const cl_RA& x);
0297
0298
0299 extern double double_approx (const cl_RA& x);
0300
0301
0302
0303 inline cl_RA& operator+= (cl_RA& x, const cl_RA& y) { return x = x + y; }
0304 inline cl_RA& operator+= (cl_RA& x, const int y) { return x = x + y; }
0305 inline cl_RA& operator+= (cl_RA& x, const unsigned int y) { return x = x + y; }
0306 inline cl_RA& operator+= (cl_RA& x, const long y) { return x = x + y; }
0307 inline cl_RA& operator+= (cl_RA& x, const unsigned long y) { return x = x + y; }
0308 inline cl_RA& operator+= (cl_RA& x, const long long y) { return x = x + y; }
0309 inline cl_RA& operator+= (cl_RA& x, const unsigned long long y) { return x = x + y; }
0310 inline cl_RA& operator++ (cl_RA& x) { return x = plus1(x); }
0311 inline void operator++ (cl_RA& x, int dummy) { (void)dummy; x = plus1(x); }
0312 inline cl_RA& operator-= (cl_RA& x, const cl_RA& y) { return x = x - y; }
0313 inline cl_RA& operator-= (cl_RA& x, const int y) { return x = x - y; }
0314 inline cl_RA& operator-= (cl_RA& x, const unsigned int y) { return x = x - y; }
0315 inline cl_RA& operator-= (cl_RA& x, const long y) { return x = x - y; }
0316 inline cl_RA& operator-= (cl_RA& x, const unsigned long y) { return x = x - y; }
0317 inline cl_RA& operator-= (cl_RA& x, const long long y) { return x = x - y; }
0318 inline cl_RA& operator-= (cl_RA& x, const unsigned long long y) { return x = x - y; }
0319 inline cl_RA& operator-- (cl_RA& x) { return x = minus1(x); }
0320 inline void operator-- (cl_RA& x, int dummy) { (void)dummy; x = minus1(x); }
0321 inline cl_RA& operator*= (cl_RA& x, const cl_RA& y) { return x = x * y; }
0322 inline cl_RA& operator/= (cl_RA& x, const cl_RA& y) { return x = x / y; }
0323
0324
0325
0326 extern cl_class cl_class_ratio;
0327
0328
0329
0330 #ifdef CL_DEBUG
0331 extern int cl_RA_debug_module;
0332 CL_FORCE_LINK(cl_RA_debug_dummy, cl_RA_debug_module)
0333 #endif
0334
0335 }
0336
0337 #endif