Skip to content

Instantly share code, notes, and snippets.

@Terminus-IMRC
Last active September 24, 2019 09:34
Show Gist options
  • Save Terminus-IMRC/dc1e12d5b274f830346a3af16ccfda5c to your computer and use it in GitHub Desktop.
Save Terminus-IMRC/dc1e12d5b274f830346a3af16ccfda5c to your computer and use it in GitHub Desktop.
Rump's example with MPFI
$ c++ rump.cpp -lmpfi -lmpfr -lgmp
$ for prec in 1 10 20 30 31 32 33 34 35 36 37 38 39 40; do ./a.out $prec; done
prec = 1: {-5.48801451098564180059512748897e+36,8.80613556589959273415384575891e+36}
prec = 10: {-719561148094296450146500608,1425281040027303069683286016}
prec = 20: {-108086391056891902.82763671875,144115188075855873.1728515625}
prec = 30: {-4194302.82739605994683529388567,4194305.17260394005319312782376}
prec = 31: {-524286.827396059946822859387794,524289.172603940053178916969046}
prec = 32: {-32766.8273960599468214160978619,1.17260394005317863186453174879}
prec = 33: {-4094.82739605994682137446449843,1.17260394005317863186453174879}
prec = 34: {-510.827396059946821369260328005,1.17260394005317863186453174879}
prec = 35: {-30.8273960599468213681761258327,1.17260394005317863186453174879}
prec = 36: {-2.82739605994682136814902077837,1.17260394005317863186453174879}
prec = 37: {-0.827396059946821368142244514793,-0.827396059946821368138856383004}
prec = 38: {-0.827396059946821368142244514793,-0.827396059946821368138856383004}
prec = 39: {-0.827396059946821368142244514793,-0.827396059946821368138856383004}
prec = 40: {-0.827396059946821368142244514793,-0.827396059946821368138856383004}
#include <iostream>
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/mpfi.hpp>
int main(const int argc, const char * const argv[])
{
if (argc != 1 + 1) {
std::cerr << "Usage: " << argv[0] << " precision" << std::endl;
std::cerr << "The precision is in decimal digits." << std::endl;
return 1;
}
const auto prec = std::stoull(argv[1]);
namespace mp = boost::multiprecision;
mp::mpfi_float::default_precision(prec);
mp::mpfi_float a = 77617, b = 33096, res;
res = (333.75 - a * a) * mp::pow(b, 6)
+ a * a * (11 * a * a * b * b - 121 * mp::pow(b, 4) - 2)
+ 5.5 * mp::pow(b, 8)
+ a / (2 * b);
std::cout << "prec = " << std::setw(2) << prec << ": "
<< std::setprecision(30) << res << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment