mpfi_snips.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. //[mpfi_eg
  6. #include <boost/multiprecision/mpfi.hpp>
  7. #include <boost/math/special_functions/gamma.hpp>
  8. #include <iostream>
  9. int main()
  10. {
  11. using namespace boost::multiprecision;
  12. // Operations at variable precision and no numeric_limits support:
  13. mpfi_float a = 2;
  14. mpfi_float::default_precision(1000);
  15. std::cout << mpfi_float::default_precision() << std::endl;
  16. std::cout << sqrt(a) << std::endl; // print root-2
  17. // Operations at fixed precision and full numeric_limits support:
  18. mpfi_float_100 b = 2;
  19. std::cout << std::numeric_limits<mpfi_float_100>::digits << std::endl;
  20. // We can use any C++ std lib function:
  21. std::cout << log(b) << std::endl; // print log(2)
  22. // Access the underlying data:
  23. mpfi_t r;
  24. mpfi_init(r);
  25. mpfi_set(r, b.backend().data());
  26. // Construct some explicit intervals and perform set operations:
  27. mpfi_float_50 i1(1, 2), i2(1.5, 2.5);
  28. std::cout << intersect(i1, i2) << std::endl;
  29. std::cout << hull(i1, i2) << std::endl;
  30. std::cout << overlap(i1, i2) << std::endl;
  31. std::cout << subset(i1, i2) << std::endl;
  32. mpfi_clear(r);
  33. return 0;
  34. }
  35. //]