diff --git a/include/fgl/size.hpp b/include/fgl/size.hpp new file mode 100644 index 0000000..fe59746 --- /dev/null +++ b/include/fgl/size.hpp @@ -0,0 +1,23 @@ +// +// Created by kj16609 on 3/21/25. +// +#pragma once + +#include +#include +#include +#include + +namespace fgl::size +{ + +std::string toHuman( std::size_t size ) +{ + constexpr std::size_t mod { 1024 }; + if ( size < mod ) return std::format( "{}B", size ); + if ( size < std::pow( mod, 2 ) ) return std::format( "{}KiB", static_cast< int >( size / mod ) ); + if ( size < std::pow( mod, 3 ) ) return std::format( "{}MiB", static_cast< int >( size / std::pow( mod, 2 ) ) ); + if ( size < std::pow( mod, 4 ) ) return std::format( "{}GiB", static_cast< int >( size / std::pow( mod, 3 ) ) ); + return std::format( "{}TiB", static_cast< int >( size / std::pow( mod, 4 ) ) ); +} +} // namespace fgl::size \ No newline at end of file