Libeval: consistent formatting for NaN
On some platforms like MSVC, NaN prints as "-nan(ind)". This
is a bit needlessly ugly, so print "NaN" on all platforms
consistently.
This fixes a test failure on MSVC.
(cherry picked from commit dd17f24c04
)
This commit is contained in:
parent
fd698653d9
commit
322524101d
|
@ -104,7 +104,17 @@ void NUMERIC_EVALUATOR::parseOk()
|
|||
|
||||
void NUMERIC_EVALUATOR::parseSetResult( double val )
|
||||
{
|
||||
snprintf( m_token.token, m_token.OutLen, "%.10g", val );
|
||||
if( std::isnan( val ) )
|
||||
{
|
||||
// Naively printing this with %g produces "nan" on some platforms
|
||||
// and "-nan(ind)" on others (e.g. MSVC). So force a "standard" string.
|
||||
snprintf( m_token.token, m_token.OutLen, "%s", "NaN" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Can be printed as a floating point
|
||||
snprintf( m_token.token, m_token.OutLen, "%.10g", val );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ static const std::vector<EVAL_CASE> eval_cases_valid = {
|
|||
{ "1.5", "1.5" },
|
||||
{ "1,5", "1.5" },
|
||||
// Semicolon is valid, but the result is NaN
|
||||
{ "1;", "nan" },
|
||||
{ "1;", "NaN" },
|
||||
// With own unit
|
||||
{ "1mm", "1" },
|
||||
// Unit that's not the evaluator's unit
|
||||
|
|
Loading…
Reference in New Issue