C++20 modernization: use new standard mathematical constants

master
Sébastien Villemot 2023-05-25 19:03:20 +02:00
parent a59e8557b4
commit 3cc531315b
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 6 additions and 4 deletions

View File

@ -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);

View File

@ -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