Skip to content

Commit 5bf1302

Browse files
authored
DPL Analysis: add protect0 node for preventing division by 0 in expressions (#14338)
1 parent 81604b4 commit 5bf1302

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Framework/Core/include/Framework/Expressions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Framework/Variant.h"
1818
#include "Framework/InitContext.h"
1919
#include "Framework/ConfigParamRegistry.h"
20+
#include "CommonConstants/MathConstants.h"
2021
#include <arrow/type_fwd.h>
2122
#include <gandiva/gandiva_aliases.h>
2223
#include <arrow/type.h>
@@ -554,6 +555,13 @@ inline Node clamp(Node&& expr, T low, T hi)
554555
return ifnode(Node{copy} < LiteralNode{low}, LiteralNode{low}, ifnode(Node{copy} > LiteralNode{hi}, LiteralNode{hi}, Node{copy}));
555556
}
556557

558+
/// division by 0 protector
559+
inline Node protect0(Node&& expr)
560+
{
561+
auto copy = expr;
562+
return ifnode(nabs(Node{copy}) < o2::constants::math::Almost0, o2::constants::math::Almost0, Node{copy});
563+
}
564+
557565
/// A struct, containing the root of the expression tree
558566
struct Filter {
559567
Filter() = default;

0 commit comments

Comments
 (0)