00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MPF_H
00024 #define MPF_H
00025
00026 #include "mpi.h"
00027
00028 namespace mp {
00029
00051 class mpf_ : public mpi_ {
00052 public:
00053 typedef mp::float_type float_type;
00054
00056 static const byte capabilities();
00057
00059 static void resetMinPrecision();
00062 static void setMinPrecision(size_type p);
00065 static size_type getMinPrecision();
00066
00067 mpf_() {}
00068 mpf_(int_type n, size_type p = 0) {
00069 init(n, p);
00070 }
00071 mpf_(float_type n, size_type p = 0) {
00072 init(n, p);
00073 }
00074 mpf_(const mpi_ &n, size_type p = 0) {
00075 init(n, p);
00076 }
00077 mpf_(const mpf_ &n, size_type p = 0) {
00078 init(n, p);
00079 }
00080
00088 int_type toInt() const;
00089 float_type toFloat() const;
00091
00092
00093 void init(int_type n, size_type p = 0);
00094 void init(float_type n, size_type p = 0);
00095 void init(const mpi_ &n, size_type p = 0);
00096 void init(const mpf_ &n, size_type p = 0);
00097
00098 void setPrecision(size_type prec);
00099
00100 void clear();
00101
00106 void swap(mpf_ &n);
00107
00108 mpi_ ipart() const;
00109 mpi_ fpart() const;
00110
00111 mpf_ getIntPart() const;
00112 mpf_ getFractPart() const;
00113
00116 size_type accuracy() const;
00121 size_type accuracy(const mpf_ &n) const;
00122
00126 int compare(const mpf_ &n) const;
00127
00132 size_type getPrecision() const;
00135 size_type getExponant() const;
00136
00137 bool hasIntPart() const;
00138 bool hasFractPart() const;
00139
00143 void normalize(mpf_ &n);
00144
00147 void add(const mpf_ &n, size_type p = 0);
00148 void sub(const mpf_ &n, size_type p = 0);
00149 void mul(const mpf_ &n, size_type p = 0);
00150 void div(const mpf_ &n, size_type p = 0);
00151 void mod(const mpf_ &n, size_type p = 0);
00152
00153 void mul_pow2(size_type n);
00154 void div_pow2(size_type n);
00155
00156 void sqr();
00158
00166 mpf_ pow(const mpf_ &n, size_type p = 0) const;
00167
00171 mpf_ sqrt(size_type p = 0) const;
00172
00177 mpf_ root(limb_type n, size_type p = 0) const;
00178
00182 mpf_ exp(size_type p = 0) const;
00183
00187 mpf_ log(size_type p = 0) const;
00188
00193 mpf_ agm(const mpf_ &n, size_type p) const;
00194
00197 void pi(size_type p);
00199
00208 void setString(const std::string &s, radix_type b = 0);
00209
00214 std::string getString(radix_type b = string_base) const;
00216
00221 void print() const;
00223
00226 void checkExp();
00227
00228 protected:
00229 static size_type min_precision;
00230 static const size_type min_prec_default;
00231
00232 size_type exp_;
00233
00234 private:
00235 void add_sub(const mpf_ &n, size_type p, bool subtract);
00236 };
00237
00248 class mpf : public mpf_ {
00249 public:
00250 mpf(const mpf_ &n) : mpf_(n) {}
00251
00252 mpf() {}
00253 mpf(int_type n, size_type p = 0) : mpf_(n, p) {}
00254 mpf(float_type n, size_type p = 0) : mpf_(n, p) {}
00255 mpf(const mpi &n, size_type p = 0) : mpf_(n, p) {}
00256 mpf(const mpf &n, size_type p = 0) : mpf_(n, p) {}
00257 mpf(const std::string &s, char b = 0) {
00258 setString(s, b);
00259 }
00260
00263 operator int_type() const {
00264 return toInt();
00265 }
00266 operator float_type() const {
00267 return toFloat();
00268 }
00269 operator std::string() const {
00270 return getString();
00271 }
00272 operator mpi() const {
00273 return ipart();
00274 }
00276
00277 mpf & operator ++ ();
00278 const mpf operator ++ (int);
00279
00280 mpf & operator -- ();
00281 const mpf operator -- (int);
00282
00283 const mpf & operator = (int_type n);
00284 const mpf & operator = (float_type n);
00285 const mpf & operator = (const mpi &n);
00286 const mpf & operator = (const mpf &n);
00287 const mpf & operator = (const std::string &n);
00288
00289
00290 const mpf & operator += (int_type n);
00291 const mpf & operator += (float_type n);
00292 const mpf & operator += (const mpi &n);
00293 const mpf & operator += (const mpf &n);
00294
00295
00296 const mpf & operator -= (int_type n);
00297 const mpf & operator -= (float_type n);
00298 const mpf & operator -= (const mpi &n);
00299 const mpf & operator -= (const mpf &n);
00300
00301
00302 const mpf & operator *= (int_type n);
00303 const mpf & operator *= (float_type n);
00304 const mpf & operator *= (const mpi &n);
00305 const mpf & operator *= (const mpf &n);
00306
00307
00308 const mpf & operator /= (int_type n);
00309 const mpf & operator /= (float_type n);
00310 const mpf & operator /= (const mpi &n);
00311 const mpf & operator /= (const mpf &n);
00312
00313 const mpf & operator %= (const mpf &n);
00314
00315 };
00316
00317 std::istream & operator >> (std::istream &is, mpf &n);
00318 std::ostream & operator << (std::ostream &os, const mpf &n);
00319
00320
00321
00322
00323 bool operator == (const mpf &x, int_type y);
00324 bool operator != (const mpf &x, int_type y);
00325 bool operator < (const mpf &x, int_type y);
00326 bool operator <= (const mpf &x, int_type y);
00327 bool operator > (const mpf &x, int_type y);
00328 bool operator >= (const mpf &x, int_type y);
00329
00330 bool operator == (const mpf &x, float_type y);
00331 bool operator != (const mpf &x, float_type y);
00332 bool operator < (const mpf &x, float_type y);
00333 bool operator <= (const mpf &x, float_type y);
00334 bool operator > (const mpf &x, float_type y);
00335 bool operator >= (const mpf &x, float_type y);
00336
00337 bool operator == (const mpf &x, const mpi &y);
00338 bool operator != (const mpf &x, const mpi &y);
00339 bool operator < (const mpf &x, const mpi &y);
00340 bool operator <= (const mpf &x, const mpi &y);
00341 bool operator > (const mpf &x, const mpi &y);
00342 bool operator >= (const mpf &x, const mpi &y);
00343
00344 bool operator == (const mpf &x, const mpf &y);
00345 bool operator != (const mpf &x, const mpf &y);
00346 bool operator < (const mpf &x, const mpf &y);
00347 bool operator <= (const mpf &x, const mpf &y);
00348 bool operator > (const mpf &x, const mpf &y);
00349 bool operator >= (const mpf &x, const mpf &y);
00350
00353 mpf operator + (const mpf &x);
00354 mpf operator - (const mpf &x);
00356
00357
00358 mpf operator + (const mpf &x, int_type y);
00359 mpf operator + (int_type x, const mpf &y);
00360 mpf operator + (const mpf &x, float_type y);
00361 mpf operator + (float_type x, const mpi &y);
00362 mpf operator + (const mpf &x, const mpi &y);
00363 mpf operator + (const mpi &x, const mpf &y);
00364 mpf operator + (const mpf &x, const mpf &y);
00365
00366
00367 mpf operator - (const mpf &x, int_type y);
00368 mpf operator - (int_type x, const mpf &y);
00369 mpf operator - (const mpf &x, float_type y);
00370 mpf operator - (float_type x, const mpi &y);
00371 mpf operator - (const mpf &x, const mpi &y);
00372 mpf operator - (const mpi &x, const mpf &y);
00373 mpf operator - (const mpf &x, const mpf &y);
00374
00375
00376 mpf operator * (const mpf &x, int_type y);
00377 mpf operator * (int_type x, const mpf &y);
00378 mpf operator * (const mpf &x, float_type y);
00379 mpf operator * (float_type x, const mpi &y);
00380 mpf operator * (const mpf &x, const mpi &y);
00381 mpf operator * (const mpi &x, const mpf &y);
00382 mpf operator * (const mpf &x, const mpf &y);
00383
00384
00385 mpf operator / (const mpf &x, int_type y);
00386 mpf operator / (int_type x, const mpf &y);
00387 mpf operator / (const mpf &x, float_type y);
00388 mpf operator / (float_type x, const mpf &y);
00389 mpf operator / (const mpf &x, const mpi &y);
00390 mpf operator / (const mpi &x, const mpf &y);
00391 mpf operator / (const mpf &x, const mpf &y);
00392
00393 mpf operator % (const mpf &x, const mpf &y);
00394
00395 mpf abs(const mpf &n);
00396 mpf round(const mpf &x, size_type a);
00397
00398 mpf pow(const mpf &x, const mpf &n, size_type p = 0);
00399 mpf sqr(const mpf &n);
00400
00401 mpf root(const mpf &x, limb_type n, size_type p = 0);
00402 mpf sqrt(const mpf &n, size_type p = 0);
00403
00404 mpf exp(const mpf &n, size_type p = 0);
00405
00406 mpf agm(const mpf &x, const mpf &y, size_type p);
00407
00408 mpf log(const mpf &n, size_type p = 0);
00409
00410 mpf pi(size_type a);
00411
00412 void sin_cos(mpf &sin, mpf &cos, const mpf &theta, size_type p);
00413
00414 mpf sin(const mpf &theta, size_type p = 0);
00415 mpf cos(const mpf &theta, size_type p = 0);
00416 mpf tan(const mpf &theta, size_type p = 0);
00417
00418 mpf asin(const mpf &x, size_type p = 0);
00419 mpf acos(const mpf &x, size_type p = 0);
00420 mpf atan(const mpf &x, size_type p = 0);
00421
00423 }
00424 #endif