changes to how formatter works

v1
Brett 2024-03-11 12:05:37 -04:00
parent b564b3e57b
commit 7e405a27ee
4 changed files with 19 additions and 8 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)
include(cmake/color.cmake)
set(BLT_VERSION 0.14.13)
set(BLT_VERSION 0.14.14)
set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT)

View File

@ -73,10 +73,15 @@ namespace blt
* @return
*/
template<int decimal_places>
static inline double round_up(double value)
constexpr static inline double round_up(double value)
{
constexpr double multiplier = pow(10, decimal_places);
return ((int) (value * multiplier) + 1) / multiplier;
if constexpr (decimal_places < 0)
return value;
else
{
constexpr double multiplier = pow(10, decimal_places);
return ((int) (value * multiplier) + 1) / multiplier;
}
}
/*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) {

View File

@ -970,7 +970,12 @@ namespace blt
deallocate(p);
}
inline const auto& getStats()
inline void resetStats()
{
stats = {};
}
inline const auto& getStats() const
{
return stats;
}

View File

@ -39,20 +39,21 @@ namespace blt::string
return ret;
}
template<int decimal_places = 0>
static inline std::string fromBytes(unsigned long bytes)
{
if (bytes > 1073741824)
{
// gigabyte
return std::to_string(round_up<3>((double) bytes / 1024.0 / 1024.0 / 1024.0)) += "gb";
return std::to_string(round_up<decimal_places>((double) bytes / 1024.0 / 1024.0 / 1024.0)) += "gb";
} else if (bytes > 1048576)
{
// megabyte
return std::to_string(round_up<3>((double) bytes / 1024.0 / 1024.0)) += "mb";
return std::to_string(round_up<decimal_places>((double) bytes / 1024.0 / 1024.0)) += "mb";
} else if (bytes > 1024)
{
// kilobyte
return std::to_string(round_up<3>((double) bytes / 1024.0)) += "kb";
return std::to_string(round_up<decimal_places>((double) bytes / 1024.0)) += "kb";
} else
{
return std::to_string(bytes) += "b";