Why isn't inv_sqrt2 defined in the C++ standard library?

559 Views Asked by At

C++20 introduces standard library header, <numbers>, with definitions in namespace std::numbers for math constants such as sqrt2 and sqrt3. It provide inverse values like inv_sqrt3, but not inv_sqrt2. Why is inv_sqrt2 missing?

1

There are 1 best solutions below

5
On

Why is inv_sqrt2 missing?

The library defines a minimal set of commonly-used constants as precisely as the type will allow. It can be tricky to express (√3)-1 without introducing rounding errors, hence inv_sqrt3. However, (√2)-1 can easily be expressed as: sqrt2 / 2, so inv_sqrt2 isn't defined.