skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-numbers
This page is read only. You can view the source, but not change it.
# <numbers> **[<numbers>](https://en.cppreference.com/w/cpp/header/numbers)** provides mathematical constants (C++20): `std::numbers::pi`, `std::numbers::e`, `std::numbers::sqrt2`, etc. The constants are exact as `double` by default, but you can specialize them for other floating-point types. Use these instead of hardcoding `3.14159` or defining your own. This example uses the pi and sqrt2 constants to calculate the area of a circle and compose other mathematical expressions. ```cpp // compile: g++ -std=c++20 -o numbersexample numbersexample.cpp // run: ./numbersexample // description: use mathematical constants #include <numbers> #include <iostream> #include <cmath> int main() { double area = std::numbers::pi * 5.0 * 5.0; std::cout << "area of circle (r=5): " << area << "\n"; double result = std::numbers::e * std::numbers::sqrt2; std::cout << "e * sqrt(2): " << result << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top