mirror of https://github.com/CGAL/cgal
Instead of letting mpq_get_str(..) allocate memory we allocate/deallocate it ourselves
This commit is contained in:
parent
808e0a0042
commit
1114dc98fb
|
|
@ -308,9 +308,13 @@ public:
|
|||
return mpq_set_str(get_mp(), s, base);
|
||||
}
|
||||
/// convert to <tt>std::string</tt>
|
||||
std::string get_str(int base = 10) const {
|
||||
_alloc_cstr t(mpq_get_str(0, base, get_mp()));
|
||||
return std::string(t.str);
|
||||
std::string get_str(int base Bi= 10) const {
|
||||
int n = mpz_sizeinbase(mpq_numref(get_mp()), base) + mpz_sizeinbase(mpq_denref(get_mp()), base)+ 3;
|
||||
char *buffer = new char[n];
|
||||
mpq_get_str(buffer, base, get_mp());
|
||||
std::string result(buffer);
|
||||
delete [] buffer;
|
||||
return result;
|
||||
}
|
||||
//@}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue