Skip to content

Commit d38b3ef

Browse files
committed
Add and correct information on P1383
1 parent d5a81ab commit d38b3ef

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

content/more-constexpr-cmath.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
```

features_cpp26.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)