Skip to content

Commit

Permalink
valueToString: simplify lookup of special float name
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDonahue committed Jan 9, 2025
1 parent 95be091 commit 5abc090
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ String valueToString(double value, bool useSpecialFloats,
// that always has a decimal point because JSON doesn't distinguish the
// concepts of reals and integers.
if (!std::isfinite(value)) {
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
{"null", "-1e+9999", "1e+9999"}};
return reps[useSpecialFloats ? 0 : 1][std::isnan(value) ? 0
: (value < 0) ? 1
: 2];
if (std::isnan(value))
return useSpecialFloats ? "NaN" : "null";
if (value < 0)
return useSpecialFloats ? "-Infinity" : "-1e+9999";
return useSpecialFloats ? "Infinity" : "1e+9999";
}

String buffer(size_t(36), '\0');
Expand Down

0 comments on commit 5abc090

Please sign in to comment.