Real constants and functions: Difference between revisions

(→‎{{header|C++}}: Boost lib)
Line 448:
 
=={{header|C++}}==
=== using Math macros ===
<lang cpp>#include <iostream>
#include <cmath>
Line 476 ⟶ 477:
<< "\npi^2 = " << std::pow(pi,2.0) << std::endl;
}</lang>
=== using Boost ===
{{libheader|Boost}}
<lang cpp>#include <iostream>
#include <iomanip>
#include <cmath>
#include <boost/math/constants/constants.hpp>
 
int main()
{
using namespace boost::math::double_constants;
std::cout << "e = " << std::setprecision(18) << e
<< "\ne³ = " << std::exp(3.0)
<< "\nπ = " << pi
<< "\nπ² = " << pi_sqr
<< "\n√2 = " << root_two
<< "\nln(e) = " << std::log(e)
<< "\nlg(100) = " << std::log10(100.0)
<< "\n|-4.5| = " << std::abs(-4.5) // or std::fabs(4.0); both work in C++
<< "\nfloor(4.5) = " << std::floor(4.5)
<< "\nceiling(4.5) = " << std::ceil(4.5) << std::endl;
}</lang>
{{out}}
<pre>e = 2.71828182845904509
e³ = 20.0855369231876679
π = 3.14159265358979312
π² = 9.86960440108935799
√2 = 1.41421356237309515
ln(e) = 1
lg(100) = 2
|-4.5| = 4.5
floor(4.5) = 4
ceiling(4.5) = 5</pre>
 
=={{header|Chef}}==
Anonymous user