Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- #include <cmath>
- #include <boost/multiprecision/cpp_int.hpp>
- #include <boost/multiprecision/mpfr.hpp>
- int main()
- {
- namespace mp = boost::multiprecision;
- using namespace boost::multiprecision;
- // mpfr_float
- mpfr_float a = 2;
- std::cout << "Operations at variable precision and no numeric_limits support:" << std::endl;
- mpfr_float::default_precision(1000);
- std::cout << "mpfr_float::default_precision() = " << mpfr_float::default_precision() << std::endl;
- std::cout << "sqrt(2) = " << sqrt(a) << std::endl;
- // fixed precision mpfr_float_100 and full numeric_limits support:
- mpfr_float_100 testmpfr = 24153319581254312065344.0;
- std::cout << "digits : " << std::numeric_limits<mpfr_float_100>::digits << std::endl;
- std::cout << "digit10 : " << std::numeric_limits<mpfr_float_100>::digits10 << std::endl;
- // We can use any C++ std lib function:
- std::cout << "root-2 std sqrt(a) = " << sqrt(a) << std::endl; // print root-2
- int256_t taxicabnumber;
- std::cout << "Anna taxicabnumber = 24153319581254312065344 " << std::endl;
- std::cin >> taxicabnumber;
- std::cout << "boost::math:cbrt(testmpfr) = " << boost::math::cbrt(testmpfr) << std::endl;
- std::cout << "mp:cbrt(testmpfr) = " << mp::cbrt(testmpfr) << std::endl;
- mpfr_float_100 taxi = taxicabnumber.convert_to<mp::mpfr_float_100>();
- std::cout << "Operations at fixed precision and full numeric_limits support:" << std::endl;
- std::cout << "wikipedia sqrt(2) = 1.41421356237309504880168872420969807856967187537694807317667973799..." << std::endl;
- std::cout << "wolfram: cubitroot(2) = 1.259921049894873164767210607278228350570251464701507980081..." << std::endl;
- mpfr_float_100 bfr = 2;
- // tulostus maksimitarkuudella eli 100-bit
- // We can use any C++ std lib function:
- std::cout << "tulostus 100 numeron tarkkuudella " << std::endl;
- std::cout << std::setprecision(std::numeric_limits<mpfr_float_100>::max_digits10) << std::endl;
- std::cout << "sqrt(testmpfr) = " << sqrt(testmpfr) << std::endl;
- std::cout << "sqrt(bfr) = " << sqrt(bfr) << std::endl;
- std::cout << "log(bfr) = " << log(bfr) << std::endl; // print log(2)
- // We can also use any function from Boost.Math:
- std::cout << "mp::sqrt(testmpfr) = " << mp::sqrt(testmpfr) << std::endl;
- std::cout << "mp::sqrt(bfr) = " << mp::sqrt(bfr) << std::endl;
- std::cout << "mp::log(bfr) = " << mp::log(bfr) << std::endl;
- std::cout << "mp::cbrt(bfr) = " << mp::cbrt(bfr) << std::endl;
- std::cout << "boost::math::tgamma(bfr) = " << boost::math::tgamma(bfr) << std::endl;
- // These even work when the argument is an expression template:
- std::cout << "boost::math::tgamma(bfr*bfr) = " << boost::math::tgamma(bfr * bfr) << std::endl;
- std::cout << "mp::pow(taxi,1/3.0) = " << mp::pow(taxi,1/3.0) << std::endl;
- int128_t raja;
- raja = (mp::pow(taxi,1/3.0) +0.5).convert_to<int128_t>();
- std::cout << "raja = " << raja << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment