1 #include "MpfrFloat.hh"
9 //===========================================================================
11 //===========================================================================
12 struct MpfrFloat::MpfrFloatData
15 MpfrFloatData* nextFreeNode;
18 MpfrFloatData(): mRefCount(1), nextFreeNode(0) {}
21 class MpfrFloat::MpfrFloatDataContainer
23 unsigned long mDefaultPrecision;
24 std::deque<MpfrFloatData> mData;
25 MpfrFloatData* mFirstFreeNode;
28 *mConst_0, *mConst_pi, *mConst_e, *mConst_log2, *mConst_epsilon;
30 void recalculateEpsilon()
32 mpfr_set_si(mConst_epsilon->mFloat, 1, GMP_RNDN);
33 mpfr_div_2ui(mConst_epsilon->mFloat, mConst_epsilon->mFloat,
34 mDefaultPrecision*7/8 - 1, GMP_RNDN);
38 MpfrFloatDataContainer():
39 mDefaultPrecision(256), mFirstFreeNode(0),
40 mConst_pi(0), mConst_e(0), mConst_log2(0), mConst_epsilon(0)
43 ~MpfrFloatDataContainer()
45 for(size_t i = 0; i < mData.size(); ++i)
46 mpfr_clear(mData[i].mFloat);
49 MpfrFloatData* allocateMpfrFloatData(bool initToZero)
53 MpfrFloatData* node = mFirstFreeNode;
54 mFirstFreeNode = node->nextFreeNode;
55 if(initToZero) mpfr_set_si(node->mFloat, 0, GMP_RNDN);
60 mData.push_back(MpfrFloatData());
61 mpfr_init2(mData.back().mFloat, mDefaultPrecision);
62 if(initToZero) mpfr_set_si(mData.back().mFloat, 0, GMP_RNDN);
66 void releaseMpfrFloatData(MpfrFloatData* data)
68 if(--(data->mRefCount) == 0)
70 data->nextFreeNode = mFirstFreeNode;
71 mFirstFreeNode = data;
75 void setDefaultPrecision(unsigned long bits)
77 if(bits != mDefaultPrecision)
79 mDefaultPrecision = bits;
80 for(size_t i = 0; i < mData.size(); ++i)
81 mpfr_prec_round(mData[i].mFloat, bits, GMP_RNDN);
83 if(mConst_pi) mpfr_const_pi(mConst_pi->mFloat, GMP_RNDN);
86 mpfr_set_si(mConst_e->mFloat, 1, GMP_RNDN);
87 mpfr_exp(mConst_e->mFloat, mConst_e->mFloat, GMP_RNDN);
89 if(mConst_log2) mpfr_const_log2(mConst_log2->mFloat, GMP_RNDN);
90 if(mConst_epsilon) recalculateEpsilon();
94 unsigned long getDefaultPrecision() const
96 return mDefaultPrecision;
99 MpfrFloatData* const_0()
101 if(!mConst_0) mConst_0 = allocateMpfrFloatData(true);
109 mConst_pi = allocateMpfrFloatData(false);
110 mpfr_const_pi(mConst_pi->mFloat, GMP_RNDN);
112 return MpfrFloat(mConst_pi);
119 mConst_e = allocateMpfrFloatData(false);
120 mpfr_set_si(mConst_e->mFloat, 1, GMP_RNDN);
121 mpfr_exp(mConst_e->mFloat, mConst_e->mFloat, GMP_RNDN);
123 return MpfrFloat(mConst_e);
126 MpfrFloat const_log2()
130 mConst_log2 = allocateMpfrFloatData(false);
131 mpfr_const_log2(mConst_log2->mFloat, GMP_RNDN);
133 return MpfrFloat(mConst_log2);
136 MpfrFloat const_epsilon()
140 mConst_epsilon = allocateMpfrFloatData(false);
141 recalculateEpsilon();
143 return MpfrFloat(mConst_epsilon);
148 //===========================================================================
150 //===========================================================================
151 // This should ensure that the container is not accessed by any MpfrFloat
152 // instance before it has been constructed or after it has been destroyed
153 // (which might otherwise happen if MpfrFloat is instantiated globally.)
154 MpfrFloat::MpfrFloatDataContainer& MpfrFloat::mpfrFloatDataContainer()
156 static MpfrFloat::MpfrFloatDataContainer container;
161 //===========================================================================
162 // Auxiliary functions
163 //===========================================================================
164 void MpfrFloat::setDefaultMantissaBits(unsigned long bits)
166 mpfrFloatDataContainer().setDefaultPrecision(bits);
169 unsigned long MpfrFloat::getCurrentDefaultMantissaBits()
171 return mpfrFloatDataContainer().getDefaultPrecision();
174 inline void MpfrFloat::copyIfShared()
176 if(mData->mRefCount > 1)
178 --(mData->mRefCount);
179 MpfrFloatData* oldData = mData;
180 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
181 mpfr_set(mData->mFloat, oldData->mFloat, GMP_RNDN);
186 //===========================================================================
187 // Constructors, destructor, assignment
188 //===========================================================================
189 MpfrFloat::MpfrFloat(DummyType):
190 mData(mpfrFloatDataContainer().allocateMpfrFloatData(false))
193 MpfrFloat::MpfrFloat(MpfrFloatData* data):
197 ++(mData->mRefCount);
200 MpfrFloat::MpfrFloat():
201 mData(mpfrFloatDataContainer().const_0())
203 ++(mData->mRefCount);
206 MpfrFloat::MpfrFloat(double value)
210 mData = mpfrFloatDataContainer().const_0();
211 ++(mData->mRefCount);
215 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
216 mpfr_set_d(mData->mFloat, value, GMP_RNDN);
220 MpfrFloat::MpfrFloat(long double value)
224 mData = mpfrFloatDataContainer().const_0();
225 ++(mData->mRefCount);
229 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
230 mpfr_set_ld(mData->mFloat, value, GMP_RNDN);
234 MpfrFloat::MpfrFloat(long value)
238 mData = mpfrFloatDataContainer().const_0();
239 ++(mData->mRefCount);
243 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
244 mpfr_set_si(mData->mFloat, value, GMP_RNDN);
248 MpfrFloat::MpfrFloat(int value)
252 mData = mpfrFloatDataContainer().const_0();
253 ++(mData->mRefCount);
257 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
258 mpfr_set_si(mData->mFloat, value, GMP_RNDN);
262 MpfrFloat::MpfrFloat(const char* value, char** endptr):
263 mData(mpfrFloatDataContainer().allocateMpfrFloatData(false))
265 mpfr_strtofr(mData->mFloat, value, endptr, 0, GMP_RNDN);
268 MpfrFloat::~MpfrFloat()
270 mpfrFloatDataContainer().releaseMpfrFloatData(mData);
273 MpfrFloat::MpfrFloat(const MpfrFloat& rhs):
276 ++(mData->mRefCount);
279 MpfrFloat& MpfrFloat::operator=(const MpfrFloat& rhs)
281 if(mData != rhs.mData)
283 mpfrFloatDataContainer().releaseMpfrFloatData(mData);
285 ++(mData->mRefCount);
290 MpfrFloat& MpfrFloat::operator=(double value)
294 mpfrFloatDataContainer().releaseMpfrFloatData(mData);
295 mData = mpfrFloatDataContainer().const_0();
296 ++(mData->mRefCount);
300 if(mData->mRefCount > 1)
302 --(mData->mRefCount);
303 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
305 mpfr_set_d(mData->mFloat, value, GMP_RNDN);
310 MpfrFloat& MpfrFloat::operator=(long double value)
314 mpfrFloatDataContainer().releaseMpfrFloatData(mData);
315 mData = mpfrFloatDataContainer().const_0();
316 ++(mData->mRefCount);
320 if(mData->mRefCount > 1)
322 --(mData->mRefCount);
323 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
325 mpfr_set_ld(mData->mFloat, value, GMP_RNDN);
330 MpfrFloat& MpfrFloat::operator=(long value)
334 mpfrFloatDataContainer().releaseMpfrFloatData(mData);
335 mData = mpfrFloatDataContainer().const_0();
336 ++(mData->mRefCount);
340 if(mData->mRefCount > 1)
342 --(mData->mRefCount);
343 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
345 mpfr_set_si(mData->mFloat, value, GMP_RNDN);
350 MpfrFloat& MpfrFloat::operator=(int value)
354 mpfrFloatDataContainer().releaseMpfrFloatData(mData);
355 mData = mpfrFloatDataContainer().const_0();
356 ++(mData->mRefCount);
360 if(mData->mRefCount > 1)
362 --(mData->mRefCount);
363 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
365 mpfr_set_si(mData->mFloat, value, GMP_RNDN);
371 MpfrFloat& MpfrFloat::operator=(const char* value)
373 if(mData->mRefCount > 1)
375 --(mData->mRefCount);
376 mData = mpfrFloatDataContainer().allocateMpfrFloatData(false);
379 mpfr_set_str(mData->mFloat, value, 10, GMP_RNDN);
384 void MpfrFloat::parseValue(const char* value)
387 mpfr_set_str(mData->mFloat, value, 10, GMP_RNDN);
390 void MpfrFloat::parseValue(const char* value, char** endptr)
393 mpfr_strtofr(mData->mFloat, value, endptr, 0, GMP_RNDN);
397 //===========================================================================
399 //===========================================================================
401 void MpfrFloat::get_raw_mpfr_data<mpfr_t>(mpfr_t& dest_mpfr_t)
403 std::memcpy(&dest_mpfr_t, mData->mFloat, sizeof(mpfr_t));
406 const char* MpfrFloat::getAsString(unsigned precision) const
408 #if(MPFR_VERSION_MAJOR < 2 || (MPFR_VERSION_MAJOR == 2 && MPFR_VERSION_MINOR < 4))
409 static const char* retval =
410 "[mpfr_snprintf() is not supported in mpfr versions prior to 2.4]";
413 static std::vector<char> str;
414 str.resize(precision+30);
415 mpfr_snprintf(&(str[0]), precision+30, "%.*RNg", precision, mData->mFloat);
420 bool MpfrFloat::isInteger() const
422 return mpfr_integer_p(mData->mFloat) != 0;
425 long MpfrFloat::toInt() const
427 return mpfr_get_si(mData->mFloat, GMP_RNDN);
430 double MpfrFloat::toDouble() const
432 return mpfr_get_d(mData->mFloat, GMP_RNDN);
436 //===========================================================================
437 // Modifying operators
438 //===========================================================================
439 MpfrFloat& MpfrFloat::operator+=(const MpfrFloat& rhs)
442 mpfr_add(mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
446 MpfrFloat& MpfrFloat::operator+=(double value)
449 mpfr_add_d(mData->mFloat, mData->mFloat, value, GMP_RNDN);
453 MpfrFloat& MpfrFloat::operator-=(const MpfrFloat& rhs)
456 mpfr_sub(mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
460 MpfrFloat& MpfrFloat::operator-=(double value)
463 mpfr_sub_d(mData->mFloat, mData->mFloat, value, GMP_RNDN);
467 MpfrFloat& MpfrFloat::operator*=(const MpfrFloat& rhs)
470 mpfr_mul(mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
474 MpfrFloat& MpfrFloat::operator*=(double value)
477 mpfr_mul_d(mData->mFloat, mData->mFloat, value, GMP_RNDN);
481 MpfrFloat& MpfrFloat::operator/=(const MpfrFloat& rhs)
484 mpfr_div(mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
488 MpfrFloat& MpfrFloat::operator/=(double value)
491 mpfr_div_d(mData->mFloat, mData->mFloat, value, GMP_RNDN);
495 MpfrFloat& MpfrFloat::operator%=(const MpfrFloat& rhs)
498 mpfr_fmod(mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
503 //===========================================================================
504 // Modifying functions
505 //===========================================================================
506 void MpfrFloat::negate()
509 mpfr_neg(mData->mFloat, mData->mFloat, GMP_RNDN);
512 void MpfrFloat::abs()
515 mpfr_abs(mData->mFloat, mData->mFloat, GMP_RNDN);
519 //===========================================================================
520 // Non-modifying operators
521 //===========================================================================
522 MpfrFloat MpfrFloat::operator+(const MpfrFloat& rhs) const
524 MpfrFloat retval(kNoInitialization);
525 mpfr_add(retval.mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
529 MpfrFloat MpfrFloat::operator+(double value) const
531 MpfrFloat retval(kNoInitialization);
532 mpfr_add_d(retval.mData->mFloat, mData->mFloat, value, GMP_RNDN);
536 MpfrFloat MpfrFloat::operator-(const MpfrFloat& rhs) const
538 MpfrFloat retval(kNoInitialization);
539 mpfr_sub(retval.mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
543 MpfrFloat MpfrFloat::operator-(double value) const
545 MpfrFloat retval(kNoInitialization);
546 mpfr_sub_d(retval.mData->mFloat, mData->mFloat, value, GMP_RNDN);
550 MpfrFloat MpfrFloat::operator*(const MpfrFloat& rhs) const
552 MpfrFloat retval(kNoInitialization);
553 mpfr_mul(retval.mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
557 MpfrFloat MpfrFloat::operator*(double value) const
559 MpfrFloat retval(kNoInitialization);
560 mpfr_mul_d(retval.mData->mFloat, mData->mFloat, value, GMP_RNDN);
564 MpfrFloat MpfrFloat::operator/(const MpfrFloat& rhs) const
566 MpfrFloat retval(kNoInitialization);
567 mpfr_div(retval.mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
571 MpfrFloat MpfrFloat::operator/(double value) const
573 MpfrFloat retval(kNoInitialization);
574 mpfr_div_d(retval.mData->mFloat, mData->mFloat, value, GMP_RNDN);
578 MpfrFloat MpfrFloat::operator%(const MpfrFloat& rhs) const
580 MpfrFloat retval(kNoInitialization);
581 mpfr_fmod(retval.mData->mFloat, mData->mFloat, rhs.mData->mFloat, GMP_RNDN);
585 MpfrFloat MpfrFloat::operator-() const
587 MpfrFloat retval(kNoInitialization);
588 mpfr_neg(retval.mData->mFloat, mData->mFloat, GMP_RNDN);
594 //===========================================================================
595 // Comparison operators
596 //===========================================================================
597 bool MpfrFloat::operator<(const MpfrFloat& rhs) const
599 return mpfr_cmp(mData->mFloat, rhs.mData->mFloat) < 0;
602 bool MpfrFloat::operator<(double value) const
604 return mpfr_cmp_d(mData->mFloat, value) < 0;
607 bool MpfrFloat::operator<=(const MpfrFloat& rhs) const
609 return mpfr_cmp(mData->mFloat, rhs.mData->mFloat) <= 0;
612 bool MpfrFloat::operator<=(double value) const
614 return mpfr_cmp_d(mData->mFloat, value) <= 0;
617 bool MpfrFloat::operator>(const MpfrFloat& rhs) const
619 return mpfr_cmp(mData->mFloat, rhs.mData->mFloat) > 0;
622 bool MpfrFloat::operator>(double value) const
624 return mpfr_cmp_d(mData->mFloat, value) > 0;
627 bool MpfrFloat::operator>=(const MpfrFloat& rhs) const
629 return mpfr_cmp(mData->mFloat, rhs.mData->mFloat) >= 0;
632 bool MpfrFloat::operator>=(double value) const
634 return mpfr_cmp_d(mData->mFloat, value) >= 0;
637 bool MpfrFloat::operator==(const MpfrFloat& rhs) const
639 return mpfr_cmp(mData->mFloat, rhs.mData->mFloat) == 0;
642 bool MpfrFloat::operator==(double value) const
644 return mpfr_cmp_d(mData->mFloat, value) == 0;
647 bool MpfrFloat::operator!=(const MpfrFloat& rhs) const
649 return mpfr_cmp(mData->mFloat, rhs.mData->mFloat) != 0;
652 bool MpfrFloat::operator!=(double value) const
654 return mpfr_cmp_d(mData->mFloat, value) != 0;
658 //===========================================================================
659 // Operator functions
660 //===========================================================================
661 MpfrFloat operator+(double lhs, const MpfrFloat& rhs)
663 MpfrFloat retval(MpfrFloat::kNoInitialization);
664 mpfr_add_d(retval.mData->mFloat, rhs.mData->mFloat, lhs, GMP_RNDN);
668 MpfrFloat operator-(double lhs, const MpfrFloat& rhs)
670 MpfrFloat retval(MpfrFloat::kNoInitialization);
671 mpfr_d_sub(retval.mData->mFloat, lhs, rhs.mData->mFloat, GMP_RNDN);
675 MpfrFloat operator*(double lhs, const MpfrFloat& rhs)
680 MpfrFloat operator/(double lhs, const MpfrFloat& rhs)
682 return MpfrFloat(lhs) / rhs;
685 MpfrFloat operator%(double lhs, const MpfrFloat& rhs)
687 return MpfrFloat(lhs) % rhs;
690 std::ostream& operator<<(std::ostream& os, const MpfrFloat& value)
692 os << value.getAsString(unsigned(os.precision()));
696 //===========================================================================
698 //===========================================================================
699 MpfrFloat MpfrFloat::log(const MpfrFloat& value)
701 MpfrFloat retval(MpfrFloat::kNoInitialization);
702 mpfr_log(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
706 MpfrFloat MpfrFloat::log2(const MpfrFloat& value)
708 MpfrFloat retval(MpfrFloat::kNoInitialization);
709 mpfr_log2(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
713 MpfrFloat MpfrFloat::log10(const MpfrFloat& value)
715 MpfrFloat retval(MpfrFloat::kNoInitialization);
716 mpfr_log10(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
720 MpfrFloat MpfrFloat::exp(const MpfrFloat& value)
722 MpfrFloat retval(MpfrFloat::kNoInitialization);
723 mpfr_exp(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
727 MpfrFloat MpfrFloat::exp2(const MpfrFloat& value)
729 MpfrFloat retval(MpfrFloat::kNoInitialization);
730 mpfr_exp2(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
734 MpfrFloat MpfrFloat::exp10(const MpfrFloat& value)
736 MpfrFloat retval(MpfrFloat::kNoInitialization);
737 mpfr_exp10(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
741 MpfrFloat MpfrFloat::cos(const MpfrFloat& value)
743 MpfrFloat retval(MpfrFloat::kNoInitialization);
744 mpfr_cos(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
748 MpfrFloat MpfrFloat::sin(const MpfrFloat& value)
750 MpfrFloat retval(MpfrFloat::kNoInitialization);
751 mpfr_sin(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
755 MpfrFloat MpfrFloat::tan(const MpfrFloat& value)
757 MpfrFloat retval(MpfrFloat::kNoInitialization);
758 mpfr_tan(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
762 MpfrFloat MpfrFloat::sec(const MpfrFloat& value)
764 MpfrFloat retval(MpfrFloat::kNoInitialization);
765 mpfr_sec(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
769 MpfrFloat MpfrFloat::csc(const MpfrFloat& value)
771 MpfrFloat retval(MpfrFloat::kNoInitialization);
772 mpfr_csc(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
776 MpfrFloat MpfrFloat::cot(const MpfrFloat& value)
778 MpfrFloat retval(MpfrFloat::kNoInitialization);
779 mpfr_cot(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
783 void MpfrFloat::sincos(const MpfrFloat& value,
788 sin.mData->mFloat, cos.mData->mFloat, value.mData->mFloat, GMP_RNDN);
791 MpfrFloat MpfrFloat::acos(const MpfrFloat& value)
793 MpfrFloat retval(MpfrFloat::kNoInitialization);
794 mpfr_acos(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
798 MpfrFloat MpfrFloat::asin(const MpfrFloat& value)
800 MpfrFloat retval(MpfrFloat::kNoInitialization);
801 mpfr_asin(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
805 MpfrFloat MpfrFloat::atan(const MpfrFloat& value)
807 MpfrFloat retval(MpfrFloat::kNoInitialization);
808 mpfr_atan(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
812 MpfrFloat MpfrFloat::atan2(const MpfrFloat& value1, const MpfrFloat& value2)
814 MpfrFloat retval(MpfrFloat::kNoInitialization);
815 mpfr_atan2(retval.mData->mFloat,
816 value1.mData->mFloat, value2.mData->mFloat, GMP_RNDN);
820 MpfrFloat MpfrFloat::hypot(const MpfrFloat& value1, const MpfrFloat& value2)
822 MpfrFloat retval(MpfrFloat::kNoInitialization);
823 mpfr_hypot(retval.mData->mFloat,
824 value1.mData->mFloat, value2.mData->mFloat, GMP_RNDN);
828 MpfrFloat MpfrFloat::cosh(const MpfrFloat& value)
830 MpfrFloat retval(MpfrFloat::kNoInitialization);
831 mpfr_cosh(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
835 MpfrFloat MpfrFloat::sinh(const MpfrFloat& value)
837 MpfrFloat retval(MpfrFloat::kNoInitialization);
838 mpfr_sinh(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
842 MpfrFloat MpfrFloat::tanh(const MpfrFloat& value)
844 MpfrFloat retval(MpfrFloat::kNoInitialization);
845 mpfr_tanh(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
849 MpfrFloat MpfrFloat::acosh(const MpfrFloat& value)
851 MpfrFloat retval(MpfrFloat::kNoInitialization);
852 mpfr_acosh(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
856 MpfrFloat MpfrFloat::asinh(const MpfrFloat& value)
858 MpfrFloat retval(MpfrFloat::kNoInitialization);
859 mpfr_asinh(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
863 MpfrFloat MpfrFloat::atanh(const MpfrFloat& value)
865 MpfrFloat retval(MpfrFloat::kNoInitialization);
866 mpfr_atanh(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
870 MpfrFloat MpfrFloat::sqrt(const MpfrFloat& value)
872 MpfrFloat retval(MpfrFloat::kNoInitialization);
873 mpfr_sqrt(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
877 MpfrFloat MpfrFloat::cbrt(const MpfrFloat& value)
879 MpfrFloat retval(MpfrFloat::kNoInitialization);
880 mpfr_cbrt(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
884 MpfrFloat MpfrFloat::root(const MpfrFloat& value, unsigned long root)
886 MpfrFloat retval(MpfrFloat::kNoInitialization);
887 mpfr_root(retval.mData->mFloat, value.mData->mFloat, root, GMP_RNDN);
891 MpfrFloat MpfrFloat::pow(const MpfrFloat& value1, const MpfrFloat& value2)
893 MpfrFloat retval(MpfrFloat::kNoInitialization);
894 mpfr_pow(retval.mData->mFloat,
895 value1.mData->mFloat, value2.mData->mFloat, GMP_RNDN);
899 MpfrFloat MpfrFloat::pow(const MpfrFloat& value, long exponent)
901 MpfrFloat retval(MpfrFloat::kNoInitialization);
902 mpfr_pow_si(retval.mData->mFloat, value.mData->mFloat, exponent, GMP_RNDN);
906 MpfrFloat MpfrFloat::abs(const MpfrFloat& value)
908 MpfrFloat retval(MpfrFloat::kNoInitialization);
909 mpfr_abs(retval.mData->mFloat, value.mData->mFloat, GMP_RNDN);
913 MpfrFloat MpfrFloat::dim(const MpfrFloat& value1, const MpfrFloat& value2)
915 MpfrFloat retval(MpfrFloat::kNoInitialization);
916 mpfr_dim(retval.mData->mFloat,
917 value1.mData->mFloat, value2.mData->mFloat, GMP_RNDN);
921 MpfrFloat MpfrFloat::round(const MpfrFloat& value)
923 MpfrFloat retval(MpfrFloat::kNoInitialization);
924 mpfr_round(retval.mData->mFloat, value.mData->mFloat);
928 MpfrFloat MpfrFloat::ceil(const MpfrFloat& value)
930 MpfrFloat retval(MpfrFloat::kNoInitialization);
931 mpfr_ceil(retval.mData->mFloat, value.mData->mFloat);
935 MpfrFloat MpfrFloat::floor(const MpfrFloat& value)
937 MpfrFloat retval(MpfrFloat::kNoInitialization);
938 mpfr_floor(retval.mData->mFloat, value.mData->mFloat);
942 MpfrFloat MpfrFloat::trunc(const MpfrFloat& value)
944 MpfrFloat retval(MpfrFloat::kNoInitialization);
945 mpfr_trunc(retval.mData->mFloat, value.mData->mFloat);
949 MpfrFloat MpfrFloat::parseString(const char* str, char** endptr)
951 MpfrFloat retval(MpfrFloat::kNoInitialization);
952 mpfr_strtofr(retval.mData->mFloat, str, endptr, 0, GMP_RNDN);
956 MpfrFloat MpfrFloat::const_pi()
958 return mpfrFloatDataContainer().const_pi();
961 MpfrFloat MpfrFloat::const_e()
963 return mpfrFloatDataContainer().const_e();
966 MpfrFloat MpfrFloat::const_log2()
968 return mpfrFloatDataContainer().const_log2();
971 MpfrFloat MpfrFloat::someEpsilon()
973 return mpfrFloatDataContainer().const_epsilon();