24 #ifndef COM_DAFER45_TBTK_ARBITRARY_PRECISION_REAL
25 #define COM_DAFER45_TBTK_ARBITRARY_PRECISION_REAL
37 namespace ArbitraryPrecision{
53 Real(
const Real &real);
58 Real(
unsigned int precision);
63 Real(
unsigned int precision,
double value);
68 Real(
unsigned int precision,
const std::string &value);
75 Real& operator=(
const Real &real);
82 Real& operator=(
double rhs);
89 Real& operator=(
const std::string &rhs);
96 Real& operator+=(
const Real &rhs);
103 Real operator+(
const Real &rhs)
const;
110 Real& operator-=(
const Real &rhs);
117 Real operator-(
const Real &rhs)
const;
124 Real& operator*=(
const Real &rhs);
138 Real& operator/=(
const Real &rhs);
145 Real operator/(
const Real &rhs)
const;
150 Real operator-()
const;
156 friend std::ostream&
operator<<(std::ostream &os,
const Real &real);
161 const mpf_t& getValue()
const;
166 double getDouble()
const;
171 mp_bitcnt_t getPrecision()
const;
181 isInitialized =
false;
184 inline Real::~Real(){
190 mpf_init2(value,
real.getPrecision());
191 mpf_set(value,
real.value);
192 isInitialized =
true;
196 mpf_init2(value, precision);
197 isInitialized =
true;
200 inline Real::Real(
unsigned int precision,
double value){
201 mpf_init2(this->value, precision);
203 isInitialized =
true;
206 inline Real::Real(
unsigned int precision,
const std::string &value){
207 mpf_init2(this->value, precision);
209 isInitialized =
true;
217 mpf_init2(value, rhs.getPrecision());
218 mpf_set(value, rhs.value);
219 isInitialized =
true;
226 mpf_set_d(value, rhs);
232 mpf_set_str(value, rhs.c_str(), 10);
238 mpf_add(value, value, rhs.value);
243 inline Real Real::operator+(
const Real &rhs)
const{
250 mpf_sub(value, value, rhs.value);
255 inline Real Real::operator-(
const Real &rhs)
const{
262 mpf_mul(value, value, rhs.value);
267 inline Real Real::operator*(
const Real &rhs)
const{
274 mpf_div(value, value, rhs.value);
279 inline Real Real::operator/(
const Real &rhs)
const{
285 inline Real Real::operator-()
const{
287 mpf_init2(
real.value, getPrecision());
288 mpf_neg(
real.value, value);
289 real.isInitialized =
true;
294 inline std::ostream&
operator<<(std::ostream &os,
const Real &real){
300 inline const mpf_t& Real::getValue()
const{
304 inline double Real::getDouble()
const{
305 return mpf_get_d(value);
308 inline mp_bitcnt_t Real::getPrecision()
const{
309 return mpf_get_prec(value);