From cbe358c2b43961734711e1c3ee2c506b1434c8f3 Mon Sep 17 00:00:00 2001 From: valmat Date: Mon, 15 Dec 2014 22:54:12 +0600 Subject: Fixed issue #149 --- tests/cpp/include/doubl2str.h | 98 +++---------------------------------------- 1 file changed, 6 insertions(+), 92 deletions(-) diff --git a/tests/cpp/include/doubl2str.h b/tests/cpp/include/doubl2str.h index 1a5e3fc..66f2b86 100644 --- a/tests/cpp/include/doubl2str.h +++ b/tests/cpp/include/doubl2str.h @@ -4,99 +4,13 @@ * */ - - -char num2char(unsigned int num) +#include +#include +std::string double2str(long double d) { - switch(num) - { - case 0: - return '0'; - case 1: - return '1'; - case 2: - return '2'; - case 3: - return '3'; - case 4: - return '4'; - case 5: - return '5'; - case 6: - return '6'; - case 7: - return '7'; - case 8: - return '8'; - case 9: - return '9'; - } - - //return '\0'; - return '-'; -} - -std::string double2str(long double D) -{ - int sign = (D > 0) ? 1 : (D*=-1.0, -1); - unsigned long long int Ceil = D; - - // if D is ceil - if(Ceil == D) - { - return std::to_string( (long long)(D*sign) ); - } - - // size of result buffer - const int bs = 32; - - // size of temporary buffer - const int pw = 16; - // Temporary buffer - char buf[pw]; - // Result buffer - char rez[bs]; - - int i, size = 0; - // set sign - if(sign < 0) rez[size++] = '-'; - - // set ceil - std::string sceil = std::to_string(Ceil); - const char * bceil = sceil.c_str(); - int sceillen = sceil.size(); - for(i = 0; i < sceillen; i++) - { - rez[size++] = bceil[i]; - } - - // set point - rez[size++] = '.'; - - unsigned long long int I = D * 10000000000000000; // D * 10**pw - // .14159265359 -> 14159265359000000 - I -= Ceil * 10000000000000000; - - // Remove the tail of zeros - // 14159265359000000 -> 14159265359 - while(0 == I % 10) I /= 10; - - int ind = 0; - while(I > 0) - { - buf[ind++] = num2char(I%10); - I = (I - I%10) / 10; - } - - // set fraction part - for(i = 0; i < ind; i++) - { - rez[size] = buf[ind-i-1]; - size++; - } - - return std::string(rez, size); - //rez[size] = '\0'; + std::ostringstream strs; + strs << std::setprecision(16) << d; + return strs.str(); } -- cgit v1.2.3 From 7b8b787e2b9f2be9d36476aff7c2a25ea5023e91 Mon Sep 17 00:00:00 2001 From: valmat Date: Tue, 16 Dec 2014 18:44:40 +0600 Subject: issue #149 fixed Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 93e22af..5f552e7 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ PHP_BIN = $(shell ${PHP_CONFIG} --php-binary) INSTALL_PREFIX = /usr INSTALL_HEADERS = ${INSTALL_PREFIX}/include -INSTALL_LIB = ${INSTALL_PREFIX}/lib +INSTALL_LIB = $(shell cat /etc/ld.so.conf.d/libc.conf | grep -v "\#" | head -1) # -- cgit v1.2.3