carl  24.04
Computer ARithmetic Library
rounding.h
Go to the documentation of this file.
1 /*
2  * This file contains the rounding policies needed from the boost interval class
3  * for exact values using operator overloading.
4  *
5  * @file rounding.h
6  * @author Benedikt Seidl
7  * @author Stefan Schupp <stefan.schupp@cs.rwth-aachen.de>
8  *
9  * @since 2014-01-28
10  * @version 2014-01-30
11  */
12 
13 #pragma once
14 
15 namespace carl
16 {
17  template<typename Number>
18  struct rounding
19  {
20  // default constructor, destructor
21 // rounding();
22 // ~rounding();
23  // mathematical operations
24  Number add_down(Number _lhs, Number _rhs) // [-∞;+∞][-∞;+∞]
25  {
26  return _lhs + _rhs;
27  }
28 
29  Number add_up(Number _lhs, Number _rhs) // [-∞;+∞][-∞;+∞]
30  {
31  return _lhs + _rhs;
32  }
33 
34  Number sub_down(Number _lhs, Number _rhs) // [-∞;+∞][-∞;+∞]
35  {
36  return _lhs - _rhs;
37  }
38 
39  Number sub_up (Number _lhs, Number _rhs) // [-∞;+∞][-∞;+∞]
40  {
41  return _lhs - _rhs;
42  }
43 
44  Number mul_down(Number _lhs, Number _rhs) // [-∞;+∞][-∞;+∞]
45  {
46  return _lhs * _rhs;
47  }
48 
49  Number mul_up (Number _lhs, Number _rhs) // [-∞;+∞][-∞;+∞]
50  {
51  return _lhs * _rhs;
52  }
53 
54  Number div_down(Number _lhs, Number _rhs) // [-∞;+∞]([-∞;+∞]-{0})
55  {
56  return _lhs / _rhs;
57  }
58 
59  Number div_up (Number _lhs, Number _rhs) // [-∞;+∞]([-∞;+∞]-{0})
60  {
61  return _lhs / _rhs;
62  }
63 
64  Number sqrt_down(Number _val) // ]0;+∞]
65  {
66  if(_val <= 0)
67  return 0;
68  return sqrt(_val);
69  }
70  Number sqrt_up (Number _val) // ]0;+∞]
71  {
72  if(_val <= 0)
73  return 0;
74  return sqrt(_val);
75  }
76  Number exp_down(Number _val) // [-∞;+∞]
77  {
78  return exp(_val);
79  }
80  Number exp_up (Number _val) // [-∞;+∞]
81  {
82  return exp(_val);
83  }
84  Number log_down(Number _val) // ]0;+∞]
85  {
86  return log(_val);
87  }
88  Number log_up (Number _val) // ]0;+∞]
89  {
90  return log(_val);
91  }
92  Number sin_up(Number _val)
93  {
94  return sin(_val);
95  }
96  Number sin_down(Number _val)
97  {
98  return sin(_val);
99  }
100  Number cos_down(Number _val) // [0;2π]
101  {
102  return cos(_val);
103  }
104  Number cos_up (Number _val) // [0;2π]
105  {
106  return cos(_val);
107  }
108  Number tan_down(Number _val) // ]-π/2;π/2[
109  {
110  return tan(_val);
111  }
112  Number tan_up (Number _val) // ]-π/2;π/2[
113  {
114  return tan(_val);
115  }
116  Number asin_down(Number _val) // [-1;1]
117  {
118  return asin(_val);
119  }
120  Number asin_up (Number _val) // [-1;1]
121  {
122  return asin(_val);
123  }
124  Number acos_down(Number _val) // [-1;1]
125  {
126  return acos(_val);
127  }
128  Number acos_up (Number _val) // [-1;1]
129  {
130  return acos(_val);
131  }
132  Number atan_down(Number _val) // [-∞;+∞]
133  {
134  return atan(_val);
135  }
136  Number atan_up (Number _val) // [-∞;+∞]
137  {
138  return atan(_val);
139  }
140  Number sinh_down(Number _val) // [-∞;+∞]
141  {
142  return sinh(_val);
143  }
144  Number sinh_up (Number _val) // [-∞;+∞]
145  {
146  return sinh(_val);
147  }
148  Number cosh_down(Number _val) // [-∞;+∞]
149  {
150  return cosh(_val);
151  }
152  Number cosh_up (Number _val) // [-∞;+∞]
153  {
154  return cosh(_val);
155  }
156  Number tanh_down(Number _val) // [-∞;+∞]
157  {
158  return tanh(_val);
159  }
160  Number tanh_up (Number _val) // [-∞;+∞]
161  {
162  return tanh(_val);
163  }
164  Number asinh_down(Number _val) // [-∞;+∞]
165  {
166  return asinh(_val);
167  }
168  Number asinh_up (Number _val) // [-∞;+∞]
169  {
170  return asinh(_val);
171  }
172  Number acosh_down(Number _val) // [1;+∞]
173  {
174  return acosh(_val);
175  }
176  Number acosh_up (Number _val) // [1;+∞]
177  {
178  return acosh(_val);
179  }
180  Number atanh_down(Number _val) // [-1;1]
181  {
182  return atanh(_val);
183  }
184  Number atanh_up (Number _val) // [-1;1]
185  {
186  return atanh(_val);
187  }
188  Number median(Number _val1, Number _val2) // [-∞;+∞][-∞;+∞]
189  {
190  return (_val1 + _val2) / 2;
191  }
192  Number int_down(Number _val) // [-∞;+∞]
193  {
194  return floor(_val);
195  }
196  Number int_up (Number _val) // [-∞;+∞]
197  {
198  return ceil(_val);
199  }
200  // conversion functions
201  template<typename U>
202  Number conv_down(U _val)
203  {
204  return Number(_val);
205  }
206 
207  template<typename U>
208  Number conv_up(U _val)
209  {
210  return Number(_val);
211  }
212  // unprotected rounding class
213 // typedef ... unprotected_rounding;
214  };
215 }
216 
217 #include "rounding_float_t.tpp"
carl is the main namespace for the library.
Interval< Number > acos(const Interval< Number > &i)
Definition: Trigonometry.h:58
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Definition: Interval.h:1535
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
Definition: Interval.h:1523
Interval< Number > tan(const Interval< Number > &i)
Definition: Trigonometry.h:34
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
Interval< Number > atanh(const Interval< Number > &i)
Definition: Trigonometry.h:142
Interval< Number > atan(const Interval< Number > &i)
Definition: Trigonometry.h:70
Interval< Number > cos(const Interval< Number > &i)
Definition: Trigonometry.h:22
Interval< Number > sqrt(const Interval< Number > &i)
Definition: Power.h:51
Interval< Number > asin(const Interval< Number > &i)
Definition: Trigonometry.h:46
Interval< Number > log(const Interval< Number > &i)
Definition: Exponential.h:22
Interval< Number > sin(const Interval< Number > &i)
Definition: Trigonometry.h:10
Interval< Number > sinh(const Interval< Number > &i)
Definition: Trigonometry.h:82
Interval< Number > tanh(const Interval< Number > &i)
Definition: Trigonometry.h:106
Interval< Number > acosh(const Interval< Number > &i)
Definition: Trigonometry.h:130
Interval< Number > asinh(const Interval< Number > &i)
Definition: Trigonometry.h:118
Interval< Number > cosh(const Interval< Number > &i)
Definition: Trigonometry.h:94
Number sqrt_down(Number _val)
Definition: rounding.h:64
Number int_down(Number _val)
Definition: rounding.h:192
Number cosh_up(Number _val)
Definition: rounding.h:152
Number asin_up(Number _val)
Definition: rounding.h:120
Number conv_up(U _val)
Definition: rounding.h:208
Number tanh_up(Number _val)
Definition: rounding.h:160
Number sin_down(Number _val)
Definition: rounding.h:96
Number acosh_down(Number _val)
Definition: rounding.h:172
Number log_down(Number _val)
Definition: rounding.h:84
Number sinh_up(Number _val)
Definition: rounding.h:144
Number sinh_down(Number _val)
Definition: rounding.h:140
Number cosh_down(Number _val)
Definition: rounding.h:148
Number asinh_up(Number _val)
Definition: rounding.h:168
Number cos_up(Number _val)
Definition: rounding.h:104
Number sub_down(Number _lhs, Number _rhs)
Definition: rounding.h:34
Number add_down(Number _lhs, Number _rhs)
Definition: rounding.h:24
Number atanh_up(Number _val)
Definition: rounding.h:184
Number median(Number _val1, Number _val2)
Definition: rounding.h:188
Number cos_down(Number _val)
Definition: rounding.h:100
Number asinh_down(Number _val)
Definition: rounding.h:164
Number mul_down(Number _lhs, Number _rhs)
Definition: rounding.h:44
Number mul_up(Number _lhs, Number _rhs)
Definition: rounding.h:49
Number log_up(Number _val)
Definition: rounding.h:88
Number acos_up(Number _val)
Definition: rounding.h:128
Number sqrt_up(Number _val)
Definition: rounding.h:70
Number sin_up(Number _val)
Definition: rounding.h:92
Number exp_down(Number _val)
Definition: rounding.h:76
Number tan_down(Number _val)
Definition: rounding.h:108
Number atan_down(Number _val)
Definition: rounding.h:132
Number acosh_up(Number _val)
Definition: rounding.h:176
Number add_up(Number _lhs, Number _rhs)
Definition: rounding.h:29
Number exp_up(Number _val)
Definition: rounding.h:80
Number int_up(Number _val)
Definition: rounding.h:196
Number atan_up(Number _val)
Definition: rounding.h:136
Number tan_up(Number _val)
Definition: rounding.h:112
Number div_down(Number _lhs, Number _rhs)
Definition: rounding.h:54
Number acos_down(Number _val)
Definition: rounding.h:124
Number div_up(Number _lhs, Number _rhs)
Definition: rounding.h:59
Number conv_down(U _val)
Definition: rounding.h:202
Number tanh_down(Number _val)
Definition: rounding.h:156
Number asin_down(Number _val)
Definition: rounding.h:116
Number sub_up(Number _lhs, Number _rhs)
Definition: rounding.h:39
Number atanh_down(Number _val)
Definition: rounding.h:180