Skip to content

Commit

Permalink
Fix for cpp_int conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzmaddock committed Sep 15, 2016
1 parent e33ada0 commit b210886
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/boost/multiprecision/cpp_int/misc.hpp
Expand Up @@ -541,6 +541,7 @@ template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignTy
inline typename enable_if_c<
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
&& is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
&& boost::is_convertible<typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::local_limb_type, R>::value
>::type
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val)
{
Expand Down Expand Up @@ -574,6 +575,7 @@ template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignTy
inline typename enable_if_c<
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
&& boost::is_convertible<typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::local_limb_type, R>::value
>::type
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val)
{
Expand Down
28 changes: 28 additions & 0 deletions test/test_cpp_bin_float_conv.cpp
Expand Up @@ -51,6 +51,34 @@ int main()
f100d = ui32.convert_to<cpp_bin_float_100>();
BOOST_CHECK_EQUAL(f100d, 98);

typedef number<cpp_int_backend<64, 64>, et_off> i64_t;
i64_t i64(67);
cpp_bin_float_100 f100e(i64);
BOOST_CHECK_EQUAL(f100e, 67);
f100e = i64.convert_to<cpp_bin_float_100>();
BOOST_CHECK_EQUAL(f100e, 67);

typedef number<cpp_int_backend<64, 64, unsigned_magnitude>, et_off> ui64_t;
ui64_t ui64(98);
cpp_bin_float_100 f100f(ui64);
BOOST_CHECK_EQUAL(f100f, 98);
f100f = ui64.convert_to<cpp_bin_float_100>();
BOOST_CHECK_EQUAL(f100f, 98);

typedef number<cpp_int_backend<128, 128>, et_off> i128_t;
i128_t i128(67);
cpp_bin_float_100 f100g(i128);
BOOST_CHECK_EQUAL(f100g, 67);
f100g = i128.convert_to<cpp_bin_float_100>();
BOOST_CHECK_EQUAL(f100g, 67);

typedef number<cpp_int_backend<128, 128, unsigned_magnitude>, et_off> ui128_t;
ui128_t ui128(98);
cpp_bin_float_100 f100h(ui128);
BOOST_CHECK_EQUAL(f100h, 98);
f100h = ui128.convert_to<cpp_bin_float_100>();
BOOST_CHECK_EQUAL(f100h, 98);

return boost::report_errors();
}

Expand Down

0 comments on commit b210886

Please sign in to comment.