diff options
author | Chris Robinson <[email protected]> | 2022-01-27 01:38:39 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-01-27 01:38:39 -0800 |
commit | 1bbea9cd3060ef65a2623f156b4f12ebf62c52fe (patch) | |
tree | 005d29f38edcd1b985e52fc49b4e58fb0ba1721e /common/alnumbers.h | |
parent | 423888b8162f9d78ec4f1b00b8368f3ba22eedd6 (diff) |
Start and use a standard-like numbers header
Diffstat (limited to 'common/alnumbers.h')
-rw-r--r-- | common/alnumbers.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/common/alnumbers.h b/common/alnumbers.h new file mode 100644 index 00000000..98994b44 --- /dev/null +++ b/common/alnumbers.h @@ -0,0 +1,32 @@ +#ifndef COMMON_ALNUMBERS_H +#define COMMON_ALNUMBERS_H + +#include <utility> + +namespace al { + +namespace numbers { + +namespace detail_ { + template<typename T> + using as_fp = std::enable_if_t<std::is_floating_point<T>::value, T>; +} // detail_ + +template<typename T> +static constexpr auto pi_v = detail_::as_fp<T>(3.141592653589793238462643383279502884L); + +template<typename T> +static constexpr auto inv_pi_v = detail_::as_fp<T>(0.318309886183790671537767526745028724L); + +template<typename T> +static constexpr auto sqrt3_v = detail_::as_fp<T>(1.732050807568877293527446341505872367L); + +static constexpr auto pi = pi_v<double>; +static constexpr auto inv_pi = inv_pi_v<double>; +static constexpr auto sqrt3 = sqrt3_v<double>; + +} // namespace numbers + +} // namespace al + +#endif /* COMMON_ALNUMBERS_H */ |