App: Use std::numeric_limits and std::numbers instead of defines

This commit is contained in:
Benjamin Nauck
2025-03-27 11:47:55 +01:00
parent db8b58f73e
commit 81e0b408fa
10 changed files with 59 additions and 59 deletions

View File

@@ -34,6 +34,8 @@
#include <boost/math/special_functions/round.hpp>
#include <boost/math/special_functions/trunc.hpp>
#include <numbers>
#include <limits>
#include <sstream>
#include <stack>
#include <string>
@@ -62,19 +64,6 @@ using namespace App;
FC_LOG_LEVEL_INIT("Expression", true, true)
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif
#ifndef DOUBLE_MAX
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
#endif
#ifndef DOUBLE_MIN
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
#endif
#if defined(_MSC_VER)
#define strtoll _strtoi64
#pragma warning(disable : 4003)
@@ -336,22 +325,22 @@ static inline int essentiallyInteger(double a, long &l, int &i) {
double intpart;
if (std::modf(a,&intpart) == 0.0) {
if (intpart<0.0) {
if (intpart >= INT_MIN) {
if (intpart >= std::numeric_limits<int>::min()) {
i = static_cast<int>(intpart);
l = i;
return 1;
}
if (intpart >= LONG_MIN) {
if (intpart >= std::numeric_limits<long>::min()) {
l = static_cast<long>(intpart);
return 2;
}
}
else if (intpart <= INT_MAX) {
else if (intpart <= std::numeric_limits<int>::max()) {
i = static_cast<int>(intpart);
l = i;
return 1;
}
else if (intpart <= static_cast<double>(LONG_MAX)) {
else if (intpart <= static_cast<double>(std::numeric_limits<long>::max())) {
l = static_cast<int>(intpart);
return 2;
}
@@ -363,12 +352,12 @@ static inline bool essentiallyInteger(double a, long &l) {
double intpart;
if (std::modf(a,&intpart) == 0.0) {
if (intpart<0.0) {
if (intpart >= LONG_MIN) {
if (intpart >= std::numeric_limits<long>::min()) {
l = static_cast<long>(intpart);
return true;
}
}
else if (intpart <= static_cast<double>(LONG_MAX)) {
else if (intpart <= static_cast<double>(std::numeric_limits<long>::max())) {
l = static_cast<long>(intpart);
return true;
}
@@ -2150,6 +2139,8 @@ Base::Vector3d FunctionExpression::extractVectorArgument(
Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std::vector<Expression*> &args)
{
using std::numbers::pi;
if(!expr || !expr->getOwner())
_EXPR_THROW("Invalid owner.", expr);
@@ -2186,7 +2177,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std
Py::Object pyobj = args[0]->getPyValue();
if (PyObject_TypeCheck(pyobj.ptr(), &Base::MatrixPy::Type)) {
auto m = static_cast<Base::MatrixPy*>(pyobj.ptr())->value();
if (fabs(m.determinant()) <= DBL_EPSILON)
if (fabs(m.determinant()) <= std::numeric_limits<double>::epsilon())
_EXPR_THROW("Cannot invert singular matrix.", expr);
m.inverseGauss();
return Py::asObject(new Base::MatrixPy(m));
@@ -2227,7 +2218,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std
Rotation rotation = Base::Rotation(
Vector3d(static_cast<double>(f == MROTATEX), static_cast<double>(f == MROTATEY), static_cast<double>(f == MROTATEZ)),
rotationAngle.getValue() * M_PI / 180.0);
rotationAngle.getValue() * pi / 180.0);
Base::Matrix4D rotationMatrix;
rotation.getValue(rotationMatrix);
@@ -2366,7 +2357,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std
switch (f) {
case VANGLE:
return Py::asObject(new QuantityPy(new Quantity(vector1.GetAngle(vector2) * 180 / M_PI, Unit::Angle)));
return Py::asObject(new QuantityPy(new Quantity(vector1.GetAngle(vector2) * 180 / pi, Unit::Angle)));
case VCROSS:
return Py::asObject(new Base::VectorPy(vector1.Cross(vector2)));
case VDOT:
@@ -2425,7 +2416,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std
_EXPR_THROW("Unit must be either empty or an angle.", expr);
// Convert value to radians
value *= M_PI / 180.0;
value *= pi / 180.0;
unit = Unit();
break;
case ACOS:
@@ -2434,7 +2425,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std
if (!v1.isDimensionless())
_EXPR_THROW("Unit must be empty.", expr);
unit = Unit::Angle;
scaler = 180.0 / M_PI;
scaler = 180.0 / pi;
break;
case EXP:
case LOG:
@@ -2466,7 +2457,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std
if (v1.getUnit() != v2.getUnit())
_EXPR_THROW("Units must be equal.",expr);
unit = Unit::Angle;
scaler = 180.0 / M_PI;
scaler = 180.0 / pi;
break;
case MOD:
if (e2.isNone())