diff --git a/nfloat.hpp b/nfloat.hpp index 19a1b85..1a427c0 100644 --- a/nfloat.hpp +++ b/nfloat.hpp @@ -166,6 +166,9 @@ std::string to_string(unsigned int accuracy) { big_num exp = from_bitset(this->exponent()); + if (exp == 0) { + return "0"; + } exp -= _bias(size); big_num integral = 0, decimal = 1; @@ -191,7 +194,7 @@ } } - else { + if (exp >= 0) { int_factor /= 2; } exp--; diff --git a/test.cpp b/test.cpp index 0ef86e7..099f17c 100644 --- a/test.cpp +++ b/test.cpp @@ -5,7 +5,7 @@ int main() { - nfloat<32> f(1.51f); + nfloat<128> f("4342.52"); std::cout << f << "\n"; std::cout << f.to_string(500);