Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 423
John McFarlane Avatar asked May 19 '20 21:05

John McFarlane


1 Answers

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.

like image 73
John McFarlane Avatar answered Oct 02 '22 17:10

John McFarlane