MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / append_exponent

Function append_exponent

extern/json/json.hpp:17749–17788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17747JSON_HEDLEY_NON_NULL(1)
17748JSON_HEDLEY_RETURNS_NON_NULL
17749inline char* append_exponent(char* buf, int e)
17750{
17751 JSON_ASSERT(e > -1000);
17752 JSON_ASSERT(e < 1000);
17753
17754 if (e < 0)
17755 {
17756 e = -e;
17757 *buf++ = '-';
17758 }
17759 else
17760 {
17761 *buf++ = '+';
17762 }
17763
17764 auto k = static_cast<std::uint32_t>(e);
17765 if (k < 10)
17766 {
17767 // Always print at least two digits in the exponent.
17768 // This is for compatibility with printf("%g").
17769 *buf++ = '0';
17770 *buf++ = static_cast<char>('0' + k);
17771 }
17772 else if (k < 100)
17773 {
17774 *buf++ = static_cast<char>('0' + k / 10);
17775 k %= 10;
17776 *buf++ = static_cast<char>('0' + k);
17777 }
17778 else
17779 {
17780 *buf++ = static_cast<char>('0' + k / 100);
17781 k %= 100;
17782 *buf++ = static_cast<char>('0' + k / 10);
17783 k %= 10;
17784 *buf++ = static_cast<char>('0' + k);
17785 }
17786
17787 return buf;
17788}
17789
17790/*!
17791@brief prettify v = buf * 10^decimal_exponent

Callers 1

format_bufferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected