Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Math constants

Use case

Standard mathematical constants.

Explanation

No more #define PI 3.14159....

Code

#include <iostream>
#include <numbers>

int main() {
  double radius = 16.0;
  double circumference = 2 * std::numbers::pi * radius;

  std::cout << "Circumference: " << circumference << "\n";

  return 0;
}

View on GitHub.

Output

$ ./src/c++20/build/math-constants
Circumference: 100.531