Skip to content

Commit f23ced2

Browse files
committed
fix for supplemental
1 parent baaf58d commit f23ced2

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

tests/basictest.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -433,28 +433,28 @@ bool check_file(std::string file_name) {
433433
if (str.size() > 0) {
434434
#ifdef __STDCPP_FLOAT16_T__
435435
// Read 16-bit hex
436-
uint16_t float16;
436+
uint16_t float16{};
437437
auto r16 =
438438
std::from_chars(str.data(), str.data() + str.size(), float16, 16);
439439
if (r16.ec != std::errc()) {
440-
std::cerr << "16-bit parsing failure\n";
440+
std::cerr << "16-bit parsing failure: " << str << "\n";
441441
return false;
442442
}
443443
#endif
444444
// Read 32-bit hex
445-
uint32_t float32;
445+
uint32_t float32{};
446446
auto r32 = std::from_chars(str.data() + 5, str.data() + str.size(),
447447
float32, 16);
448448
if (r32.ec != std::errc()) {
449-
std::cerr << "32-bit parsing failure\n";
449+
std::cerr << "32-bit parsing failure: " << str << "\n";
450450
return false;
451451
}
452452
// Read 64-bit hex
453-
uint64_t float64;
453+
uint64_t float64{};
454454
auto r64 = std::from_chars(str.data() + 14, str.data() + str.size(),
455455
float64, 16);
456456
if (r64.ec != std::errc()) {
457-
std::cerr << "64-bit parsing failure\n";
457+
std::cerr << "64-bit parsing failure: " << str << "\n";
458458
return false;
459459
}
460460
// The string to parse:
@@ -467,34 +467,34 @@ bool check_file(std::string file_name) {
467467
fast_float::from_chars(number_string, end_of_string, parsed_16);
468468
if (fast_float_r16.ec != std::errc() &&
469469
fast_float_r16.ec != std::errc::result_out_of_range) {
470-
std::cerr << "16-bit fast_float parsing failure for: " + str + "\n";
470+
std::cerr << "16-bit fast_float parsing failure: " << str << "\n";
471471
return false;
472472
}
473473
#endif
474474
// Parse as 32-bit float
475-
float parsed_32;
475+
float parsed_32{};
476476
auto fast_float_r32 =
477477
fast_float::from_chars(number_string, end_of_string, parsed_32);
478478
if (fast_float_r32.ec != std::errc() &&
479479
fast_float_r32.ec != std::errc::result_out_of_range) {
480-
std::cerr << "32-bit fast_float parsing failure for: " + str + "\n";
480+
std::cerr << "32-bit fast_float parsing failure: " << str << "\n";
481481
return false;
482482
}
483483
// Parse as 64-bit float
484-
double parsed_64;
484+
double parsed_64{};
485485
auto fast_float_r64 =
486486
fast_float::from_chars(number_string, end_of_string, parsed_64);
487487
if (fast_float_r64.ec != std::errc() &&
488488
fast_float_r32.ec != std::errc::result_out_of_range) {
489-
std::cerr << "64-bit fast_float parsing failure: " + str + "\n";
489+
std::cerr << "64-bit fast_float parsing failure: " << str << "\n";
490490
return false;
491491
}
492492
// Convert the floats to unsigned ints.
493493
#ifdef __STDCPP_FLOAT16_T__
494-
uint16_t float16_parsed;
494+
uint16_t float16_parsed{};
495495
#endif
496-
uint32_t float32_parsed;
497-
uint64_t float64_parsed;
496+
uint32_t float32_parsed{};
497+
uint64_t float64_parsed{};
498498
#ifdef __STDCPP_FLOAT16_T__
499499
::memcpy(&float16_parsed, &parsed_16, sizeof(parsed_16));
500500

@@ -504,27 +504,27 @@ bool check_file(std::string file_name) {
504504
// Compare with expected results
505505
#ifdef __STDCPP_FLOAT16_T__
506506
if (float16_parsed != float16) {
507-
std::cout << "bad 16 " << str << std::endl;
508-
std::cout << "parsed as " << iHexAndDec(parsed_16) << std::endl;
509-
std::cout << "as raw uint16_t, parsed = " << float16_parsed
507+
std::cout << "bad 16: " << str << std::endl;
508+
std::cout << "parsed as " << fHexAndDec(parsed_16) << std::endl;
509+
std::cout << "as raw uint16_t, parsed = " << float16_parsed
510510
<< ", expected = " << float16 << std::endl;
511511
std::cout << "fesetround: " << round_name(d) << std::endl;
512512
fesetround(FE_TONEAREST);
513513
return false;
514514
}
515515
#endif
516516
if (float32_parsed != float32) {
517-
std::cout << "bad 32 " << str << std::endl;
518-
std::cout << "parsed as " << iHexAndDec(parsed_32) << std::endl;
519-
std::cout << "as raw uint32_t, parsed = " << float32_parsed
517+
std::cout << "bad 32: " << str << std::endl;
518+
std::cout << "parsed as " << fHexAndDec(parsed_32) << std::endl;
519+
std::cout << "as raw uint32_t, parsed = " << float32_parsed
520520
<< ", expected = " << float32 << std::endl;
521521
std::cout << "fesetround: " << round_name(d) << std::endl;
522522
fesetround(FE_TONEAREST);
523523
return false;
524524
}
525525
if (float64_parsed != float64) {
526-
std::cout << "bad 64 " << str << std::endl;
527-
std::cout << "parsed as " << iHexAndDec(parsed_64) << std::endl;
526+
std::cout << "bad 64: " << str << std::endl;
527+
std::cout << "parsed as " << fHexAndDec(parsed_64) << std::endl;
528528
std::cout << "as raw uint64_t, parsed = " << float64_parsed
529529
<< ", expected = " << float64 << std::endl;
530530
std::cout << "fesetround: " << round_name(d) << std::endl;
@@ -550,7 +550,9 @@ bool check_file(std::string file_name) {
550550
TEST_CASE("supplemental") {
551551
std::string path = SUPPLEMENTAL_TEST_DATA_DIR;
552552
for (auto const &entry : std::filesystem::directory_iterator(path)) {
553-
CHECK(check_file(entry.path().string()));
553+
const auto file = entry.path().string();
554+
CAPTURE(file);
555+
CHECK(check_file(file));
554556
}
555557
}
556558
#endif

0 commit comments

Comments
 (0)