diff --git a/Number_types/doc_tex/NumberTypeSupport_ref/Gmpfr.tex b/Number_types/doc_tex/NumberTypeSupport_ref/Gmpfr.tex index 57a67058ad8..3b9b396b0a4 100644 --- a/Number_types/doc_tex/NumberTypeSupport_ref/Gmpfr.tex +++ b/Number_types/doc_tex/NumberTypeSupport_ref/Gmpfr.tex @@ -73,7 +73,7 @@ This type is \ccc{ImplicitInteroperable} with \ccc{Gmpz}, \verb-long-, \ccConstructor{Gmpfr(const Gmpzf &zf);} {Creates a \ccc{Gmpfr}, initialized with the value of \ccc{zf}.} -\ccConstructor{Gmpfr(std::pair ie);} +\ccConstructor{Gmpfr(const std::pair &ie);} {Creates a \ccc{Gmpfr}, initialized with the value of \( ie.first \times 2^{ie.second} \) .} @@ -331,8 +331,8 @@ the compared numbers is \ccc{NaN}, the \ccc{erange} flag is set. \ccMethod{bool is_square(const Gmpfr &y);} {Returns \ccc{true} iff \ccVar~is the square of a number - representable by an object of this type, calculating it and storing - it in \ccc{y}.} + representable by an object of this type, computing and storing it + in \ccc{y}.} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -348,7 +348,7 @@ the compared numbers is \ccc{NaN}, the \ccc{erange} flag is set. \ccFunction{std::ostream& operator<<(std::ostream& out, const Gmpfr& f);} {If the ostream \ccc{out} is in pretty-print mode, writes a decimal - approximatin of \ccc{f} to \ccc{out}. Otherwise, writes \ccc{f} to + approximation of \ccc{f} to \ccc{out}. Otherwise, writes \ccc{f} to \ccc{out} in the form \(MeE\), where \(M\) is its mantissa and \(E\) is its exponent, both in base 10.} diff --git a/Number_types/include/CGAL/GMP/Gmpfr_type.h b/Number_types/include/CGAL/GMP/Gmpfr_type.h index b476850aa10..863a551988f 100644 --- a/Number_types/include/CGAL/GMP/Gmpfr_type.h +++ b/Number_types/include/CGAL/GMP/Gmpfr_type.h @@ -255,7 +255,7 @@ class Gmpfr: } } - Gmpfr(Gmpzf f, + Gmpfr(const Gmpzf &f, std::float_round_style r, Gmpfr::Precision_type p=Gmpfr::get_default_precision()){ CGAL_assertion(p>=MPFR_PREC_MIN&&p<=MPFR_PREC_MAX); @@ -264,7 +264,7 @@ class Gmpfr: mpfr_mul_2si(fr(),fr(),f.exp(),_gmp_rnd(r)); } - Gmpfr(Gmpzf f,Gmpfr::Precision_type p){ + Gmpfr(const Gmpzf &f,Gmpfr::Precision_type p){ CGAL_assertion(p>=MPFR_PREC_MIN&&p<=MPFR_PREC_MAX); mpfr_init2(fr(),p); mpfr_set_z(fr(),f.man(),mpfr_get_default_rounding_mode()); @@ -274,7 +274,7 @@ class Gmpfr: mpfr_get_default_rounding_mode()); } - Gmpfr(Gmpzf f){ + Gmpfr(const Gmpzf &f){ mpfr_init2(fr(), static_cast( mpz_sizeinbase(f.man(),2) intexp, + Gmpfr(const std::pair &intexp, std::float_round_style r=Gmpfr::get_default_rndmode(), Gmpfr::Precision_type p=Gmpfr::get_default_precision()){ CGAL_assertion(p>=MPFR_PREC_MIN&&p<=MPFR_PREC_MAX); @@ -297,7 +297,7 @@ class Gmpfr: mpfr_mul_2si(fr(),fr(),intexp.second,_gmp_rnd(r)); } - Gmpfr(std::pair intexp,Gmpfr::Precision_type p){ + Gmpfr(const std::pair &intexp,Gmpfr::Precision_type p){ CGAL_assertion(p>=MPFR_PREC_MIN&&p<=MPFR_PREC_MAX); mpfr_init2(fr(),p); mpfr_set_z(fr(), diff --git a/Number_types/test/Number_types/Gmpfr.cpp b/Number_types/test/Number_types/Gmpfr.cpp index 0412939457f..e1c1b5d0f96 100644 --- a/Number_types/test/Number_types/Gmpfr.cpp +++ b/Number_types/test/Number_types/Gmpfr.cpp @@ -116,15 +116,26 @@ int test_to_integer_exp(CGAL::Gmpfr f){ } } +// This function checks equality between an _NT x and a Gmpfr y. template -int test_constructors(_NT x){ +int are_different(const _NT &x,const CGAL::Gmpfr &y){ + return x!=y; +} + +template<> +int are_different(const std::pair &x,const CGAL::Gmpfr &y){ + return(mpfr_cmp_si_2exp(y.fr(),mpz_get_si(x.first.mpz()),x.second)); +} + +template +int test_constructors(const _NT &x){ typedef CGAL::Gmpfr Gmpfr; typedef _NT NT; bool fail=false; Gmpfr::set_default_precision(70); Gmpfr f(x); // this conversion should be exact - if(f!=x){ + if(are_different(x,f)){ std::cerr<<"failed default construction! (inexact)"<((CGAL::Gmpz(1)<<1000)+CGAL::Gmpz(1));) _TEST("constructors Gmpzf",test_constructors(1025);) + typedef std::pair MantExp; + _TEST("constructors pair", + test_constructors(std::make_pair(CGAL::Gmpz(4096),35));) _TEST("operators Gmpfr",test_operators();) _TEST("operators Gmpzf",test_operators();)