This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: math constants
Hey,
2013/2/1 Ulrich Drepper <drepper@gmail.com>:
...
>
> Aside from the fact that this is unnecessarily long it also means some
> platforms won't have all the precision. Shouldn't we add as an
> extension some constants like this:
>
> template<typename _RealType>
> struct math_constants {
> static constexpr _RealType pi =
> _RealType(3.141592653589793238462643383279502884197169399375105820974944L);
> static constexpr _RealType root_pi =
> _RealType(1.772453850905516027298167483341145182797549456122387128213808L);
> };
>
> This variant would be implemented without any macros. With macros the
> ugly long double constant in _RealType constructor could be avoided
> but at least -Wall doesn't warn.
>
Using c++11 uniform initialization syntax should be fine with -Wall,
so If you really want avoid duck-typing it would be:
template<typename _RealType>
struct math_constants {
static constexpr _RealType
pi{3.141592653589793238462643383279502884197169399375105820974944L};
static constexpr _RealType
root_pi{1.772453850905516027298167483341145182797549456122387128213808L};
};
Tried with 4.7 and worked as expected. ;-)
> Would this be an acceptable patch?
Cheers,
/Piotr