MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / append_exponent

Function append_exponent

Source/Utils/json.hpp:15261–15300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

format_bufferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected