File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ execute : false
3+ ---
4+
5+ ## What It Does
6+
7+ Most functions in the ` <cmath> ` and ` <complex> ` headers are made ` constexpr ` .
8+
9+ ## Why It Matters
10+
11+ Historically, while arithmetic expressions such as addition and multiplication
12+ between floating-point operands could be used in constant expressions,
13+ common mathematical functions such as ` std::sqrt ` or ` std::pow ` couldn't be.
14+ This meant that some computations had to be done unnecessarily at runtime,
15+ or the user had to re-implement a ` constexpr ` version
16+ of the ` <cmath> ` functions themselves.
17+ The same applies to
18+
19+ ## Example
20+
21+ ``` cpp
22+ #include < cmath>
23+ #include < complex>
24+
25+ constexpr double sqrt_10 = std::sqrt(10 );
26+
27+ using namespace std ::complex_literals;
28+ constexpr std::complex<double > i = std::sqrt(-1i);
29+ ```
Original file line number Diff line number Diff line change @@ -309,8 +309,10 @@ features:
309309
310310 - desc : " More constexpr for `<cmath>` and `<complex>`"
311311 paper : P1383
312+ summary : " More mathematical functions are now `constexpr`, such as `std::sqrt`."
313+ content : more-constexpr-cmath.md
312314 lib : true
313- support : [GCC 4.6]
315+ support : [GCC 4.6 (partial) ]
314316 ftm :
315317 - name : __cpp_lib_constexpr_cmath
316318 value : 202306L
You can’t perform that action at this time.
0 commit comments