From 3cc531315bd5abe5fe9d53145ec3c3de6723f1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Thu, 25 May 2023 19:03:20 +0200 Subject: [PATCH] C++20 modernization: use new standard mathematical constants --- src/ExprNode.cc | 5 +++-- src/macro/Expressions.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 7b1a86d7..7b8c4151 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -24,6 +24,7 @@ #include <utility> #include <limits> #include <numeric> +#include <numbers> #include "ExprNode.hh" #include "DataTree.hh" @@ -6118,9 +6119,9 @@ TrinaryOpNode::eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v switch (op_code) { case TrinaryOpcode::normcdf: - return (0.5*(1+erf((v1-v2)/v3/M_SQRT2))); + return (0.5*(1+erf((v1-v2)/v3/numbers::sqrt2))); case TrinaryOpcode::normpdf: - return (1/(v3*sqrt(2*M_PI)*exp(pow((v1-v2)/v3, 2)/2))); + return (1/(v3*sqrt(2*numbers::pi)*exp(pow((v1-v2)/v3, 2)/2))); } // Suppress GCC warning exit(EXIT_FAILURE); diff --git a/src/macro/Expressions.cc b/src/macro/Expressions.cc index 54f74700..83fd7b3a 100644 --- a/src/macro/Expressions.cc +++ b/src/macro/Expressions.cc @@ -18,6 +18,7 @@ */ #include <utility> +#include <numbers> #include "Expressions.hh" @@ -240,7 +241,7 @@ Real::normpdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const auto btp22 = dynamic_pointer_cast<Real>(btp2); if (!btp12 || !btp22) throw StackTrace("Type mismatch for operands of `normpdf` operator"); - return make_shared<Real>((1/(btp22->value*std::sqrt(2*M_PI)*std::exp(pow((value-btp12->value)/btp22->value, 2)/2)))); + return make_shared<Real>((1/(btp22->value*std::sqrt(2*numbers::pi)*std::exp(pow((value-btp12->value)/btp22->value, 2)/2)))); } RealPtr @@ -250,7 +251,7 @@ Real::normcdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const auto btp22 = dynamic_pointer_cast<Real>(btp2); if (!btp12 || !btp22) throw StackTrace("Type mismatch for operands of `normpdf` operator"); - return make_shared<Real>((0.5*(1+std::erf((value-btp12->value)/btp22->value/M_SQRT2)))); + return make_shared<Real>((0.5*(1+std::erf((value-btp12->value)/btp22->value/numbers::sqrt2)))); } BaseTypePtr -- GitLab