From 31855dd0a46c0213a278734167b4fba1fa2f1a0a Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Jul 2023 02:44:25 -0400 Subject: [PATCH] move math functions to math.h format contained a rounding function and power function, they are now in math.h --- include/blt/math/math.h | 20 ++++++++++++++++++++ include/blt/nbt/nbt.h | 2 +- include/blt/std/format.h | 20 +------------------- src/blt/nbt/nbt.cpp | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/blt/math/math.h b/include/blt/math/math.h index 3fc3b0b..e544ea4 100755 --- a/include/blt/math/math.h +++ b/include/blt/math/math.h @@ -36,6 +36,26 @@ namespace blt { return y; } + + static inline constexpr double pow(int b, int p) { + int collection = 1; + for (int i = 0; i < p; i++) + collection *= b; + return collection; + } + + /** + * This is a fast rounding function and is not guaranteed to be 100% correct + * @tparam decimal_places + * @param value + * @return + */ + template + static inline double round_up(double value) { + constexpr double multiplier = pow(10, decimal_places); + return ((int)(value * multiplier) + 1) / multiplier; + } + /*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) { return out << "\rMatrix4x4{" << v.m00() << ", " << v.m01() << ", " << v.m02() << ", " << v.m03() << "} \n"\ << " {" << v.m10() << ", " << v.m11() << ", " << v.m12() << ", " << v.m13() << "} \n"\ diff --git a/include/blt/nbt/nbt.h b/include/blt/nbt/nbt.h index 9ddbcf7..d719b1d 100755 --- a/include/blt/nbt/nbt.h +++ b/include/blt/nbt/nbt.h @@ -15,7 +15,7 @@ namespace blt::nbt { std::string readUTF8String(std::fstream& stream); - enum nbt_type { + enum class nbt_type : char { tag_end = 0, tag_byte = 1, tag_short = 2, diff --git a/include/blt/std/format.h b/include/blt/std/format.h index d29e3aa..cb28884 100755 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -10,27 +10,9 @@ #include #include #include +#include namespace blt::string { - static inline constexpr double _static_pow(int p) { - int collection = 1; - for (int i = 0; i < p; i++) - collection *= 10; - return collection; - } - - /** - * This is a fast rounding function and is not guaranteed to be 100% correct - * @tparam decimal_places - * @param value - * @return - */ - template - static inline double round_up(double value) { - constexpr double multiplier = _static_pow(decimal_places); - return ((int)(value * multiplier) + 1) / multiplier; - } - static inline std::string fromBytes(unsigned long bytes){ if (bytes > 1073741824) { diff --git a/src/blt/nbt/nbt.cpp b/src/blt/nbt/nbt.cpp index b9bcfb9..4dc259b 100755 --- a/src/blt/nbt/nbt.cpp +++ b/src/blt/nbt/nbt.cpp @@ -23,7 +23,7 @@ namespace blt::nbt { stream.read(str.characters, str.size); - auto strOut = std::move(blt::string::getStringFromUTF8(str)); + auto strOut = blt::string::getStringFromUTF8(str); delete[] str.characters; return strOut; }