mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Use std::to_chars() in RealToString().
This commit is contained in:
parent
f017b27ae2
commit
1475635382
@ -222,26 +222,26 @@ const char* RealToString( double val )
|
||||
char* buf = bufpool[bufsel];
|
||||
bufsel = ( bufsel + 1 ) % Pool;
|
||||
|
||||
sprintf( buf, "%f", val );
|
||||
*PrintFloat( buf, buf+64, val ) = '\0';
|
||||
auto ptr = buf;
|
||||
if( *ptr == '-' ) ptr++;
|
||||
|
||||
const auto vbegin = ptr;
|
||||
|
||||
while( *ptr != '\0' && *ptr != ',' && *ptr != '.' ) ptr++;
|
||||
while( *ptr != '\0' && *ptr != '.' ) ptr++;
|
||||
auto end = ptr;
|
||||
while( *end != '\0' ) end++;
|
||||
auto sz = end - ptr;
|
||||
auto sz = end - ptr + 1;
|
||||
|
||||
while( ptr - vbegin > 3 )
|
||||
{
|
||||
ptr -= 3;
|
||||
memmove( ptr+1, ptr, sz );
|
||||
memmove( ptr+1, ptr, sz+3 );
|
||||
*ptr = ',';
|
||||
sz += 4;
|
||||
}
|
||||
|
||||
while( *ptr != '\0' && *ptr != ',' && *ptr != '.' ) ptr++;
|
||||
while( *ptr != '\0' && *ptr != '.' ) ptr++;
|
||||
|
||||
if( *ptr == '\0' ) return buf;
|
||||
while( *ptr != '\0' ) ptr++;
|
||||
|
@ -20,6 +20,16 @@ static inline char* PrintFloat( char* begin, char* end, T value, int precision )
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline char* PrintFloat( char* begin, char* end, T value )
|
||||
{
|
||||
#if ( defined _MSC_VER && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
|
||||
return std::to_chars( begin, end, value, std::chars_format::fixed ).ptr;
|
||||
#else
|
||||
return begin + sprintf( begin, "%f", value );
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* TimeToString( int64_t ns );
|
||||
const char* RealToString( double val );
|
||||
const char* MemSizeToString( int64_t val );
|
||||
|
Loading…
Reference in New Issue
Block a user