MCPcopy Create free account
hub / github.com/Gecode/gecode / precision

Function precision

gecode/int/linear/int-post.cpp:78–150  ·  view source on GitHub ↗

Decide the required precision and check for overflow

Source from the content-addressed store, hash-verified

76
77 /// Decide the required precision and check for overflow
78 forceinline bool
79 precision(Term<IntView>* t_p, int n_p,
80 Term<IntView>* t_n, int n_n,
81 long long int d) {
82 long long int sl = 0;
83 long long int su = 0;
84
85 for (int i=0; i<n_p; i++) {
86 long long int axmin =
87 t_p[i].a * static_cast<long long int>(t_p[i].x.min());
88 if (Limits::overflow_add(sl,axmin))
89 throw OutOfLimits("Int::linear");
90 sl = sl + axmin;
91 long long int axmax =
92 t_p[i].a * static_cast<long long int>(t_p[i].x.max());
93 if (Limits::overflow_add(sl,axmax))
94 throw OutOfLimits("Int::linear");
95 su = su + axmax;
96 }
97 for (int i=0; i<n_n; i++) {
98 long long int axmax =
99 t_n[i].a * static_cast<long long int>(t_n[i].x.max());
100 if (Limits::overflow_sub(sl,axmax))
101 throw OutOfLimits("Int::linear");
102 sl = sl - axmax;
103 long long int axmin =
104 t_n[i].a * static_cast<long long int>(t_n[i].x.min());
105 if (Limits::overflow_sub(su,axmin))
106 throw OutOfLimits("Int::linear");
107 su = su - axmin;
108 }
109
110 bool is_ip = (sl >= Limits::min) && (su <= Limits::max);
111
112 if (Limits::overflow_sub(sl,d))
113 throw OutOfLimits("Int::linear");
114 sl = sl - d;
115 if (Limits::overflow_sub(su,d))
116 throw OutOfLimits("Int::linear");
117 su = su - d;
118
119 is_ip = is_ip && (sl >= Limits::min) && (su <= Limits::max);
120
121 for (int i=0; i<n_p; i++) {
122 long long int axmin =
123 t_p[i].a * static_cast<long long int>(t_p[i].x.min());
124 if (Limits::overflow_sub(sl,axmin))
125 throw OutOfLimits("Int::linear");
126 if (sl - axmin < Limits::min)
127 is_ip = false;
128 long long int axmax =
129 t_p[i].a * static_cast<long long int>(t_p[i].x.max());
130 if (Limits::overflow_sub(su,axmax))
131 throw OutOfLimits("Int::linear");
132 if (su - axmax > Limits::max)
133 is_ip = false;
134 }
135 for (int i=0; i<n_n; i++) {

Callers 1

postFunction · 0.85

Calls 2

minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected