Skip to content

Commit b064189

Browse files
committed
fix a bug when parsing certain floats
- e.g., `./build/benchmarks/benchmark -f data/noaa_gfs_1p00.txt -r 100 -s`
1 parent c7d9175 commit b064189

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

benchmarks/benchmark.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ std::vector<TestCase<T>> fileload(const std::string &filename) {
116116
std::vector<TestCase<T>> lines;
117117
lines.reserve(10000); // let us reserve plenty of memory.
118118
for (std::string line; getline(inputfile, line);) {
119-
try {
120-
lines.emplace_back(std::is_same_v<T, float> ? std::stof(line) : std::stod(line), line);
121-
} catch (...) {
119+
T value;
120+
auto [ptr, ec] = std::from_chars(line.data(), line.data() + line.size(), value);
121+
if (ec != std::errc()) {
122122
fmt::println(stderr, "problem with {}\nWe expect floating-point numbers (one per line).", line);
123123
std::abort();
124124
}
125+
lines.emplace_back(value, line);
125126
}
126127
fmt::println("# read {} lines", lines.size());
127128
return lines;

scripts/generate_multiple_tables.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
input_files = [
1717
'data/canada.txt',
1818
'data/mesh.txt',
19+
'data/bitcoin.txt',
20+
'data/gaia.txt',
21+
'data/marine_ik.txt',
22+
'data/mobilenetv3_large.txt',
23+
'data/noaa_gfs_1p00.txt',
24+
'data/noaa_global_hourly_2023.txt'
1925
]
2026
models = [
2127
'uniform_01',

0 commit comments

Comments
 (0)