move math functions to math.h
format contained a rounding function and power function, they are now in math.hv1
parent
0d5abd143f
commit
31855dd0a4
|
@ -36,6 +36,26 @@ namespace blt {
|
||||||
return y;
|
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<int decimal_places>
|
||||||
|
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) {
|
/*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) {
|
||||||
return out << "\rMatrix4x4{" << v.m00() << ", " << v.m01() << ", " << v.m02() << ", " << v.m03() << "} \n"\
|
return out << "\rMatrix4x4{" << v.m00() << ", " << v.m01() << ", " << v.m02() << ", " << v.m03() << "} \n"\
|
||||||
<< " {" << v.m10() << ", " << v.m11() << ", " << v.m12() << ", " << v.m13() << "} \n"\
|
<< " {" << v.m10() << ", " << v.m11() << ", " << v.m12() << ", " << v.m13() << "} \n"\
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace blt::nbt {
|
||||||
|
|
||||||
std::string readUTF8String(std::fstream& stream);
|
std::string readUTF8String(std::fstream& stream);
|
||||||
|
|
||||||
enum nbt_type {
|
enum class nbt_type : char {
|
||||||
tag_end = 0,
|
tag_end = 0,
|
||||||
tag_byte = 1,
|
tag_byte = 1,
|
||||||
tag_short = 2,
|
tag_short = 2,
|
||||||
|
|
|
@ -10,27 +10,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <blt/math/math.h>
|
||||||
|
|
||||||
namespace blt::string {
|
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<int decimal_places>
|
|
||||||
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){
|
static inline std::string fromBytes(unsigned long bytes){
|
||||||
if (bytes > 1073741824) {
|
if (bytes > 1073741824) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace blt::nbt {
|
||||||
|
|
||||||
stream.read(str.characters, str.size);
|
stream.read(str.characters, str.size);
|
||||||
|
|
||||||
auto strOut = std::move(blt::string::getStringFromUTF8(str));
|
auto strOut = blt::string::getStringFromUTF8(str);
|
||||||
delete[] str.characters;
|
delete[] str.characters;
|
||||||
return strOut;
|
return strOut;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue