MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / append_exponent

Function append_exponent

include/behaviortree_cpp/contrib/json.hpp:17835–17874  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17833JSON_HEDLEY_NON_NULL(1)
17834JSON_HEDLEY_RETURNS_NON_NULL
17835inline char* append_exponent(char* buf, int e)
17836{
17837 JSON_ASSERT(e > -1000);
17838 JSON_ASSERT(e < 1000);
17839
17840 if (e < 0)
17841 {
17842 e = -e;
17843 *buf++ = '-';
17844 }
17845 else
17846 {
17847 *buf++ = '+';
17848 }
17849
17850 auto k = static_cast<std::uint32_t>(e);
17851 if (k < 10)
17852 {
17853 // Always print at least two digits in the exponent.
17854 // This is for compatibility with printf("%g").
17855 *buf++ = '0';
17856 *buf++ = static_cast<char>('0' + k);
17857 }
17858 else if (k < 100)
17859 {
17860 *buf++ = static_cast<char>('0' + k / 10);
17861 k %= 10;
17862 *buf++ = static_cast<char>('0' + k);
17863 }
17864 else
17865 {
17866 *buf++ = static_cast<char>('0' + k / 100);
17867 k %= 100;
17868 *buf++ = static_cast<char>('0' + k / 10);
17869 k %= 10;
17870 *buf++ = static_cast<char>('0' + k);
17871 }
17872
17873 return buf;
17874}
17875
17876/*!
17877@brief prettify v = buf * 10^decimal_exponent

Callers 1

format_bufferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected