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

Function WriteDoubleToBuffer

src/common/base/string_number.cc:231–248  ·  view source on GitHub ↗

----------------------------------------------------------------- Double to string or buffer. Make sure buffer size >= kMaxDoubleStringSize -----------------------------------------------------------------

Source from the content-addressed store, hash-verified

229// Make sure buffer size >= kMaxDoubleStringSize
230// -----------------------------------------------------------------
231char* WriteDoubleToBuffer(double value, char* buffer) {
232 // DBL_DIG is 15 on almost all platforms.
233 // If it's too big, the buffer will overflow
234 // STATIC_ASSERT(DBL_DIG < 20, "DBL_DIG is too big");
235
236 if (value >= numeric_limits<double>::infinity()) {
237 strcpy(buffer, "inf"); // NOLINT
238 return buffer + 3;
239 } else if (value <= -numeric_limits<double>::infinity()) {
240 strcpy(buffer, "-inf"); // NOLINT
241 return buffer + 4;
242 } else if (IsNaN(value)) {
243 strcpy(buffer, "nan"); // NOLINT
244 return buffer + 3;
245 }
246
247 return buffer + snprintf(buffer, kMaxDoubleStringSize, "%.*g", DBL_DIG, value);
248}
249
250// -------------------------------------------------------------
251// Float to string or buffer.

Callers 1

DoubleToStringFunction · 0.85

Calls 1

IsNaNFunction · 0.85

Tested by

no test coverage detected