Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions lib/lexer.lxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

%top{
#include <cstdint>
#include <cerrno>
#include <cstdlib>
}

%{
Expand Down Expand Up @@ -101,9 +103,28 @@ namespace MiniZinc {
}

bool strtofloatval(const char* s, double& v) {
std::istringstream iss(s);
iss >> v;
return !iss.fail();
char* endptr;
errno = 0;
v = std::strtod(s, &endptr);

// Check if the entire string was consumed
if (*endptr != '\0') {
return false;
}

// Check for overflow or underflow
if (errno == ERANGE) {
// ERANGE can indicate overflow to infinity or underflow to zero
// Both are valid floating point representations, so we accept them
return true;
}

// Any other errno value indicates an error
if (errno != 0) {
return false;
}

return true;
}

void clearBuffer(void* parm) {
Expand Down