forked from boostorg/endian
Test floating point in endian_arithmetic_test
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
template<BOOST_SCOPED_ENUM(boost::endian::order) Order, BOOST_SCOPED_ENUM(boost::endian::align) Align, class T> void test_( T const& x )
|
||||
template<BOOST_SCOPED_ENUM(boost::endian::order) Order, BOOST_SCOPED_ENUM(boost::endian::align) Align, class T> void test_arithmetic_( T const& x )
|
||||
{
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y( x );
|
||||
|
||||
@ -20,14 +20,6 @@ template<BOOST_SCOPED_ENUM(boost::endian::order) Order, BOOST_SCOPED_ENUM(boost:
|
||||
|
||||
BOOST_TEST_EQ( x * x, y * y );
|
||||
BOOST_TEST_EQ( x / x, y / y );
|
||||
BOOST_TEST_EQ( x % x, y % y );
|
||||
|
||||
BOOST_TEST_EQ( x & x, y & y );
|
||||
BOOST_TEST_EQ( x | x, y | y );
|
||||
BOOST_TEST_EQ( x ^ x, y ^ y );
|
||||
|
||||
BOOST_TEST_EQ( x << 1, y << 1 );
|
||||
BOOST_TEST_EQ( x >> 1, y >> 1 );
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
@ -57,6 +49,48 @@ template<BOOST_SCOPED_ENUM(boost::endian::order) Order, BOOST_SCOPED_ENUM(boost:
|
||||
BOOST_TEST_EQ( x2 /= x, y2 /= y );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( ++x2, ++y2 );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( --x2, --y2 );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( x2++, y2++ );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( x2--, y2-- );
|
||||
}
|
||||
}
|
||||
|
||||
template<BOOST_SCOPED_ENUM(boost::endian::order) Order, BOOST_SCOPED_ENUM(boost::endian::align) Align, class T> void test_integral_( T const& x )
|
||||
{
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y( x );
|
||||
|
||||
BOOST_TEST_EQ( x % x, y % y );
|
||||
|
||||
BOOST_TEST_EQ( x & x, y & y );
|
||||
BOOST_TEST_EQ( x | x, y | y );
|
||||
BOOST_TEST_EQ( x ^ x, y ^ y );
|
||||
|
||||
BOOST_TEST_EQ( x << 1, y << 1 );
|
||||
BOOST_TEST_EQ( x >> 1, y >> 1 );
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
@ -98,48 +132,33 @@ template<BOOST_SCOPED_ENUM(boost::endian::order) Order, BOOST_SCOPED_ENUM(boost:
|
||||
|
||||
BOOST_TEST_EQ( x2 >>= 1, y2 >>= 1 );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( ++x2, ++y2 );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( --x2, --y2 );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( x2++, y2++ );
|
||||
}
|
||||
|
||||
{
|
||||
T x2( x );
|
||||
boost::endian::endian_arithmetic<Order, T, sizeof(T) * 8, Align> y2( y );
|
||||
|
||||
BOOST_TEST_EQ( x2--, y2-- );
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> void test( T const& x )
|
||||
template<class T> void test_arithmetic( T const& x )
|
||||
{
|
||||
test_<boost::endian::order::little, boost::endian::align::no>( x );
|
||||
test_<boost::endian::order::little, boost::endian::align::yes>( x );
|
||||
test_<boost::endian::order::big, boost::endian::align::no>( x );
|
||||
test_<boost::endian::order::big, boost::endian::align::yes>( x );
|
||||
test_arithmetic_<boost::endian::order::little, boost::endian::align::no>( x );
|
||||
test_arithmetic_<boost::endian::order::little, boost::endian::align::yes>( x );
|
||||
test_arithmetic_<boost::endian::order::big, boost::endian::align::no>( x );
|
||||
test_arithmetic_<boost::endian::order::big, boost::endian::align::yes>( x );
|
||||
}
|
||||
|
||||
template<class T> void test_integral( T const& x )
|
||||
{
|
||||
test_arithmetic( x );
|
||||
|
||||
test_integral_<boost::endian::order::little, boost::endian::align::no>( x );
|
||||
test_integral_<boost::endian::order::little, boost::endian::align::yes>( x );
|
||||
test_integral_<boost::endian::order::big, boost::endian::align::no>( x );
|
||||
test_integral_<boost::endian::order::big, boost::endian::align::yes>( x );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test( 0x7EF2 );
|
||||
test( 0x01020304u );
|
||||
test_integral( 0x7EF2 );
|
||||
test_integral( 0x01020304u );
|
||||
|
||||
test_arithmetic( 3.1416f );
|
||||
test_arithmetic( 3.14159 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user