5

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.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Nick
  • 3,205
  • 9
  • 57
  • 108

1 Answers1

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
    In boost 1.57 the include is actually `` – void.pointer Jan 06 '15 at 20:21