You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by db...@apache.org on 2017/09/20 17:08:35 UTC

[03/10] incubator-trafodion git commit: rewrite double_to_char function

rewrite double_to_char function


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/dfd8af74
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/dfd8af74
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/dfd8af74

Branch: refs/heads/master
Commit: dfd8af74137739ba1c326ff2bf38edb5759cd171
Parents: b6513da
Author: SuJinpei <87...@qq.com>
Authored: Thu Sep 14 16:54:08 2017 +0800
Committer: SuJinpei <87...@qq.com>
Committed: Thu Sep 14 16:54:08 2017 +0800

----------------------------------------------------------------------
 win-odbc64/odbcclient/drvr35/drvrglobal.cpp | 77 +++---------------------
 1 file changed, 9 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dfd8af74/win-odbc64/odbcclient/drvr35/drvrglobal.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/drvrglobal.cpp b/win-odbc64/odbcclient/drvr35/drvrglobal.cpp
old mode 100644
new mode 100755
index 8d1124c..4012e4e
--- a/win-odbc64/odbcclient/drvr35/drvrglobal.cpp
+++ b/win-odbc64/odbcclient/drvr35/drvrglobal.cpp
@@ -865,77 +865,18 @@ bool use_gcvt(double number, char* string, short size)
 
 bool double_to_char (double number, int precision, char* string, short size)
 {
-	char *buffer,*temp ;
-	bool rc = true;
-
-	int	decimal_spot,
-		sign,
-		count,
-		current_location = 0,
-		length;
-
-	*string = 0;
-
-	temp = _fcvt (number, precision, &decimal_spot, &sign) ;
-	length = strlen(temp);
-	if (length == 0)
-	{
-		return use_gcvt(number,string,size);
-	}
-	if (length > precision)
-		buffer = (char *) malloc (length + 3) ;
-	else
-		buffer = (char *) malloc (precision + 3) ;
-
-	if (buffer == NULL)
-		return false;
-
-/* Add negative sign if required. */ 
-
-	if (sign)
-		buffer [current_location++] = '-' ;
-
-/* Place decimal point in the correct location. */ 
-
-	if (decimal_spot > 0)
-	{
-		strncpy (&buffer [current_location], temp, decimal_spot) ;
-		buffer [decimal_spot + current_location] = '.' ;
-		strcpy (&buffer [decimal_spot + current_location + 1],
-					&temp [decimal_spot]) ;
-	}
-	else
-	{
-		buffer [current_location] = '.' ;
-		for(count = current_location;
-			count< abs(decimal_spot)+current_location; count++)
-			buffer [count + 1] = '0' ;
-		strcpy (&buffer [count + 1], temp) ;
-	}
+    bool rc = false;
+    char format[16];
+    char buf[512];
 
-	rSup(buffer);
-	length = strlen(buffer);
-	if (buffer[0] == '.' || (buffer[0] == '-' && buffer[1] == '.')) length++;
+    sprintf(format, "%%.%dl%c", precision, number < 1e-6 ? 'g':'f');
+    sprintf(buf, format, number);
 
-	if (length>size)
-		rc = use_gcvt(number,string,size);
-	else
-	{
-		if (buffer[0] == '.')
-		{
-			strcpy( string, "0");
-			strcat( string, buffer);
-		}
-		else if (buffer[0] == '-' && buffer[1] == '.')
-		{
-			strcpy( string, "-0");
-			strcat( string, &buffer[1]);
-		}
-		else
-			strcpy( string, buffer);
-	}
+    if (size > strlen(buf)) {
+        strcpy(string, buf);
+        rc = true;
+    }
 
-	free (buffer);
 	return rc;
 }