diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/multiprecision/test/issue_13301.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/multiprecision/test/issue_13301.cpp')
-rw-r--r-- | src/boost/libs/multiprecision/test/issue_13301.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/boost/libs/multiprecision/test/issue_13301.cpp b/src/boost/libs/multiprecision/test/issue_13301.cpp new file mode 100644 index 00000000..f2192d0e --- /dev/null +++ b/src/boost/libs/multiprecision/test/issue_13301.cpp @@ -0,0 +1,77 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright 2016 John Maddock. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/multiprecision/cpp_bin_float.hpp> + +int main() +{ + typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<8, boost::multiprecision::backends::digit_base_2> > quarter_float; + + quarter_float qf(256); + + unsigned int ui = qf.convert_to<unsigned int>(); + if (ui != 256) + return 1; + + boost::uintmax_t m(1), n; + m <<= std::numeric_limits<boost::uintmax_t>::digits - 1; + qf = m; + n = qf.convert_to<boost::uintmax_t>(); + if (m != n) + return 2; + qf *= 2; + n = qf.convert_to<boost::uintmax_t>(); + m = (std::numeric_limits<boost::uintmax_t>::max)(); + if (m != n) + return 3; + + qf = 256; + int si = qf.convert_to<int>(); + if (si != 256) + return 4; + boost::intmax_t sm(1), sn; + sm <<= std::numeric_limits<boost::intmax_t>::digits - 1; + qf = sm; + sn = qf.convert_to<boost::intmax_t>(); + if (sm != sn) + return 5; + qf *= 2; + sn = qf.convert_to<boost::intmax_t>(); + sm = (std::numeric_limits<boost::intmax_t>::max)(); + if (sm != sn) + return 6; + + // Again with negative numbers: + qf = -256; + si = qf.convert_to<int>(); + if (si != -256) + return 7; + sm = 1; + sm <<= std::numeric_limits<boost::intmax_t>::digits - 1; + sm = -sm; + qf = sm; + sn = qf.convert_to<boost::intmax_t>(); + if (sm != sn) + return 8; + qf *= 2; + sn = qf.convert_to<boost::intmax_t>(); + sm = (std::numeric_limits<boost::intmax_t>::min)(); + if (sm != sn) + return 9; + + // Now try conversion to cpp_int: + qf = 256; + boost::multiprecision::cpp_int i = qf.convert_to<boost::multiprecision::cpp_int>(), j; + if (i != 256) + return 10; + qf = ldexp(qf, 126); + i = qf.convert_to<boost::multiprecision::cpp_int>(); + j = 256; + j <<= 126; + if (i != j) + return 11; + + return 0; +} |