float128_snips.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. //[float128_eg
  6. #include <boost/multiprecision/float128.hpp>
  7. #include <boost/math/special_functions/gamma.hpp>
  8. #include <iostream>
  9. int main()
  10. {
  11. using namespace boost::multiprecision;
  12. // Operations at 128-bit precision and full numeric_limits support:
  13. float128 b = 2;
  14. // There are 113-bits of precision:
  15. std::cout << std::numeric_limits<float128>::digits << std::endl;
  16. // Or 34 decimal places:
  17. std::cout << std::numeric_limits<float128>::digits10 << std::endl;
  18. // We can use any C++ std lib function, lets print all the digits as well:
  19. std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10)
  20. << log(b) << std::endl; // print log(2) = 0.693147180559945309417232121458176575
  21. // We can also use any function from Boost.Math:
  22. std::cout << boost::math::tgamma(b) << std::endl;
  23. // And since we have an extended exponent range we can generate some really large
  24. // numbers here (4.02387260077093773543702433923004111e+2564):
  25. std::cout << boost::math::tgamma(float128(1000)) << std::endl;
  26. //
  27. // We can declare constants using GCC or Intel's native types, and the Q suffix,
  28. // these can be declared constexpr if required:
  29. /*<-*/
  30. #ifndef BOOST_NO_CXX11_CONSTEXPR
  31. /*->*/
  32. constexpr float128 pi = 3.1415926535897932384626433832795028841971693993751058Q;
  33. /*<-*/
  34. #endif
  35. /*->*/
  36. return 0;
  37. }
  38. //]