Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Some interconversions between number types are completely generic,
- // and are always available, albeit the conversions are always explicit:
- cpp_int cppi(2);
- cpp_dec_float_50 df(cppi); // OK, int to float // <-- But fails with cpp_dec_float<0>!
- #include <boost/multiprecision/number.hpp>
- #include <boost/multiprecision/cpp_int.hpp>
- #include <boost/multiprecision/cpp_dec_float.hpp>
- int main()
- {
- boost::multiprecision::cpp_int n{ 0 };
- boost::multiprecision::cpp_dec_float<0> f{ n }; // Compile error in MSVC 2013
- }
- template <class R, class T>
- inline bool check_in_range(const T& t)
- {
- // Can t fit in an R?
- if(std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded
- && (t > (std::numeric_limits<R>::max)()))
- return true;
- return false;
- }
- #include <boost/multiprecision/number.hpp>
- #include <boost/multiprecision/cpp_int.hpp>
- #include <boost/multiprecision/cpp_dec_float.hpp>
- #include <iostream>
- namespace mp = boost::multiprecision;
- int main()
- {
- using Int = mp::cpp_int;
- // let's think of a nice large number
- Int n = 1;
- for (Int f = 42; f>0; --f)
- n *= f;
- std::cout << n << "nn"; // print it for vanity
- // let's convert it to cpp_dec_float
- // and... do something with it
- using Dec = mp::number<mp::cpp_dec_float<0> >;
- std::cout << n.convert_to<Dec>();
- }
- 1405006117752879898543142606244511569936384000000000
- 1.40501e+51
- Dec decfloat(n);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement