cpp_bin_float_snips.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2013 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_bin_float_eg
  6. #include <boost/multiprecision/cpp_bin_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_bin_float_100 b = 2;
  14. std::cout << std::numeric_limits<cpp_bin_float_100>::digits << std::endl;
  15. std::cout << std::numeric_limits<cpp_bin_float_100>::digits10 << std::endl;
  16. // We can use any C++ std lib function, lets print all the digits as well:
  17. std::cout << std::setprecision(std::numeric_limits<cpp_bin_float_100>::max_digits10)
  18. << log(b) << std::endl; // print log(2)
  19. // We can also use any function from Boost.Math:
  20. std::cout << boost::math::tgamma(b) << std::endl;
  21. // These even work when the argument is an expression template:
  22. std::cout << boost::math::tgamma(b * b) << std::endl;
  23. // And since we have an extended exponent range we can generate some really large
  24. // numbers here (4.0238726007709377354370243e+2564):
  25. std::cout << boost::math::tgamma(cpp_bin_float_100(1000)) << std::endl;
  26. return 0;
  27. }
  28. //]