Skip to content

Commit

Permalink
problem_settings: fix float regex
Browse files Browse the repository at this point in the history
A missing `*` was unfortunately not caught during review. Added a
regression test.
  • Loading branch information
Riolku committed Dec 29, 2024
1 parent 549d173 commit c901da9
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ long long readInt(long long lo, long long hi) {

long double readFloat(long double min, long double max,
long double eps = 1e-9) {
static regex_t re = regex_helpers::compile("^-?(0|[1-9][0-9])(\\.[0-9]+)?$");
static regex_t re = regex_helpers::compile("^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$");
std::string token = readToken();
assertWA(regex_helpers::match(re, token));
long double parsedDouble;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ long long readInt(long long lo, long long hi) {

long double readFloat(long double min, long double max,
long double eps = 1e-9) {
static regex_t re = regex_helpers::compile("^-?(0|[1-9][0-9])(\\.[0-9]+)?$");
static regex_t re = regex_helpers::compile("^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$");
std::string token = readToken();
assertWA(regex_helpers::match(re, token));
long double parsedDouble;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
1.76
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.76
2 changes: 1 addition & 1 deletion sample_files/problem_setting/validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ long long readInt(long long lo, long long hi) {

long double readFloat(long double min, long double max,
long double eps = 1e-9) {
static regex_t re = regex_helpers::compile("^-?(0|[1-9][0-9])(\\.[0-9]+)?$");
static regex_t re = regex_helpers::compile("^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$");
std::string token = readToken();
assert(regex_helpers::match(re, token));
long double parsedDouble = stold(token); // May throw.
Expand Down

0 comments on commit c901da9

Please sign in to comment.