mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Fixed issue #267.
This commit is contained in:
@@ -887,10 +887,11 @@ namespace bx
|
||||
const char* dot = strFind(str, INT32_MAX, '.');
|
||||
if (NULL != dot)
|
||||
{
|
||||
const int32_t prec = INT32_MAX == _param.prec ? 6 : _param.prec;
|
||||
const int32_t prec = INT32_MAX == _param.prec ? len-(dot+1-str) : _param.prec;
|
||||
|
||||
const int32_t precLen = int32_t(
|
||||
dot
|
||||
+ uint32_min(prec + _param.spec, 1)
|
||||
+ min(prec + _param.spec, 1)
|
||||
+ prec
|
||||
- str
|
||||
);
|
||||
@@ -900,8 +901,10 @@ namespace bx
|
||||
{
|
||||
str[ii] = '0';
|
||||
}
|
||||
|
||||
str[precLen] = '\0';
|
||||
}
|
||||
|
||||
len = precLen;
|
||||
}
|
||||
|
||||
|
||||
@@ -333,6 +333,7 @@ TEST_CASE("toString double", "")
|
||||
REQUIRE(testToString(-270.000000, "-270.0") );
|
||||
REQUIRE(testToString(2.225073858507201e-308, "2.225073858507201e-308") );
|
||||
REQUIRE(testToString(-79.39773355813419, "-79.39773355813419") );
|
||||
REQUIRE(testToString(-1.234567e-9, "-1.234567e-9") );
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
|
||||
@@ -72,9 +72,11 @@ TEST_CASE("vsnprintf f")
|
||||
REQUIRE(test("0001.500", "%08.3f", 1.5) );
|
||||
REQUIRE(test("+001.500", "%+08.3f", 1.5) );
|
||||
REQUIRE(test("-001.500", "%+08.3f", -1.5) );
|
||||
REQUIRE(test("0.003906", "%f", 0.00390625) );
|
||||
REQUIRE(test("0.0039", "%.4f", 0.00390625) );
|
||||
|
||||
REQUIRE(test("0.00390625", "%f", 0.00390625) );
|
||||
REQUIRE(test("-1.234567e-9", "%f", -1.234567e-9) );
|
||||
|
||||
REQUIRE(test("0.00390625", "%.8f", 0.00390625) );
|
||||
REQUIRE(test("-0.00390625", "%.8f", -0.00390625) );
|
||||
REQUIRE(test("1.50000000000000000", "%.17f", 1.5) );
|
||||
|
||||
Reference in New Issue
Block a user