Merge pull request #193 from fastfloat/issue_191

We need to update some of our exhaustive tests to the new API
This commit is contained in:
Daniel Lemire 2023-04-02 19:44:03 -04:00 committed by GitHub
commit f34e880ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 81 additions and 53 deletions

View File

@ -30,7 +30,10 @@ void allvalues() {
const char *string_end = to_string(v, buffer); const char *string_end = to_string(v, buffer);
float result_value; float result_value;
auto result = fast_float::from_chars(buffer, string_end, result_value); auto result = fast_float::from_chars(buffer, string_end, result_value);
if (result.ec != std::errc()) { // Starting with version 4.0 for fast_float, we return result_out_of_range if the
// value is either too small (too close to zero) or too large (effectively infinity).
// So std::errc::result_out_of_range is normal for well-formed input strings.
if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << "parsing error ? " << buffer << std::endl; std::cerr << "parsing error ? " << buffer << std::endl;
abort(); abort();
} }

View File

@ -21,7 +21,7 @@ bool basic_test_64bit(std::string vals, double val) {
double result_value; double result_value;
auto result = fast_float::from_chars(vals.data(), vals.data() + vals.size(), auto result = fast_float::from_chars(vals.data(), vals.data() + vals.size(),
result_value); result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << " I could not parse " << vals << std::endl; std::cerr << " I could not parse " << vals << std::endl;
return false; return false;
} }

View File

@ -90,7 +90,10 @@ bool allvalues() {
float result_value; float result_value;
auto result = fast_float::from_chars(buffer, string_end, result_value); auto result = fast_float::from_chars(buffer, string_end, result_value);
if (result.ec != std::errc()) { // Starting with version 4.0 for fast_float, we return result_out_of_range if the
// value is either too small (too close to zero) or too large (effectively infinity).
// So std::errc::result_out_of_range is normal for well-formed input strings.
if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << "parsing error ? " << buffer << std::endl; std::cerr << "parsing error ? " << buffer << std::endl;
return false; return false;
} }

View File

@ -29,7 +29,10 @@ void allvalues() {
const char *string_end = to_string(v, buffer); const char *string_end = to_string(v, buffer);
float result_value; float result_value;
auto result = fast_float::from_chars(buffer, string_end, result_value); auto result = fast_float::from_chars(buffer, string_end, result_value);
if (result.ec != std::errc()) { // Starting with version 4.0 for fast_float, we return result_out_of_range if the
// value is either too small (too close to zero) or too large (effectively infinity).
// So std::errc::result_out_of_range is normal for well-formed input strings.
if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << "parsing error ? " << buffer << std::endl; std::cerr << "parsing error ? " << buffer << std::endl;
abort(); abort();
} }

View File

@ -28,7 +28,10 @@ void all_32bit_values() {
const char *string_end = to_string(v, buffer); const char *string_end = to_string(v, buffer);
double result_value; double result_value;
auto result = fast_float::from_chars(buffer, string_end, result_value); auto result = fast_float::from_chars(buffer, string_end, result_value);
if (result.ec != std::errc()) { // Starting with version 4.0 for fast_float, we return result_out_of_range if the
// value is either too small (too close to zero) or too large (effectively infinity).
// So std::errc::result_out_of_range is normal for well-formed input strings.
if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << "parsing error ? " << buffer << std::endl; std::cerr << "parsing error ? " << buffer << std::endl;
abort(); abort();
} }

View File

@ -56,7 +56,10 @@ void random_values(size_t N) {
const char *string_end = to_string(v, buffer); const char *string_end = to_string(v, buffer);
double result_value; double result_value;
auto result = fast_float::from_chars(buffer, string_end, result_value); auto result = fast_float::from_chars(buffer, string_end, result_value);
if (result.ec != std::errc()) { // Starting with version 4.0 for fast_float, we return result_out_of_range if the
// value is either too small (too close to zero) or too large (effectively infinity).
// So std::errc::result_out_of_range is normal for well-formed input strings.
if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << "parsing error ? " << buffer << std::endl; std::cerr << "parsing error ? " << buffer << std::endl;
errors++; errors++;
if (errors > 10) { if (errors > 10) {

View File

@ -22,7 +22,7 @@ bool test() {
while((begin < end) && (std::isspace(*begin))) { begin++; } while((begin < end) && (std::isspace(*begin))) { begin++; }
auto result = fast_float::from_chars(begin, end, auto result = fast_float::from_chars(begin, end,
result_value); result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
printf("parsing %.*s\n", int(end - begin), begin); printf("parsing %.*s\n", int(end - begin), begin);
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;

View File

@ -105,7 +105,7 @@ bool tester() {
double result_value; double result_value;
auto result = auto result =
fast_float::from_chars(to_be_parsed.data(), to_be_parsed.data() + to_be_parsed.size(), result_value); fast_float::from_chars(to_be_parsed.data(), to_be_parsed.data() + to_be_parsed.size(), result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cout << to_be_parsed << std::endl; std::cout << to_be_parsed << std::endl;
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;

View File

@ -59,7 +59,10 @@ void random_values(size_t N) {
const char *string_end = to_string(v, buffer); const char *string_end = to_string(v, buffer);
double result_value; double result_value;
auto result = fast_float::from_chars(buffer, string_end, result_value); auto result = fast_float::from_chars(buffer, string_end, result_value);
if (result.ec != std::errc()) { // Starting with version 4.0 for fast_float, we return result_out_of_range if the
// value is either too small (too close to zero) or too large (effectively infinity).
// So std::errc::result_out_of_range is normal for well-formed input strings.
if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
std::cerr << "parsing error ? " << buffer << std::endl; std::cerr << "parsing error ? " << buffer << std::endl;
errors++; errors++;
if (errors > 10) { if (errors > 10) {

View File

@ -101,7 +101,12 @@ size_t build_random_string(RandomEngine &rand, char *buffer) {
if (i == size_t(location_of_decimal_separator)) { if (i == size_t(location_of_decimal_separator)) {
buffer[pos++] = '.'; buffer[pos++] = '.';
} }
buffer[pos++] = char(rand.next_digit() + '0'); buffer[pos] = char(rand.next_digit() + '0');
// We can have a leading zero only if location_of_decimal_separator = 1.
while(i == 0 && 1 != size_t(location_of_decimal_separator) && buffer[pos] == '0') {
buffer[pos] = char(rand.next_digit() + '0');
}
pos++;
} }
if (rand.next_bool()) { if (rand.next_bool()) {
if (rand.next_bool()) { if (rand.next_bool()) {
@ -178,7 +183,7 @@ bool tester(uint64_t seed, size_t volume) {
double result_value; double result_value;
auto result = auto result =
fast_float::from_chars(buffer, buffer + length, result_value); fast_float::from_chars(buffer, buffer + length, result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
printf("parsing %.*s\n", int(length), buffer); printf("parsing %.*s\n", int(length), buffer);
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;
@ -201,7 +206,7 @@ bool tester(uint64_t seed, size_t volume) {
float result_value; float result_value;
auto result = auto result =
fast_float::from_chars(buffer, buffer + length, result_value); fast_float::from_chars(buffer, buffer + length, result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
printf("parsing %.*s\n", int(length), buffer); printf("parsing %.*s\n", int(length), buffer);
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;

View File

@ -97,7 +97,12 @@ size_t build_random_string(RandomEngine &rand, char *buffer) {
if (i == size_t(location_of_decimal_separator)) { if (i == size_t(location_of_decimal_separator)) {
buffer[pos++] = '.'; buffer[pos++] = '.';
} }
buffer[pos++] = char(rand.next_digit() + '0'); buffer[pos] = char(rand.next_digit() + '0');
// We can have a leading zero only if location_of_decimal_separator = 1.
while(i == 0 && 1 != size_t(location_of_decimal_separator) && buffer[pos] == '0') {
buffer[pos] = char(rand.next_digit() + '0');
}
pos++;
} }
if (rand.next_bool()) { if (rand.next_bool()) {
if (rand.next_bool()) { if (rand.next_bool()) {
@ -174,7 +179,7 @@ bool tester(uint64_t seed, size_t volume) {
double result_value; double result_value;
auto result = auto result =
fast_float::from_chars(buffer, buffer + length, result_value); fast_float::from_chars(buffer, buffer + length, result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
printf("parsing %.*s\n", int(length), buffer); printf("parsing %.*s\n", int(length), buffer);
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;
@ -197,7 +202,7 @@ bool tester(uint64_t seed, size_t volume) {
float result_value; float result_value;
auto result = auto result =
fast_float::from_chars(buffer, buffer + length, result_value); fast_float::from_chars(buffer, buffer + length, result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
printf("parsing %.*s\n", int(length), buffer); printf("parsing %.*s\n", int(length), buffer);
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;

View File

@ -239,7 +239,7 @@ bool partow_test() {
T result_value; T result_value;
auto result = fast_float::from_chars(st.data(), st.data() + st.size(), auto result = fast_float::from_chars(st.data(), st.data() + st.size(),
result_value); result_value);
if (result.ec != std::errc()) { if (result.ec != std::errc() && result.ec != std::errc::result_out_of_range) {
printf("parsing %.*s\n", int(st.size()), st.data()); printf("parsing %.*s\n", int(st.size()), st.data());
std::cerr << " I could not parse " << std::endl; std::cerr << " I could not parse " << std::endl;
return false; return false;