@@ -1402,10 +1402,29 @@ namespace MiniZinc {
14021402 return true ;
14031403 }
14041404
1405- bool strtofloatval (const char * s, double & v) {
1406- std::istringstream iss (s);
1407- iss >> v;
1408- return !iss.fail ();
1405+ bool strtofloatval (void * parm, const char * s, double & val) {
1406+ MiniZinc::ParserState* pp =
1407+ static_cast <MiniZinc::ParserState*>(parm);
1408+ #if defined(_WIN32)
1409+ _locale_t c_loc = pp->cLocale ;
1410+ if (!c_loc) return false ;
1411+ errno = 0 ;
1412+ char * end = nullptr ;
1413+ val = _strtod_l (s, &end, c_loc);
1414+ #else
1415+ locale_t c_loc = pp->cLocale ;
1416+ if (!c_loc) return false ;
1417+ errno = 0 ;
1418+ char * end = nullptr ;
1419+ val = strtod_l (s, &end, c_loc);
1420+ #endif
1421+ if (end == s) return false ;
1422+ if (*end != ' \0 ' ) return false ;
1423+ if (!std::isfinite (val)) return false ;
1424+ if (errno != 0 && errno != ERANGE) {
1425+ return false ;
1426+ }
1427+ return true ;
14091428 }
14101429
14111430 void clearBuffer (void * parm) {
@@ -2041,7 +2060,7 @@ YY_RULE_SETUP
20412060case 26 :
20422061YY_RULE_SETUP
20432062{
2044- if (::MiniZinc::strtofloatval (yytext, yylval->dValue ))
2063+ if (::MiniZinc::strtofloatval (yyget_extra (yyscanner), yytext, yylval->dValue ))
20452064 return MZN_FLOAT_LITERAL;
20462065 else
20472066 return MZN_INVALID_FLOAT_LITERAL;
@@ -2083,7 +2102,7 @@ YY_RULE_SETUP
20832102case 31 :
20842103YY_RULE_SETUP
20852104{
2086- if (::MiniZinc::strtofloatval (yytext, yylval->dValue ))
2105+ if (::MiniZinc::strtofloatval (yyget_extra (yyscanner), yytext, yylval->dValue ))
20872106 return MZN_FLOAT_LITERAL;
20882107 else
20892108 return MZN_INVALID_FLOAT_LITERAL;
@@ -2092,7 +2111,7 @@ YY_RULE_SETUP
20922111case 32 :
20932112YY_RULE_SETUP
20942113{
2095- if (::MiniZinc::strtofloatval (yytext, yylval->dValue ))
2114+ if (::MiniZinc::strtofloatval (yyget_extra (yyscanner), yytext, yylval->dValue ))
20962115 return MZN_FLOAT_LITERAL;
20972116 else
20982117 return MZN_INVALID_FLOAT_LITERAL;
@@ -2101,7 +2120,7 @@ YY_RULE_SETUP
21012120case 33 :
21022121YY_RULE_SETUP
21032122{
2104- if (::MiniZinc::strtofloatval (yytext, yylval->dValue ))
2123+ if (::MiniZinc::strtofloatval (yyget_extra (yyscanner), yytext, yylval->dValue ))
21052124 return MZN_FLOAT_LITERAL;
21062125 else
21072126 return MZN_INVALID_FLOAT_LITERAL;
0 commit comments