codac 1.5.6
Loading...
Searching...
No Matches
codac2_ceil.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Interval.h"
13#include "codac2_AnalyticType.h"
15
16namespace codac2
17{
18 struct CeilOp
19 {
20 static Interval fwd(const Interval& x1);
21 static ScalarType fwd_natural(const ScalarType& x1);
22 static ScalarType fwd_centered(const ScalarType& x1);
23 static void bwd(const Interval& y, Interval& x1);
24 };
25
26 // Analytic operator
27 // The following function can be used to build analytic expressions.
28
29 inline ScalarExpr
30 ceil(const ScalarExpr& x1)
31 {
32 return { std::make_shared<AnalyticOperationExpr<CeilOp,ScalarType,ScalarType>>(x1) };
33 }
34
35 // Inline functions
36
37 inline Interval CeilOp::fwd(const Interval& x1)
38 {
39 return ceil(x1);
40 }
41
42 inline ScalarType CeilOp::fwd_natural(const ScalarType& x1)
43 {
44 return {
45 fwd(x1.a),
46 x1.def_domain
47 };
48 }
49
50 inline ScalarType CeilOp::fwd_centered(const ScalarType& x1)
51 {
52 return {
53 fwd(x1.m),
54 fwd(x1.a),
55 IntervalMatrix(0,0), // not supported yet for auto diff
56 x1.def_domain
57 };
58 }
59
60 inline void CeilOp::bwd(const Interval& y, Interval& x1)
61 {
62 // The content of this function comes from the IBEX library.
63 // See ibex::Interval (IBEX lib, main author: Gilles Chabert)
64 // https://ibex-lib.readthedocs.io
65
66 if(y.is_empty())
67 x1.set_empty();
68
69 else
70 {
71 double r = std::floor(y.ub());
72 double l = std::ceil(y.lb());
73
74 if(r < l)
75 x1.set_empty();
76
77 else
78 x1 &= Interval(l,r) + Interval(-1,0);
79 }
80 }
81}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval ceil(const Interval &x)
Returns ceil of .
Definition codac2_Interval_operations_impl.h:294