Does STL contain definition for pi (=3.14...)? Certainly, I can use old good M_PI
, but it is non-standard and not cross-compiler compliant.
Asked
Active
Viewed 8,469 times
5

Deduplicator
- 44,692
- 7
- 66
- 118

Nick
- 3,205
- 9
- 57
- 108
-
1Nope. But you can use `acos(-1.0)` or something similar – Bartek Banachewicz Feb 19 '13 at 09:31
-
Also see [Best platform independent pi constant?](https://stackoverflow.com/q/21867617/1708801) – Shafik Yaghmour Apr 11 '18 at 17:48
1 Answers
4
Boost.Math defines pi (and many other) mathematical constants to very high precision
#include <boost/math/constants.hpp>
long double pi = boost::math::constants::pi<long double>();
A full list is available here.

Marshall Clow
- 15,972
- 2
- 29
- 45
-
If you need double precision then you can use the "template-free" constant like this: `double pi = boost::math::double_constants::pi;`. If you need several constants, then you may use a namespace alias like `namespace bmath = boost::math::double_constants;` and then refer to `bmath::pi`, `bmath::root_pi`, etc. – András Aszódi Jan 19 '14 at 13:55
-
2