4

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
  • 43,322
  • 6
  • 62
  • 109
Nick
  • 2,905
  • 8
  • 55
  • 100

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,001
  • 2
  • 27
  • 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. – Laryx Decidua Jan 19 '14 at 13:55
  • 1
    In boost 1.57 the include is actually `` – void.pointer Jan 06 '15 at 20:21