From 0da005ddae2d5686d82a337d571fb61eabf0d6ba Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 3 Oct 2016 21:03:07 +0100 Subject: [PATCH] MCOL-328 Fix func float -> str conversion Functions such as reverse() that do float/double to string conversion use printf's %g to do it. Unfortunately this adds a '+' symbol before the exponent symbol. MariaDB doesn't do this. This patch builds the string in a way that does not have that problem, it resembles the way it is done elsewhere in the codebase. --- utils/funcexp/functor_str.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/utils/funcexp/functor_str.h b/utils/funcexp/functor_str.h index 939727286..ab6f3631e 100644 --- a/utils/funcexp/functor_str.h +++ b/utils/funcexp/functor_str.h @@ -90,22 +90,37 @@ protected: // Bug3788, use the shorter of fixed or scientific notation for floating point values. // [ the default format in treenode.h is fixed-point notation ] char buf[20]; + double floatVal; + int exponent; + double base; switch (fp->data()->resultType().colDataType) { case execplan::CalpontSystemCatalog::DOUBLE: - snprintf(buf, 20, "%.10g", fp->data()->getDoubleVal(row, isNull)); - break; - + floatVal = fp->data()->getDoubleVal(row, isNull); + break; case execplan::CalpontSystemCatalog::FLOAT: - snprintf(buf, 20, "%g", fp->data()->getFloatVal(row, isNull)); - break; + floatVal = fp->data()->getFloatVal(row, isNull); + break; default: return fp->data()->getStrVal(row, isNull); break; } + exponent = (int)floor(log10( fabs(floatVal))); + base = floatVal * pow(10, -1.0*exponent); + if (isnan(exponent) || isnan(base)) + { + snprintf(buf, 20, "%f", floatVal); + fFloatStr = execplan::removeTrailing0(buf, 20); + } + else + { + snprintf(buf, 20, "%.5f", base); + fFloatStr = execplan::removeTrailing0(buf, 20); + snprintf(buf, 20, "e%02d", exponent); + fFloatStr += buf; + } - fFloatStr = std::string(buf); return fFloatStr; }