From d7f4d2125d15d31d91dd986ca3c3f1e21d8d1ff4 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 18 Feb 2025 11:07:46 +0100 Subject: [PATCH] update --- .../expressions/visitors/EvalVisitor.h | 31 ++++++++----------- .../optim-model-filler/LinearExpression.cpp | 1 - 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/expressions/include/antares/expressions/visitors/EvalVisitor.h b/src/expressions/include/antares/expressions/visitors/EvalVisitor.h index 4b1bb9c85e..a255cd62f4 100644 --- a/src/expressions/include/antares/expressions/visitors/EvalVisitor.h +++ b/src/expressions/include/antares/expressions/visitors/EvalVisitor.h @@ -71,29 +71,24 @@ class EvaluationResult struct SafeDivides { - double operator()(double lhs, double rhs) const + static constexpr double DEFAULT_THRESHOLD = 1e-16; + + explicit SafeDivides(double threshold = DEFAULT_THRESHOLD): + threshold_(threshold) { - // if (rhs == 0.0) - // { - // throw std::runtime_error("Division by zero in EvaluationResult."); - // } - double result{0.}; - try - { - result = lhs / rhs; + } - if (!std::isfinite(result)) - { - throw EvalVisitorDivisionException(lhs, rhs, "is not a finite number"); - } - } - catch (const std::exception& ex) + double operator()(double lhs, double rhs) const + { + if (std::abs(rhs) <= threshold_) { - throw EvalVisitorDivisionException(lhs, rhs, ex.what()); + throw EvalVisitorDivisionException(lhs, rhs, "Division by zero"); } - - return result; + return lhs / rhs; } + + private: + double threshold_; }; EvaluationResult operator/(const EvaluationResult& right) const diff --git a/src/solver/optim-model-filler/LinearExpression.cpp b/src/solver/optim-model-filler/LinearExpression.cpp index bb740b1d63..891362d062 100644 --- a/src/solver/optim-model-filler/LinearExpression.cpp +++ b/src/solver/optim-model-filler/LinearExpression.cpp @@ -42,7 +42,6 @@ struct IdentityFunction * value. For every key: value = left_value + rhs_multiplier * right_value * @param left The left hand side map * @param right The right hand side map - * @param rhs_multiplier The multiplier to apply to the right hand side map * @return The map resulting from the operation */ template>