// Copyright 2022 The Abseil Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License.
// This program tests the absl::SimpleAtod and absl::SimpleAtof functions. Run // it as "atod_manual_test pnftd/data/*.txt" where the pnftd directory is a // local checkout of the https://github.com/nigeltao/parse-number-fxx-test-data // repository. The test suite lives in a separate repository because its more // than 5 million test cases weigh over several hundred megabytes and because // the test cases are also useful to other software projects, not just Abseil. // Its data/*.txt files contain one test case per line, like: // // 3C00 3F800000 3FF0000000000000 1 // 3D00 3FA00000 3FF4000000000000 1.25 // 3D9A 3FB33333 3FF6666666666666 1.4 // 57B7 42F6E979 405EDD2F1A9FBE77 123.456 // 622A 44454000 4088A80000000000 789 // 7C00 7F800000 7FF0000000000000 123.456e789 // // For each line (and using 0-based column indexes), columns [5..13] and // [14..30] contain the 32-bit float and 64-bit double result of parsing // columns [31..]. // // For example, parsing "1.4" as a float gives the bits 0x3FB33333. // // In this 6-line example, the final line's float and double values are all // infinity. The largest finite float and double values are approximately // 3.40e+38 and 1.80e+308.
// Test absl::SimpleAtof.
{ float f; if (!absl::SimpleAtof(input, &f)) {
absl::FPrintF(stderr, "Could not parse \"%s\" in %s\n", input,
filename); returnfalse;
}
uint32_t have32 = absl::bit_cast<uint32_t>(f);
uint32_t want32 = 0; for (int i = 0; i < 8; i++) {
want32 = (want32 << 4) | kUnhex[static_cast<unsignedchar>(v[5 + i])];
}
if (have32 != want32) {
absl::FPrintF(stderr, "absl::SimpleAtof failed parsing \"%s\" in %s\n have " "%08X\n want %08X\n",
input, filename, have32, want32); returnfalse;
}
}
// Test absl::SimpleAtod.
{ double d; if (!absl::SimpleAtod(input, &d)) {
absl::FPrintF(stderr, "Could not parse \"%s\" in %s\n", input,
filename); returnfalse;
}
uint64_t have64 = absl::bit_cast<uint64_t>(d);
uint64_t want64 = 0; for (int i = 0; i < 16; i++) {
want64 = (want64 << 4) | kUnhex[static_cast<unsignedchar>(v[14 + i])];
}
if (have64 != want64) {
absl::FPrintF(stderr, "absl::SimpleAtod failed parsing \"%s\" in %s\n have " "%016X\n want %016X\n",
input, filename, have64, want64); returnfalse;
}
}
num_cases++;
v = v.substr(new_line + 1);
}
printf("%8d OK in %s\n", num_cases, filename); returntrue;
}
int main(int argc, char** argv) { if (argc < 2) {
absl::FPrintF(
stderr, "Usage: %s pnftd/data/*.txt\nwhere the pnftd directory is a local " "checkout of " "the\nhttps://github.com/nigeltao/parse-number-fxx-test-data " "repository.\n",
argv[0]); return1;
}
for (int i = 1; i < argc; i++) { if (!ProcessOneTestFile(argv[i])) { return1;
}
} return0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.