Skip to content
Permalink
Browse files

Fix #607, output 8 digits on floats when 6 is not enough to be precise.

  • Loading branch information...
klirichek committed Jan 31, 2019
1 parent 1068f45 commit 266e0e7b088549722a805fc837bf101ff681a5e8
@@ -11816,11 +11816,13 @@ class SqlRowBuffer_c : public ISphNoncopyable, public IDataTupleter, private Laz

using BaseVec::Add;

void PutFloatAsString ( float fVal, const char * sFormat = "%f" )
void PutFloatAsString ( float fVal, const char * sFormat = nullptr )
{
ReserveGap ( SPH_MAX_NUMERIC_STR );
auto pSize = End();
int iLen = snprintf ( ( char * )pSize+1, SPH_MAX_NUMERIC_STR-1, sFormat, fVal );
int iLen = sFormat
? snprintf (( char* ) pSize + 1, SPH_MAX_NUMERIC_STR - 1, sFormat, fVal )
: sph::PrintVarFloat (( char* ) pSize + 1, fVal );
*pSize = BYTE ( iLen );
AddN ( iLen + 1 );
}
@@ -2365,15 +2365,27 @@ void vSprintf_T ( PCHAR * _pOutput, const char * sFmt, va_list ap )
{
double fValue = va_arg ( ap, double );

// ensure 32 is enough to take any float value.
Grow ( pOutput, Max ( iWidth, ( size_t ) 32 ));

// extract current format from source format line
char sFormat[32] = {0};
auto *pF = sFmt;
while ( *--pF!='%' );
memcpy ( sFormat, pF, sFmt-pF );

// invoke standard sprintf
Grow ( pOutput, Max ( iWidth, (size_t)32 ) ); // ensure 32 is enough to take any flow value.
pOutput += sprintf ( tail ( pOutput ), sFormat, fValue );
if ( memcmp ( pF, "%f", 2 )!=0 )
{

// invoke standard sprintf
char sFormat[32] = { 0 };
memcpy ( sFormat, pF, sFmt - pF );
pOutput += sprintf ( tail ( pOutput ), sFormat, fValue );
} else
{
// plain %f - output arbitrary 6 or 8 digits
pOutput += PrintVarFloat ( tail ( pOutput ), fValue );
assert (( sFmt - pF )==2 );
}

state = SNORMAL;
break;
}
@@ -2419,6 +2431,15 @@ void vSprintf_T ( PCHAR * _pOutput, const char * sFmt, va_list ap )
va_end ( ap );
}

int PrintVarFloat ( char* sBuffer, float fVal )
{
int iLen = sprintf ( sBuffer, "%f", fVal );
auto fTest = strtof ( sBuffer, nullptr );
if ( fTest!=fVal )
return sprintf ( sBuffer, "%1.8f", fVal );
return iLen;
}

} // namespace sph

static int sphVSprintf ( char * pOutput, const char * sFmt, va_list ap )
@@ -83,6 +83,10 @@ namespace sph {
int Sprintf ( char * pOutput, const char * sFmt, ... );
void vSprintf ( StringBuilder_c &pOutput, const char * sFmt, va_list ap );
void Sprintf ( StringBuilder_c& pOutput, const char * sFmt, ...);

/// output fVal with arbitrary 6 or 8 digits
/// ensure that sBuffer has enough space to fit fVal!
int PrintVarFloat ( char* sBuffer, float fVal );
}

/// string splitter, extracts sequences of alphas (as in sphIsAlpha)

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1 +1 @@
a:1:{i:0;a:1:{i:0;a:3:{s:8:"sphinxql";s:131:"SELECT id, packedfactors() p FROM test1 WHERE MATCH ('(test1 test3 test4 test4 test7) (test1 test2 test7)') OPTION ranker=expr('1')";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:2:"id";s:1:"1";s:1:"p";s:448:"bm25=427, bm25a=0.378080, field_mask=1, doc_word_count=5, field0=(lcs=2, hit_count=5, word_count=5, tf_idf=-0.158496, min_idf=-0.079248, max_idf=0.000000, sum_idf=-0.158496, min_hit_pos=1, min_best_span_pos=1, exact_hit=0, max_window_hits=1, min_gaps=2, exact_order=1, lccs=2, wlccs=0.000000, atc=0.002182), word0=(tf=1, idf=-0.079248), word1=(tf=1, idf=0.000000), word2=(tf=1, idf=0.000000), word4=(tf=1, idf=-0.079248), word6=(tf=1, idf=0.000000)";}}}}}
a:1:{i:0;a:1:{i:0;a:3:{s:8:"sphinxql";s:131:"SELECT id, packedfactors() p FROM test1 WHERE MATCH ('(test1 test3 test4 test4 test7) (test1 test2 test7)') OPTION ranker=expr('1')";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:2:"id";s:1:"1";s:1:"p";s:462:"bm25=427, bm25a=0.37807980, field_mask=1, doc_word_count=5, field0=(lcs=2, hit_count=5, word_count=5, tf_idf=-0.15849625, min_idf=-0.07924812, max_idf=0.000000, sum_idf=-0.15849625, min_hit_pos=1, min_best_span_pos=1, exact_hit=0, max_window_hits=1, min_gaps=2, exact_order=1, lccs=2, wlccs=0.000000, atc=0.00218189), word0=(tf=1, idf=-0.07924812), word1=(tf=1, idf=0.000000), word2=(tf=1, idf=0.000000), word4=(tf=1, idf=-0.07924812), word6=(tf=1, idf=0.000000)";}}}}}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1 +1 @@
a:1:{i:0;a:31:{i:0;a:2:{s:8:"sphinxql";s:116:"INSERT INTO rt1 (id, idd, body) VALUES ( 1, 11, 'The role of a software tester in an Agile environment goes beyond')";s:14:"total_affected";i:1;}i:1;a:2:{s:8:"sphinxql";s:106:"INSERT INTO rt1 (id, idd, body) VALUES ( 2, 11, 'paint coating is to be tested with a wet sponge tester' )";s:14:"total_affected";i:1;}i:2;a:2:{s:8:"sphinxql";s:81:"INSERT INTO rt1 (id, idd, body) VALUES ( 3, 11, 'technical tester builds tools' )";s:14:"total_affected";i:1;}i:3;a:2:{s:8:"sphinxql";s:70:"INSERT INTO rt1 (id, idd, body) VALUES ( 4, 11, 'aquia magic rester' )";s:14:"total_affected";i:1;}i:4;a:2:{s:8:"sphinxql";s:93:"INSERT INTO rt1 (id, idd, body) VALUES ( 5, 11, 'pharma exec arrested for securities fraud' )";s:14:"total_affected";i:1;}i:5;a:2:{s:8:"sphinxql";s:93:"INSERT INTO rt1 (id, idd, body) VALUES ( 6, 11, 'was arrested for stealing a tester bottle' )";s:14:"total_affected";i:1;}i:6;a:2:{s:8:"sphinxql";s:84:"INSERT INTO rt1 (id, idd, body) VALUES ( 7, 11, 'star allegedly tells drug tester' )";s:14:"total_affected";i:1;}i:7;a:2:{s:8:"sphinxql";s:98:"INSERT INTO rt1 (id, idd, body) VALUES ( 10, 22, 'С благодарностью к своим' )";s:14:"total_affected";i:1;}i:8;a:2:{s:8:"sphinxql";s:96:"INSERT INTO rt1 (id, idd, body) VALUES ( 11, 22, 'с благодарностью за все' )";s:14:"total_affected";i:1;}i:9;a:2:{s:8:"sphinxql";s:119:"INSERT INTO rt1 (id, idd, body) VALUES ( 12, 22, 'его к поощрению благодарностью всех' )";s:14:"total_affected";i:1;}i:10;a:2:{s:8:"sphinxql";s:122:"INSERT INTO rt1 (id, idd, body) VALUES ( 13, 22, 'письма благодарности героям прошлого' )";s:14:"total_affected";i:1;}i:11;a:2:{s:8:"sphinxql";s:107:"INSERT INTO rt1 (id, idd, body) VALUES ( 14, 22, 'его благодарность неизвестна' )";s:14:"total_affected";i:1;}i:12;a:2:{s:8:"sphinxql";s:108:"INSERT INTO rt1 (id, idd, body) VALUES ( 15, 22, 'написать e-mail с благодарностью' )";s:14:"total_affected";i:1;}i:13;a:3:{s:8:"sphinxql";s:34:"CALL SUGGEST ( 'taster', 'plain1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"1";s:4:"docs";s:1:"5";}i:1;a:3:{s:7:"suggest";s:6:"tested";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}}}i:14;a:3:{s:8:"sphinxql";s:31:"CALL SUGGEST ( 'taster', 'rt1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"1";s:4:"docs";s:1:"5";}i:1;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:6:"tested";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}}}i:15;a:3:{s:8:"sphinxql";s:54:"CALL SUGGEST ( 'благодраность', 'plain1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:26:"благодарность";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:1;a:3:{s:7:"suggest";s:28:"благодарностью";s:8:"distance";s:1:"3";s:4:"docs";s:1:"4";}i:2;a:3:{s:7:"suggest";s:26:"благодарности";s:8:"distance";s:1:"3";s:4:"docs";s:1:"1";}}}i:16;a:3:{s:8:"sphinxql";s:51:"CALL SUGGEST ( 'благодраность', 'rt1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:26:"благодарность";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:1;a:3:{s:7:"suggest";s:28:"благодарностью";s:8:"distance";s:1:"3";s:4:"docs";s:1:"4";}i:2;a:3:{s:7:"suggest";s:26:"благодарности";s:8:"distance";s:1:"3";s:4:"docs";s:1:"1";}}}i:17;a:3:{s:8:"sphinxql";s:64:"CALL QSUGGEST ( 'tests passed well because of taster', 'plain1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"1";s:4:"docs";s:1:"5";}i:1;a:3:{s:7:"suggest";s:6:"tested";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}}}i:18;a:3:{s:8:"sphinxql";s:61:"CALL QSUGGEST ( 'tests passed well because of taster', 'rt1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"1";s:4:"docs";s:1:"5";}i:1;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:6:"tested";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}}}i:19;a:3:{s:8:"sphinxql";s:81:"CALL QSUGGEST ( 'с превеликой благодраностью', 'plain1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:28:"благодарностью";s:8:"distance";s:1:"2";s:4:"docs";s:1:"4";}i:1;a:3:{s:7:"suggest";s:26:"благодарность";s:8:"distance";s:1:"3";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:26:"благодарности";s:8:"distance";s:1:"4";s:4:"docs";s:1:"1";}}}i:20;a:3:{s:8:"sphinxql";s:78:"CALL QSUGGEST ( 'с превеликой благодраностью', 'rt1')";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:7:"suggest";s:28:"благодарностью";s:8:"distance";s:1:"2";s:4:"docs";s:1:"4";}i:1;a:3:{s:7:"suggest";s:26:"благодарность";s:8:"distance";s:1:"3";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:26:"благодарности";s:8:"distance";s:1:"4";s:4:"docs";s:1:"1";}}}i:21;a:2:{s:8:"sphinxql";s:116:"INSERT INTO rt2 (id, idd, body) VALUES ( 1, 11, 'The role of a software tester in an Agile environment goes beyond')";s:14:"total_affected";i:1;}i:22;a:2:{s:8:"sphinxql";s:70:"INSERT INTO rt2 (id, idd, body) VALUES ( 4, 11, 'aquia magic rester' )";s:14:"total_affected";i:1;}i:23;a:2:{s:8:"sphinxql";s:93:"INSERT INTO rt2 (id, idd, body) VALUES ( 6, 11, 'was arrested for stealing a tester bottle' )";s:14:"total_affected";i:1;}i:24;a:3:{s:8:"sphinxql";s:34:"CALL SUGGEST ( 'taster', 'plain2')";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"1";s:4:"docs";s:1:"2";}i:1;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}}}i:25;a:3:{s:8:"sphinxql";s:31:"CALL SUGGEST ( 'taster', 'rt2')";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"1";s:4:"docs";s:1:"2";}i:1;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}}}i:26;a:2:{s:8:"sphinxql";s:79:"INSERT INTO rt1 (id, idd, body) VALUES ( 21, 11, '#test from bunch of tester' )";s:14:"total_affected";i:1;}i:27;a:2:{s:8:"sphinxql";s:77:"INSERT INTO rt1 (id, idd, body) VALUES ( 22, 11, '#test passed for #taster' )";s:14:"total_affected";i:1;}i:28;a:2:{s:8:"sphinxql";s:77:"INSERT INTO rt1 (id, idd, body) VALUES ( 23, 11, '#test #tests passes well' )";s:14:"total_affected";i:1;}i:29;a:3:{s:8:"sphinxql";s:31:"CALL SUGGEST ( '#trest', 'rt1')";s:10:"total_rows";i:5;s:4:"rows";a:5:{i:0;a:3:{s:7:"suggest";s:4:"test";s:8:"distance";s:1:"2";s:4:"docs";s:1:"3";}i:1;a:3:{s:7:"suggest";s:5:"tests";s:8:"distance";s:1:"3";s:4:"docs";s:1:"1";}i:2;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"4";s:4:"docs";s:1:"6";}i:3;a:3:{s:7:"suggest";s:8:"arrested";s:8:"distance";s:1:"4";s:4:"docs";s:1:"2";}i:4;a:3:{s:7:"suggest";s:6:"rester";s:8:"distance";s:1:"4";s:4:"docs";s:1:"1";}}}i:30;a:3:{s:8:"sphinxql";s:47:"CALL SUGGEST ( '#trest', 'rt1', 1 as non_char )";s:10:"total_rows";i:5;s:4:"rows";a:5:{i:0;a:3:{s:7:"suggest";s:5:"#test";s:8:"distance";s:1:"1";s:4:"docs";s:1:"3";}i:1;a:3:{s:7:"suggest";s:4:"test";s:8:"distance";s:1:"2";s:4:"docs";s:1:"3";}i:2;a:3:{s:7:"suggest";s:6:"#tests";s:8:"distance";s:1:"2";s:4:"docs";s:1:"1";}i:3;a:3:{s:7:"suggest";s:5:"tests";s:8:"distance";s:1:"3";s:4:"docs";s:1:"1";}i:4;a:3:{s:7:"suggest";s:6:"tester";s:8:"distance";s:1:"4";s:4:"docs";s:1:"6";}}}}}
a:0:{}
Oops, something went wrong.

0 comments on commit 266e0e7

Please sign in to comment.
You can’t perform that action at this time.