MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / append_exponent

Function append_exponent

lesson6-Segmentation/json.hpp:15262–15301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15260JSON_HEDLEY_NON_NULL(1)
15261JSON_HEDLEY_RETURNS_NON_NULL
15262inline char* append_exponent(char* buf, int e)
15263{
15264 JSON_ASSERT(e > -1000);
15265 JSON_ASSERT(e < 1000);
15266
15267 if (e < 0)
15268 {
15269 e = -e;
15270 *buf++ = '-';
15271 }
15272 else
15273 {
15274 *buf++ = '+';
15275 }
15276
15277 auto k = static_cast<std::uint32_t>(e);
15278 if (k < 10)
15279 {
15280 // Always print at least two digits in the exponent.
15281 // This is for compatibility with printf("%g").
15282 *buf++ = '0';
15283 *buf++ = static_cast<char>('0' + k);
15284 }
15285 else if (k < 100)
15286 {
15287 *buf++ = static_cast<char>('0' + k / 10);
15288 k %= 10;
15289 *buf++ = static_cast<char>('0' + k);
15290 }
15291 else
15292 {
15293 *buf++ = static_cast<char>('0' + k / 100);
15294 k %= 100;
15295 *buf++ = static_cast<char>('0' + k / 10);
15296 k %= 10;
15297 *buf++ = static_cast<char>('0' + k);
15298 }
15299
15300 return buf;
15301}
15302
15303/*!
15304@brief prettify v = buf * 10^decimal_exponent

Callers 1

format_bufferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected