------------------------------------------------------------- Float to string or buffer. Makesure buffer size >= kMaxFloatStringSize -------------------------------------------------------------
| 330 | // Makesure buffer size >= kMaxFloatStringSize |
| 331 | // ------------------------------------------------------------- |
| 332 | char* 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 | |
| 356 | char* DoubleToString(double n, char* buffer) |
| 357 | { |
no outgoing calls
no test coverage detected