Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions content/more-constexpr-cmath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
execute: false
---

## What It Does

Most functions in the `<cmath>` and `<complex>` headers are made `constexpr`.

## Why It Matters

Historically, while arithmetic expressions such as addition and multiplication
between floating-point operands could be used in constant expressions,
common mathematical functions such as `std::sqrt` or `std::pow` couldn't be.
This meant that some computations had to be done unnecessarily at runtime,
or the user had to re-implement a `constexpr` version
of the `<cmath>`functions themselves.
The same applies to the corresponding functions in `<complex>`.

## Example

```cpp
#include <cmath>
#include <complex>

constexpr double sqrt_10 = std::sqrt(10);
constexpr std::complex<double> i = std::sqrt(std::complex<double>(-1));
```
4 changes: 3 additions & 1 deletion features_cpp26.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ features:

- desc: "More constexpr for `<cmath>` and `<complex>`"
paper: P1383
summary: "More mathematical functions are now `constexpr`, such as `std::sqrt`."
content: more-constexpr-cmath.md
lib: true
support: [GCC 4.6]
support: [GCC 4.6 (partial)]
ftm:
- name: __cpp_lib_constexpr_cmath
value: 202306L
Expand Down