Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef EIGEN_MPREALSUPPORT_MODULE_H
00031 #define EIGEN_MPREALSUPPORT_MODULE_H
00032
00033 #include <mpreal.h>
00034 #include <Eigen/Core>
00035
00036 namespace Eigen {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 template<> struct NumTraits<mpfr::mpreal>
00081 : GenericNumTraits<mpfr::mpreal>
00082 {
00083 enum {
00084 IsInteger = 0,
00085 IsSigned = 1,
00086 IsComplex = 0,
00087 RequireInitialization = 1,
00088 ReadCost = 10,
00089 AddCost = 10,
00090 MulCost = 40
00091 };
00092
00093 typedef mpfr::mpreal Real;
00094 typedef mpfr::mpreal NonInteger;
00095
00096 inline static mpfr::mpreal highest() { return mpfr::mpreal_max(mpfr::mpreal::get_default_prec()); }
00097 inline static mpfr::mpreal lowest() { return -mpfr::mpreal_max(mpfr::mpreal::get_default_prec()); }
00098
00099 inline static Real epsilon()
00100 {
00101 return mpfr::machine_epsilon(mpfr::mpreal::get_default_prec());
00102 }
00103 inline static Real dummy_precision()
00104 {
00105 unsigned int weak_prec = ((mpfr::mpreal::get_default_prec()-1)*90)/100;
00106 return mpfr::machine_epsilon(weak_prec);
00107 }
00108 };
00109
00110 namespace internal {
00111
00112 template<> mpfr::mpreal random<mpfr::mpreal>()
00113 {
00114 #if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
00115 static gmp_randstate_t state;
00116 static bool isFirstTime = true;
00117
00118 if(isFirstTime)
00119 {
00120 gmp_randinit_default(state);
00121 gmp_randseed_ui(state,(unsigned)time(NULL));
00122 isFirstTime = false;
00123 }
00124
00125 return mpfr::urandom(state)*2-1;
00126 #else
00127 return mpfr::mpreal(random<double>());
00128 #endif
00129 }
00130
00131 template<> mpfr::mpreal random<mpfr::mpreal>(const mpfr::mpreal& a, const mpfr::mpreal& b)
00132 {
00133 return a + (b-a) * random<mpfr::mpreal>();
00134 }
00135
00136 bool isMuchSmallerThan(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& prec)
00137 {
00138 return mpfr::abs(a) <= mpfr::abs(b) * prec;
00139 }
00140
00141 inline bool isApprox(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& prec)
00142 {
00143 return mpfr::abs(a - b) <= (mpfr::min)(mpfr::abs(a), mpfr::abs(b)) * prec;
00144 }
00145
00146 inline bool isApproxOrLessThan(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& prec)
00147 {
00148 return a <= b || isApprox(a, b, prec);
00149 }
00150
00151 }
00152 }
00153
00154 #endif // EIGEN_MPREALSUPPORT_MODULE_H