MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / append_exponent

Function append_exponent

Source/external/json.hpp:17711–17750  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17709JSON_HEDLEY_NON_NULL(1)
17710JSON_HEDLEY_RETURNS_NON_NULL
17711inline char* append_exponent(char* buf, int e)
17712{
17713 JSON_ASSERT(e > -1000);
17714 JSON_ASSERT(e < 1000);
17715
17716 if (e < 0)
17717 {
17718 e = -e;
17719 *buf++ = '-';
17720 }
17721 else
17722 {
17723 *buf++ = '+';
17724 }
17725
17726 auto k = static_cast<std::uint32_t>(e);
17727 if (k < 10)
17728 {
17729 // Always print at least two digits in the exponent.
17730 // This is for compatibility with printf("%g").
17731 *buf++ = '0';
17732 *buf++ = static_cast<char>('0' + k);
17733 }
17734 else if (k < 100)
17735 {
17736 *buf++ = static_cast<char>('0' + k / 10);
17737 k %= 10;
17738 *buf++ = static_cast<char>('0' + k);
17739 }
17740 else
17741 {
17742 *buf++ = static_cast<char>('0' + k / 100);
17743 k %= 100;
17744 *buf++ = static_cast<char>('0' + k / 10);
17745 k %= 10;
17746 *buf++ = static_cast<char>('0' + k);
17747 }
17748
17749 return buf;
17750}
17751
17752/*!
17753@brief prettify v = buf * 10^decimal_exponent

Callers 1

format_bufferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected