Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Feb 18, 2025
1 parent f695540 commit d7f4d21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
31 changes: 13 additions & 18 deletions src/expressions/include/antares/expressions/visitors/EvalVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/solver/optim-model-filler/LinearExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Key, typename Value, typename UnaryOp = IdentityFunction<Value>>
Expand Down

0 comments on commit d7f4d21

Please sign in to comment.