2 * This file contains the rounding policies needed from the boost interval class
3 * for the FLOAT_T<FloatType> type used in carl.
6 * @author Stefan Schupp <stefan.schupp@cs.rwth-aachen.de>
13 #include "../../numbers/numbers.h"
17 template<typename FloatType>
18 struct rounding<FLOAT_T<FloatType> >
20 // default constructor, destructor
23 // mathematical operations
24 FLOAT_T<FloatType> add_down(FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞][-∞;+∞]
26 FLOAT_T<FloatType> result;
27 _lhs.add(result, _rhs, CARL_RND::D );
31 FLOAT_T<FloatType> add_up(FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞][-∞;+∞]
33 FLOAT_T<FloatType> result;
34 _lhs.add(result, _rhs, CARL_RND::U );
38 FLOAT_T<FloatType> sub_down(FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞][-∞;+∞]
40 FLOAT_T<FloatType> result;
41 _lhs.sub(result, _rhs, CARL_RND::D );
45 FLOAT_T<FloatType> sub_up (FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞][-∞;+∞]
47 FLOAT_T<FloatType> result;
48 _lhs.sub(result, _rhs, CARL_RND::U );
52 FLOAT_T<FloatType> mul_down(FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞][-∞;+∞]
54 FLOAT_T<FloatType> result;
55 _lhs.mul(result, _rhs, CARL_RND::D );
59 FLOAT_T<FloatType> mul_up (FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞][-∞;+∞]
61 FLOAT_T<FloatType> result;
62 _lhs.mul(result, _rhs, CARL_RND::U );
66 FLOAT_T<FloatType> div_down(FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞]([-∞;+∞]-{0})
68 FLOAT_T<FloatType> result;
69 _lhs.div(result, _rhs, CARL_RND::D );
73 FLOAT_T<FloatType> div_up (FLOAT_T<FloatType> _lhs, FLOAT_T<FloatType> _rhs) // [-∞;+∞]([-∞;+∞]-{0})
75 FLOAT_T<FloatType> result;
76 _lhs.div(result, _rhs, CARL_RND::U );
80 FLOAT_T<FloatType> sqrt_down(FLOAT_T<FloatType> _val) // ]0;+∞]
83 return FLOAT_T<FloatType>(0);
85 FLOAT_T<FloatType> result;
86 _val.sqrt(result, CARL_RND::D );
89 FLOAT_T<FloatType> sqrt_up (FLOAT_T<FloatType> _val) // ]0;+∞]
92 return FLOAT_T<FloatType>(0);
94 FLOAT_T<FloatType> result;
95 _val.sqrt(result, CARL_RND::U );
98 FLOAT_T<FloatType> exp_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
100 FLOAT_T<FloatType> result;
101 _val.exp(result, CARL_RND::D );
104 FLOAT_T<FloatType> exp_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
106 FLOAT_T<FloatType> result;
107 _val.exp(result, CARL_RND::U );
110 FLOAT_T<FloatType> log_down(FLOAT_T<FloatType> _val) // ]0;+∞]
112 FLOAT_T<FloatType> result;
113 _val.log(result, CARL_RND::D );
116 FLOAT_T<FloatType> log_up (FLOAT_T<FloatType> _val) // ]0;+∞]
118 FLOAT_T<FloatType> result;
119 _val.log(result, CARL_RND::U );
122 FLOAT_T<FloatType> cos_down(FLOAT_T<FloatType> _val) // [0;2π]
124 FLOAT_T<FloatType> result;
125 _val.cos(result, CARL_RND::D );
128 FLOAT_T<FloatType> cos_up (FLOAT_T<FloatType> _val) // [0;2π]
130 FLOAT_T<FloatType> result;
131 _val.cos(result, CARL_RND::U );
134 FLOAT_T<FloatType> tan_down(FLOAT_T<FloatType> _val) // ]-π/2;π/2[
136 FLOAT_T<FloatType> result;
137 _val.tan(result, CARL_RND::D );
140 FLOAT_T<FloatType> tan_up (FLOAT_T<FloatType> _val) // ]-π/2;π/2[
142 FLOAT_T<FloatType> result;
143 _val.tan(result, CARL_RND::U );
146 FLOAT_T<FloatType> asin_down(FLOAT_T<FloatType> _val) // [-1;1]
148 FLOAT_T<FloatType> result;
149 _val.asin(result, CARL_RND::D );
152 FLOAT_T<FloatType> asin_up (FLOAT_T<FloatType> _val) // [-1;1]
154 FLOAT_T<FloatType> result;
155 _val.asin(result, CARL_RND::U );
158 FLOAT_T<FloatType> acos_down(FLOAT_T<FloatType> _val) // [-1;1]
160 FLOAT_T<FloatType> result;
161 _val.acos(result, CARL_RND::D );
164 FLOAT_T<FloatType> acos_up (FLOAT_T<FloatType> _val) // [-1;1]
166 FLOAT_T<FloatType> result;
167 _val.acos(result, CARL_RND::U );
170 FLOAT_T<FloatType> atan_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
172 FLOAT_T<FloatType> result;
173 _val.atan(result, CARL_RND::D );
176 FLOAT_T<FloatType> atan_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
178 FLOAT_T<FloatType> result;
179 _val.atan(result, CARL_RND::U );
182 FLOAT_T<FloatType> sinh_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
184 FLOAT_T<FloatType> result;
185 _val.sinh(result, CARL_RND::D );
188 FLOAT_T<FloatType> sinh_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
190 FLOAT_T<FloatType> result;
191 _val.sinh(result, CARL_RND::U );
194 FLOAT_T<FloatType> cosh_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
196 FLOAT_T<FloatType> result;
197 _val.cosh(result, CARL_RND::D );
200 FLOAT_T<FloatType> cosh_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
202 FLOAT_T<FloatType> result;
203 _val.cosh(result, CARL_RND::U );
206 FLOAT_T<FloatType> tanh_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
208 FLOAT_T<FloatType> result;
209 _val.tanh(result, CARL_RND::D );
212 FLOAT_T<FloatType> tanh_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
214 FLOAT_T<FloatType> result;
215 _val.tanh(result, CARL_RND::U );
218 FLOAT_T<FloatType> asinh_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
220 FLOAT_T<FloatType> result;
221 _val.asinh(result, CARL_RND::D );
224 FLOAT_T<FloatType> asinh_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
226 FLOAT_T<FloatType> result;
227 _val.asinh(result, CARL_RND::U );
230 FLOAT_T<FloatType> acosh_down(FLOAT_T<FloatType> _val) // [1;+∞]
232 FLOAT_T<FloatType> result;
233 _val.acosh(result, CARL_RND::D );
236 FLOAT_T<FloatType> acosh_up (FLOAT_T<FloatType> _val) // [1;+∞]
238 FLOAT_T<FloatType> result;
239 _val.acosh(result, CARL_RND::U );
242 FLOAT_T<FloatType> atanh_down(FLOAT_T<FloatType> _val) // [-1;1]
244 FLOAT_T<FloatType> result;
245 _val.atanh(result, CARL_RND::D );
248 FLOAT_T<FloatType> atanh_up (FLOAT_T<FloatType> _val) // [-1;1]
250 FLOAT_T<FloatType> result;
251 _val.atanh(result, CARL_RND::U );
254 FLOAT_T<FloatType> median(FLOAT_T<FloatType> _val1, FLOAT_T<FloatType> _val2) // [-∞;+∞][-∞;+∞]
256 // @todo: Median <. arithmetisches Mittel ???
257 FLOAT_T<FloatType> result;
258 result.add_assign(_val1);
259 result.add_assign(_val2);
260 result.div_assign(FLOAT_T<FloatType>(2));
263 FLOAT_T<FloatType> int_down(FLOAT_T<FloatType> _val) // [-∞;+∞]
265 FLOAT_T<FloatType> result;
266 _val.floor(result, CARL_RND::D );
269 FLOAT_T<FloatType> int_up (FLOAT_T<FloatType> _val) // [-∞;+∞]
271 FLOAT_T<FloatType> result;
272 _val.ceil(result, CARL_RND::U );
275 // conversion functions
277 FLOAT_T<FloatType> conv_down(U _val)
279 return FLOAT_T<FloatType>(_val, CARL_RND::D );
283 FLOAT_T<FloatType> conv_up(U _val)
285 return FLOAT_T<FloatType>(_val, CARL_RND::U );
287 // unprotected rounding class
288 // typedef ... unprotected_rounding;