Branimir Karadžić 7 anos atrás
pai
commit
6db21d9a36
2 arquivos alterados com 3 adições e 1 exclusões
  1. 2 1
      src/dtoa.cpp
  2. 1 0
      tests/string_test.cpp

+ 2 - 1
src/dtoa.cpp

@@ -314,7 +314,8 @@ namespace bx
 			if (p2 < delta)
 			if (p2 < delta)
 			{
 			{
 				*K += kappa;
 				*K += kappa;
-				GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * s_kPow10[-kappa]);
+				const int index = -static_cast<int>(kappa);
+				GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? s_kPow10[-static_cast<int>(kappa)] : 0));
 				return;
 				return;
 			}
 			}
 		}
 		}

+ 1 - 0
tests/string_test.cpp

@@ -274,6 +274,7 @@ TEST_CASE("toString double", "")
 	REQUIRE(testToString(0.0000000001,            "1e-10") );
 	REQUIRE(testToString(0.0000000001,            "1e-10") );
 	REQUIRE(testToString(-270.000000,             "-270.0") );
 	REQUIRE(testToString(-270.000000,             "-270.0") );
 	REQUIRE(testToString(2.225073858507201e-308,  "2.225073858507201e-308") );
 	REQUIRE(testToString(2.225073858507201e-308,  "2.225073858507201e-308") );
+	REQUIRE(testToString(-79.39773355813419,      "-79.39773355813419") );
 }
 }
 
 
 static bool testFromString(double _value, const char* _input)
 static bool testFromString(double _value, const char* _input)