Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // Some interconversions between number types are completely generic,
  2. // and are always available, albeit the conversions are always explicit:
  3.  
  4. cpp_int cppi(2);
  5. cpp_dec_float_50 df(cppi); // OK, int to float // <-- But fails with cpp_dec_float<0>!
  6.  
  7. #include <boost/multiprecision/number.hpp>
  8. #include <boost/multiprecision/cpp_int.hpp>
  9. #include <boost/multiprecision/cpp_dec_float.hpp>
  10.  
  11. int main()
  12. {
  13. boost::multiprecision::cpp_int n{ 0 };
  14. boost::multiprecision::cpp_dec_float<0> f{ n }; // Compile error in MSVC 2013
  15. }
  16.  
  17. template <class R, class T>
  18. inline bool check_in_range(const T& t)
  19. {
  20. // Can t fit in an R?
  21. if(std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded
  22. && (t > (std::numeric_limits<R>::max)()))
  23. return true;
  24. return false;
  25. }
  26.  
  27. #include <boost/multiprecision/number.hpp>
  28. #include <boost/multiprecision/cpp_int.hpp>
  29. #include <boost/multiprecision/cpp_dec_float.hpp>
  30. #include <iostream>
  31.  
  32. namespace mp = boost::multiprecision;
  33.  
  34. int main()
  35. {
  36. using Int = mp::cpp_int;
  37.  
  38. // let's think of a nice large number
  39. Int n = 1;
  40. for (Int f = 42; f>0; --f)
  41. n *= f;
  42.  
  43. std::cout << n << "nn"; // print it for vanity
  44.  
  45. // let's convert it to cpp_dec_float
  46. // and... do something with it
  47. using Dec = mp::number<mp::cpp_dec_float<0> >;
  48. std::cout << n.convert_to<Dec>();
  49. }
  50.  
  51. 1405006117752879898543142606244511569936384000000000
  52.  
  53. 1.40501e+51
  54.  
  55. Dec decfloat(n);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement