P0631R8 Math Constants C++20で数学定数が入ることが決まりましたね。やっと標準ライブラリの範囲で円周率を定数として使えるようになります。 ここまでの道のりですが、 constexpr (C++11) 変数テンプレート (C++14) インライン変数 (C++17) 数学定数 (C++20) とても長かったですね。 #include <iostream> #include <numbers> template <class T> T degree_to_radian(T x) { return x * std::numbers::pi_v<T> / static_cast<T>(180.0); } int main() { float y = degree_to_radian(90.0f); std::cout << y << std::endl; // 1.570