summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-12-30 08:59:49 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-12-30 08:59:49 +0100
commitcd2284df9dbecff9dafb0dea1b176b2d5934356f (patch)
tree0084366dd5f7bad6d9b61bf8190002dd24020a6d
parent38135ce4ab49c06799df08cfff4bc8d6f67e5fc7 (diff)
parent7b8b787e2b9f2be9d36476aff7c2a25ea5023e91 (diff)
Merge pull request #152 from valmat/issue149
Fix Issue149
-rw-r--r--Makefile2
-rw-r--r--tests/cpp/include/doubl2str.h98
2 files changed, 7 insertions, 93 deletions
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)
#
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 <sstream>
+#include <iomanip>
+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();
}