1 // Copyright 2019 Peter Dimov
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
6 #include <boost/endian/arithmetic.hpp>
7 #include <boost/endian/buffers.hpp>
8 #include <boost/core/lightweight_test.hpp>
10 template<class T> struct align
15 explicit align( typename T::value_type y ): _(), v( y )
20 template<class T, class U> void test_buffer( U const & y, bool aligned )
24 BOOST_TEST_EQ( sizeof(x), aligned? 2 * sizeof(U): 1 + sizeof(U) );
26 BOOST_TEST_EQ( x.v.value(), y );
29 template<class T, class U> void test_arithmetic( U const & y, bool aligned )
31 test_buffer<T>( y, aligned );
35 BOOST_TEST_EQ( x.v + 7, y + 7 );
40 using namespace boost::endian;
44 test_buffer<big_float32_buf_t>( 3.1416f, false );
45 test_buffer<big_float64_buf_t>( 3.14159, false );
47 test_buffer<little_float32_buf_t>( 3.1416f, false );
48 test_buffer<little_float64_buf_t>( 3.14159, false );
50 test_buffer<native_float32_buf_t>( 3.1416f, false );
51 test_buffer<native_float64_buf_t>( 3.14159, false );
53 test_buffer<big_float32_buf_at>( 3.1416f, true );
54 test_buffer<big_float64_buf_at>( 3.14159, true );
56 test_buffer<little_float32_buf_at>( 3.1416f, true );
57 test_buffer<little_float64_buf_at>( 3.14159, true );
61 test_arithmetic<big_float32_t>( 3.1416f, false );
62 test_arithmetic<big_float64_t>( 3.14159, false );
64 test_arithmetic<little_float32_t>( 3.1416f, false );
65 test_arithmetic<little_float64_t>( 3.14159, false );
67 test_arithmetic<native_float32_t>( 3.1416f, false );
68 test_arithmetic<native_float64_t>( 3.14159, false );
70 test_arithmetic<big_float32_at>( 3.1416f, true );
71 test_arithmetic<big_float64_at>( 3.14159, true );
73 test_arithmetic<little_float32_at>( 3.1416f, true );
74 test_arithmetic<little_float64_at>( 3.14159, true );
76 return boost::report_errors();