1800{
1801
1802 (void)b;
1803 (void)mode;
1804
1805#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1806
1807 std::ostringstream format;
1808
1810
1811 format << "%." << digits << "RNg";
1812
1814
1815#else
1816
1817 char *
s, *ns = NULL;
1818 size_t slen, nslen;
1820 std::string out;
1821
1822 if(mpfr_inf_p(mp))
1823 {
1824 if(mpfr_sgn(mp)>0) return "+Inf";
1825 else return "-Inf";
1826 }
1827
1828 if(mpfr_zero_p(mp)) return "0";
1829 if(mpfr_nan_p(mp)) return "NaN";
1830
1831 s = mpfr_get_str(NULL, &exp, b, 0, mp, mode);
1832 ns = mpfr_get_str(NULL, &exp, b, (std::max)(0,n), mp, mode);
1833
1834 if(
s!=NULL && ns!=NULL)
1835 {
1837 nslen = strlen(ns);
1838 if(nslen<=slen)
1839 {
1842 slen = nslen;
1843 }
1844 else {
1845 mpfr_free_str(ns);
1846 }
1847
1848
1849 if (exp>0 && static_cast<size_t>(exp)<slen)
1850 {
1852 {
1853
1854 char* ptr =
s+slen-1;
1855 while (*ptr==
'0' && ptr>
s+exp) ptr--;
1856
1857 if(ptr==
s+exp) out = std::string(
s,exp+1);
1858 else out = std::string(
s,exp+1)+
'.'+std::string(
s+exp+1,ptr-(
s+exp+1)+1);
1859
1860
1861 }
1862 else
1863 {
1864
1865 char* ptr =
s+slen-1;
1866 while (*ptr==
'0' && ptr>
s+exp-1) ptr--;
1867
1868 if(ptr==
s+exp-1) out = std::string(
s,exp);
1869 else out = std::string(
s,exp)+
'.'+std::string(
s+exp,ptr-(
s+exp)+1);
1870
1871
1872 }
1873
1874 }else{
1876 {
1877
1878 char* ptr =
s+slen-1;
1879 while (*ptr==
'0' && ptr>
s+1) ptr--;
1880
1881 if(ptr==
s+1) out = std::string(
s,2);
1882 else out = std::string(
s,2)+
'.'+std::string(
s+2,ptr-(
s+2)+1);
1883
1884
1885 }
1886 else
1887 {
1888
1889 char* ptr =
s+slen-1;
1890 while (*ptr==
'0' && ptr>
s) ptr--;
1891
1892 if(ptr==
s) out = std::string(
s,1);
1893 else out = std::string(
s,1)+
'.'+std::string(
s+1,ptr-(
s+1)+1);
1894
1895
1896 }
1897
1898
1899 if(--exp)
1900 {
1901 if(exp>0) out += "e+"+mpfr::toString<mp_exp_t>(exp,std::dec);
1902 else out += "e"+mpfr::toString<mp_exp_t>(exp,std::dec);
1903 }
1904 }
1905
1907 return out;
1908 }else{
1909 return "conversion error!";
1910 }
1911#endif
1912}
::mpfr_srcptr mpfr_srcptr() const
friend const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
std::ostringstream & toString(std::ostringstream &o, int len, int *p)
int bits2digits(mp_prec_t b)