Commit dae69fd5 authored by ussrhero's avatar ussrhero

fixed print out of floats

parent 2a4220fa
......@@ -308,11 +308,13 @@ public:
return sstr.str();
case floatT:
sstr << m_floatVal;
sstr.precision(8);
sstr << std::defaultfloat << m_floatVal;
return sstr.str();
case doubleT:
sstr << m_doubleVal;
sstr.precision(16);
sstr << std::defaultfloat << m_doubleVal;
return sstr.str();
}
......@@ -323,7 +325,7 @@ public:
std::wstringstream sstr;
sstr << std::hex;
sstr << std::hex << std::showbase;
switch ( m_numType )
{
......@@ -350,12 +352,14 @@ public:
return sstr.str();
case floatT:
sstr << m_floatVal;
return sstr.str();
sstr.precision(8);
sstr << std::hexfloat << m_floatVal;
return sstr.str();
case doubleT:
sstr << m_doubleVal;
return sstr.str();
sstr.precision(8);
sstr << std::hexfloat << m_doubleVal;
return sstr.str();
}
throw NumVariantError();
......
......@@ -796,7 +796,7 @@ std::wstring TypedVarBase::printValue() const
std::wstringstream sstr;
try {
sstr << L"0x" << getValue().asHex() << L" (" << getValue().asStr() << L")";
sstr << getValue().asHex() << L" (" << getValue().asStr() << L")";
return sstr.str();
} catch(MemoryException& )
{}
......
......@@ -6,10 +6,10 @@
using namespace kdlib;
class VariantCtorTest : public ::testing::Test {
class VariantTest : public ::testing::Test {
};
TEST_F( VariantCtorTest, Ctor )
TEST_F( VariantTest, Ctor )
{
EXPECT_TRUE( NumVariant(0).isInt() );
EXPECT_TRUE( NumVariant(-1LL).isLongLong() );
......@@ -20,6 +20,21 @@ TEST_F( VariantCtorTest, Ctor )
EXPECT_TRUE( NumVariant(unsigned short(29) ).isUShort() );
}
TEST_F(VariantTest, AsStr)
{
EXPECT_EQ(L"-98765432", NumVariant(-98765432LL).asStr());
EXPECT_EQ(L"12345678", NumVariant(12345678LL).asStr());
EXPECT_EQ(L"-45.123402", NumVariant(-45.1234f).asStr());
EXPECT_EQ(L"15.0000000001", NumVariant(15.0000000001).asStr());
}
TEST_F(VariantTest, AsHex)
{
EXPECT_EQ(L"0xfffffffffa1cf588", NumVariant(-98765432LL).asHex());
EXPECT_EQ(L"0xbc614e", NumVariant(12345678LL).asHex());
EXPECT_EQ(L"-0x1.68fcba00p+5", NumVariant(-45.1234f).asHex());
EXPECT_EQ(L"0x1.e0000000p+3", NumVariant(15.0000000001).asHex());
}
class VariantConversionTest : public ::testing::TestWithParam<unsigned long long> {
};
......@@ -246,3 +261,6 @@ TEST_F( VariantOperationTests, isInteger )
EXPECT_FALSE( NumVariant( double(0) ).isInteger() );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment