diff --git a/common/libeval/numeric_evaluator.cpp b/common/libeval/numeric_evaluator.cpp index 8f7be2ca8f..a70bf915d1 100644 --- a/common/libeval/numeric_evaluator.cpp +++ b/common/libeval/numeric_evaluator.cpp @@ -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 ); + } } diff --git a/qa/common/libeval/test_numeric_evaluator.cpp b/qa/common/libeval/test_numeric_evaluator.cpp index 3eeb9aef97..6128810377 100644 --- a/qa/common/libeval/test_numeric_evaluator.cpp +++ b/qa/common/libeval/test_numeric_evaluator.cpp @@ -117,7 +117,7 @@ static const std::vector 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