19 static inline double canonical_mod(
double x,
double p)
21 double r = std::fmod(x, p);
28 template<
typename X1,
typename P>
29 static std::string str(
const X1& x1,
const P& p)
31 return "mod(" + x1->str() +
"," + p->str() +
")";
34 template<
typename X1,
typename P>
35 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const P& p)
40 static Interval fwd(
const Interval& x1,
const Interval& p);
41 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& p);
42 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& p);
43 static void bwd(
const Interval& y, Interval& x1, Interval& p);
45 static void fwd_bwd(Interval& y, Interval& x1,
double p);
46 static void fwd_bwd(Interval& y, Interval& x1, Interval& p);
53 mod(
const ScalarExpr& x1,
const ScalarExpr& p)
55 return { std::make_shared<AnalyticOperationExpr<ModOp,ScalarType,ScalarType,ScalarType>>(x1,p) };
62 if(x1.is_empty() || p.is_empty())
70 if(x1.is_degenerated() && pp.is_degenerated())
71 return { canonical_mod(x1.lb(), pp.lb()) };
74 if(x1.lb() >= 0.0 && x1.ub() < pp.lb())
78 if(pp.lb() == pp.ub())
80 const double q = pp.lb();
81 const double k1 = std::floor(x1.lb() / q);
82 const double k2 = std::floor(x1.ub() / q);
87 return x1 - (Interval(k1) * q);
94 yub = std::min(yub, x1.ub());
99 inline ScalarType ModOp::fwd_natural(
const ScalarType& x1,
const ScalarType& p)
103 x1.def_domain && p.def_domain
107 inline ScalarType ModOp::fwd_centered(
const ScalarType& x1,
const ScalarType& p)
109 if(centered_form_not_available_for_args(x1,p))
110 return fwd_natural(x1,p);
116 x1.def_domain && p.def_domain
128 if(y.is_empty() || x1.is_empty() || p.is_empty())
144 Interval y0 = y & Interval(0.0, p.ub());
153 Interval r = (x1-y0)/p;
155 const double kmin_d = std::ceil(r.lb());
156 const double kmax_d = std::floor(r.ub());
158 if(!(kmin_d <= kmax_d))
164 Interval K(kmin_d, kmax_d);
186 y0 &= Interval(0.0, p.ub());
205 ModOp::fwd_bwd(y,x1,ip);
210 y &= ModOp::fwd(x1,p);
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:568
void set_empty()
Marks the interval matrix as empty.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:141
Definition codac2_OctaSym.h:21
double next_float(double x)
Returns the next representable double-precision floating-point value after x.
Definition codac2_Interval_impl.h:619
Eigen::Matrix< Interval,-1,-1 > IntervalMatrix
Alias for a dynamic-size matrix of intervals.
Definition codac2_IntervalMatrix.h:25