MCPcopy Create free account
hub / github.com/baidu/tera / WriteFloatToBuffer

Function WriteFloatToBuffer

src/common/base/string_number.cc:254–270  ·  view source on GitHub ↗

------------------------------------------------------------- Float to string or buffer. Makesure buffer size >= kMaxFloatStringSize -------------------------------------------------------------

Source from the content-addressed store, hash-verified

252// Makesure buffer size >= kMaxFloatStringSize
253// -------------------------------------------------------------
254char* WriteFloatToBuffer(float value, char* buffer) {
255 // FLT_DIG is 6 on almost all platforms.
256 // If it's too big, the buffer will overflow
257 // STATIC_ASSERT(FLT_DIG < 10, "FLT_DIG is too big");
258 if (value >= numeric_limits<double>::infinity()) {
259 strcpy(buffer, "inf"); // NOLINT
260 return buffer + 3;
261 } else if (value <= -numeric_limits<double>::infinity()) {
262 strcpy(buffer, "-inf"); // NOLINT
263 return buffer + 4;
264 } else if (IsNaN(value)) {
265 strcpy(buffer, "nan"); // NOLINT
266 return buffer + 3;
267 }
268
269 return buffer + snprintf(buffer, kMaxFloatStringSize, "%.*g", FLT_DIG, value);
270}
271
272char* DoubleToString(double n, char* buffer) {
273 WriteDoubleToBuffer(n, buffer);

Callers 1

FloatToStringFunction · 0.85

Calls 1

IsNaNFunction · 0.85

Tested by

no test coverage detected