Ramanujan's constant: Difference between revisions

Added C++ solution
m (Phix/mpfr)
(Added C++ solution)
Line 5:
show that when evaluated with the last four [https://en.wikipedia.org/wiki/Heegner_number Heegner numbers]
the result is ''almost'' an integer.
 
=={{header|C++}}==
{{libheader|Boost}}
<lang cpp>#include <iomanip>
#include <iostream>
#include <boost/math/constants/constants.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
 
using big_float = boost::multiprecision::cpp_dec_float_100;
 
big_float f(unsigned int n) {
big_float pi(boost::math::constants::pi<big_float>());
return exp(sqrt(big_float(n)) * pi);
}
 
int main() {
std::cout << "Ramanujan's constant using formula f(N) = exp(pi*sqrt(N)):\n"
<< std::setprecision(80) << f(163) << '\n';
std::cout << "\nResult with last four Heegner numbers:\n";
std::cout << std::setprecision(30);
for (unsigned int n : {19, 43, 67, 163}) {
auto x = f(n);
auto c = ceil(x);
auto pc = 100.0 * (x/c);
std::cout << "f(" << n << ") = " << x << " = "
<< pc << "% of " << c << '\n';
}
return 0;
}</lang>
 
{{out}}
<pre>
Ramanujan's constant using formula f(N) = exp(pi*sqrt(N)):
262537412640768743.99999999999925007259719818568887935385633733699086270753741038
 
Result with last four Heegner numbers:
f(19) = 885479.777680154319497537893482 = 99.9999748927309842681413350366% of 885480
f(43) = 884736743.999777466034906661937 = 99.9999999999748474372063224648% of 884736744
f(67) = 147197952743.999998662454224507 = 99.9999999999999990913285473342% of 147197952744
f(163) = 262537412640768743.999999999999 = 99.9999999999999999999999999997% of 262537412640768744
</pre>
 
=={{header|Fōrmulæ}}==
1,777

edits