Merge pull request #1 from KJNeko/modules

Modules
This commit is contained in:
KJ16609
2025-05-29 13:56:09 -04:00
committed by GitHub
3 changed files with 30 additions and 3 deletions

View File

@@ -55,8 +55,12 @@
#ifndef NDEBUG
#include <stdexcept>
#define FGL_ASSERT( test, msg ) assert( ( test ) && "msg" );
//if ( !( test ) ) throw std::runtime_error( msg );
#define FGL_ASSERT( test, msg ) \
if ( !( test ) ) \
{ \
throw std::runtime_error( msg ); \
std::abort(); \
}
#else
#define FGL_ASSERT( test, msg )
#endif

23
include/fgl/size.hpp Normal file
View File

@@ -0,0 +1,23 @@
//
// Created by kj16609 on 3/21/25.
//
#pragma once
#include <cmath>
#include <cstdint>
#include <format>
#include <string>
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