Skip to content

Commit b4e88e3

Browse files
committed
valueToString: simplify lookup of special float name
1 parent a888632 commit b4e88e3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/lib_json/json_writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ String valueToString(double value, bool useSpecialFloats,
6767
// that always has a decimal point because JSON doesn't distinguish the
6868
// concepts of reals and integers.
6969
if (!std::isfinite(value)) {
70-
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
71-
{"null", "-1e+9999", "1e+9999"}};
72-
return reps[useSpecialFloats ? 0 : 1][std::isnan(value) ? 0
73-
: (value < 0) ? 1
74-
: 2];
70+
if (std::isnan(value))
71+
return useSpecialFloats ? "NaN" : "null";
72+
if (value < 0)
73+
return useSpecialFloats ? "-Infinity" : "-1e+9999";
74+
return useSpecialFloats ? "Infinity" : "1e+9999";
7575
}
7676

7777
String buffer(size_t(36), '\0');

0 commit comments

Comments
 (0)