cpp_dec_float_snips.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2011 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
  5. //[cpp_dec_float_eg
  6. #include <boost/multiprecision/cpp_dec_float.hpp>
  7. #include <boost/math/special_functions/gamma.hpp>
  8. #include <iostream>
  9. int main()
  10. {
  11. using namespace boost::multiprecision;
  12. // Operations at fixed precision and full numeric_limits support:
  13. cpp_dec_float_100 b = 2;
  14. std::cout << std::numeric_limits<cpp_dec_float_100>::digits << std::endl;
  15. // Note that digits10 is the same as digits, since we're base 10! :
  16. std::cout << std::numeric_limits<cpp_dec_float_100>::digits10 << std::endl;
  17. // We can use any C++ std lib function, lets print all the digits as well:
  18. std::cout << std::setprecision(std::numeric_limits<cpp_dec_float_100>::max_digits10)
  19. << log(b) << std::endl; // print log(2)
  20. // We can also use any function from Boost.Math:
  21. std::cout << boost::math::tgamma(b) << std::endl;
  22. // These even work when the argument is an expression template:
  23. std::cout << boost::math::tgamma(b * b) << std::endl;
  24. // And since we have an extended exponent range we can generate some really large
  25. // numbers here (4.0238726007709377354370243e+2564):
  26. std::cout << boost::math::tgamma(cpp_dec_float_100(1000)) << std::endl;
  27. return 0;
  28. }
  29. //]