MCPcopy Create free account
hub / github.com/chen3feng/toft / WriteFloatToBuffer

Function WriteFloatToBuffer

base/string/number.cpp:332–354  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

330// Makesure buffer size >= kMaxFloatStringSize
331// -------------------------------------------------------------
332char* WriteFloatToBuffer(float value, char* buffer)
333{
334 // FLT_DIG is 6 on almost all platforms.
335 // If it's too big, the buffer will overflow
336 TOFT_STATIC_ASSERT(FLT_DIG < 10, "FLT_DIG is too big");
337 if (value >= std::numeric_limits<double>::infinity())
338 {
339 strcpy(buffer, "inf"); // NOLINT
340 return buffer + 3;
341 }
342 else if (value <= -std::numeric_limits<double>::infinity())
343 {
344 strcpy(buffer, "-inf"); // NOLINT
345 return buffer + 4;
346 }
347 else if (isnan(value))
348 {
349 strcpy(buffer, "nan"); // NOLINT
350 return buffer + 3;
351 }
352
353 return buffer + snprintf(buffer, kMaxFloatStringSize, "%.*g", FLT_DIG, value);
354}
355
356char* DoubleToString(double n, char* buffer)
357{

Callers 2

StringAppendFunction · 0.85
FloatToStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected