Test and bugfix real128
This commit is contained in:
parent
b55ae3431a
commit
c3a6b40188
4 changed files with 27 additions and 4 deletions
|
|
@ -235,6 +235,9 @@ target_link_libraries( ntp_test fc )
|
||||||
add_executable( task_cancel_test tests/task_cancel.cpp )
|
add_executable( task_cancel_test tests/task_cancel.cpp )
|
||||||
target_link_libraries( task_cancel_test fc )
|
target_link_libraries( task_cancel_test fc )
|
||||||
|
|
||||||
|
add_executable( real128_test tests/real128_test.cpp )
|
||||||
|
target_link_libraries( real128_test fc )
|
||||||
|
|
||||||
#include_directories( vendor/udt4/src )
|
#include_directories( vendor/udt4/src )
|
||||||
|
|
||||||
add_executable( udt_server tests/udts.cpp )
|
add_executable( udt_server tests/udts.cpp )
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace fc {
|
||||||
class real128
|
class real128
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
real128( uint64_t integer = 0):fixed(integer){}
|
real128( uint64_t integer = 0):fixed(integer,0){}
|
||||||
real128( const std::string& str );
|
real128( const std::string& str );
|
||||||
operator std::string()const;
|
operator std::string()const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace fc
|
||||||
++c;
|
++c;
|
||||||
digit = *c - '0';
|
digit = *c - '0';
|
||||||
}
|
}
|
||||||
fixed = fc::uint128(int_part);
|
fixed = fc::uint128(int_part, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -92,8 +92,7 @@ namespace fc
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << to_uint64();
|
ss << to_uint64();
|
||||||
ss << '.';
|
ss << '.';
|
||||||
auto frac = *this * real128( uint128(-1,0) );
|
real128 frac(fixed.low_bits());
|
||||||
frac += real128(1);
|
|
||||||
|
|
||||||
ss << std::string( frac.fixed ).substr(1);
|
ss << std::string( frac.fixed ).substr(1);
|
||||||
|
|
||||||
|
|
|
||||||
21
tests/real128_test.cpp
Normal file
21
tests/real128_test.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include <fc/real128.hpp>
|
||||||
|
#define BOOST_TEST_MODULE Real128Test
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using fc::real128;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(real128_test)
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL(string(real128(0)), string("0."));
|
||||||
|
BOOST_CHECK_EQUAL(real128(8).to_uint64(), 8);
|
||||||
|
BOOST_CHECK_EQUAL(real128(6789).to_uint64(), 6789);
|
||||||
|
BOOST_CHECK_EQUAL(real128(10000).to_uint64(), 10000);
|
||||||
|
BOOST_CHECK_EQUAL(string(real128(1)), string("1."));
|
||||||
|
BOOST_CHECK_EQUAL(string(real128(5)), string("5."));
|
||||||
|
BOOST_CHECK_EQUAL(string(real128(12345)), string("12345."));
|
||||||
|
BOOST_CHECK_EQUAL(string(real128(0)), string(real128("0")));
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(real128("12345.6789").to_uint64(), 12345);
|
||||||
|
BOOST_CHECK_EQUAL(string(real128("12345.6789")), string("12345.6789"));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue