ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/addin/outil/src/ot_doubleprecision.cpp
Revision: 1156
Committed: Thu Jun 13 22:02:48 2024 UTC (14 months, 2 weeks ago) by francois
File size: 7206 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

# Content
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// ot_doubleprecision.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:53:59 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 #pragma hdrstop
23
24 #include <math.h>
25 #include <iomanip>
26 #include "ot_doubleprecision.h"
27
28
29
30 double double2::EPS_RELATIF=1e-8;
31
32 double2::double2():x(0.),dx(EPS_RELATIF)
33 {
34 }
35 double2::double2(double val):x(val),dx(EPS_RELATIF*fabs(val))
36 {
37 if (dx==0.0) dx=EPS_RELATIF;
38 }
39 double2::double2(double val,double prec):x(val),dx(prec)
40 {
41 }
42 double2::double2(double2 &mdd):x(mdd.x),dx(mdd.dx)
43 {
44 }
45 double2::double2(const double2& mdd):x(mdd.x),dx(mdd.dx)
46 {
47 }
48 double2::~double2()
49 {
50 }
51
52
53 double2& double2::operator=(const double2& val)
54 {
55 x=val.x;
56 dx=val.dx;
57 return *this;
58 }
59
60 int double2::operator==(double2& val)
61 {
62 int rep=0;
63 if ((val.x>=x-dx/2.) && (val.x<=x+dx/2.) )
64 if ((x>=val.x-val.dx/2.) && (x<=val.x+val.dx/2.) )
65 rep=1;
66 else rep=0;
67 return rep;
68 }
69 int double2::operator!=(double2& val)
70 {
71 return !(*this==val);
72 }
73
74 int double2::operator<(double2& val)
75 {
76 if (x+dx/2.<val.x-val.dx/2.)
77 return 1;
78 else
79 return 0;
80 }
81
82 int double2::operator<=(double2& val)
83 {
84 /* if ((*this<val) || (*this==val)) return 1;
85 return 0;*/
86 if (x+dx/2.<val.x+val.dx/2.)
87 return 1;
88 else
89 return 0;
90 }
91
92 int double2::operator>(double2& val)
93 {
94 double a=x-dx/2.;
95 double b=val.x+val.dx/2.;
96 if (a>b)
97 return 1;
98 else
99 return 0;
100 }
101
102 int double2::operator>=(double2& val)
103 {
104 /*if ((*this>val) || (*this==val)) return 1;
105 return 0;*/
106 if (x-dx/2.>val.x-val.dx/2.)
107 return 1;
108 else return 0;
109
110 }
111
112 double2 operator+(double2& val1,double2& val2)
113 {
114 double2 xx;
115 xx.x=val1.x+val2.x;
116 xx.dx=val1.dx+val2.dx;
117 return xx;
118 }
119
120 double2 operator+(const double2& val1,const double2& val2)
121 {
122 double2 xx;
123 xx.x=val1.x+val2.x;
124 xx.dx=val1.dx+val2.dx;
125 return xx;
126 }
127
128
129 double2 operator-(double2& val1,double2& val2)
130 {
131 double2 xx;
132 xx.x=val1.x-val2.x;
133 xx.dx=val1.dx+val2.dx;
134 return xx;
135 }
136
137 double2 operator-(const double2& val1,const double2& val2)
138 {
139 double2 xx;
140 xx.x=val1.x-val2.x;
141 xx.dx=val1.dx+val2.dx;
142 return xx;
143 }
144
145
146 double2 operator*(double2& val1,double2& val2)
147 {
148 double2 xx;
149 xx.x=val1.x*val2.x;
150 xx.dx=fabs(val1.x)*val2.dx+fabs(val2.x)*val1.dx;
151 return xx;
152 }
153
154 double2 operator*(const double2& val1,const double2& val2)
155 {
156 double2 xx;
157 xx.x=val1.x*val2.x;
158 xx.dx=fabs(val1.x)*val2.dx+fabs(val2.x)*val1.dx;
159 return xx;
160 }
161
162
163 double2 operator/(double2& val1,double2& val2)
164 {
165 double2 xx;
166 xx.x=val1.x/val2.x;
167 xx.dx=fabs(1./val2.x)*val1.dx+fabs(val1.x/val2.x/val2.x)*val2.dx;
168 return xx;
169 }
170
171 double2 operator/(const double2& val1,const double2& val2)
172 {
173 double2 xx;
174 xx.x=val1.x/val2.x;
175 xx.dx=fabs(1./val2.x)*val1.dx+fabs(val1.x/val2.x/val2.x)*val2.dx;
176 return xx;
177 }
178
179
180 double2 operator^(double2& val1,double n)
181 {
182 double2 xx;
183 xx.x=pow(val1.x,n);
184 if (val1.x)
185 xx.dx=n*pow(val1.x,n-1)*val1.dx;
186 else xx.dx=val1.dx;
187 return xx;
188 }
189
190 double2 operator^(const double2& val1,const double n)
191 {
192 double2 xx;
193 xx.x=pow(val1.x,n);
194 if (val1.x)
195 xx.dx=n*pow(val1.x,n-1)*val1.dx;
196 else xx.dx=val1.dx;
197 return xx;
198 }
199
200 std::ostream& operator <<(std::ostream& os,const double2& m)
201 {
202 os<<m.x<<std::setw(15);//<<m.dx;
203 return os;
204 }
205
206 double2 cos(double2& val)
207 {
208 double2 xx;
209 xx.x=cos(val.x);
210 xx.dx=fabs(sin(val.x))*val.dx;
211 return xx;
212 }
213
214
215 double2 cos(const double2& val)
216 {
217 double2 xx;
218 xx.x=cos(val.x);
219 xx.dx=fabs(sin(val.x))*val.dx;
220 return xx;
221 }
222
223
224 double2 acos(double2& val)
225 {
226 double2 xx;
227 double2 zero=0.;
228 double2 un=1. ;
229 xx.x=acos(val.x);
230
231 zero.dx=val.dx;
232 xx.dx=fabs(-1./sqrt(1-val.x*val.x))*val.dx;
233 return xx;
234 }
235
236 double2 acos(const double2& val)
237 {
238 double2 xx;
239 double2 zero(0);
240 double2 un(1);
241
242 xx.x=acos(val.x);
243
244 zero.dx=val.dx;
245 xx.dx=fabs(-1./sqrt(1-val.x*val.x))*val.dx;
246 return xx;
247 }
248
249
250 double2 sin(double2& val)
251 {
252 double2 xx;
253 xx.x=sin(val.x);
254 xx.dx=fabs(cos(val.x))*val.dx;
255 return xx;
256 }
257
258
259 double2 double2::get_fabs()
260 {
261 double2 zro=0.0;
262 double2 tmp=*this;
263 if (tmp.x<0) return zro-tmp;
264 else return tmp;
265 }
266
267 double2 f2abs(double2& val)
268 {
269 double2 xx;
270 xx.x=fabs(val.x);
271 xx.dx=val.dx;
272 return xx;
273 }
274
275 double2 f2abs(const double2& val)
276 {
277 double2 xx;
278 xx.x=fabs(val.x);
279 xx.dx=val.dx;
280 return xx;
281 }
282
283 double2 sin(const double2& val)
284 {
285 double2 xx;
286 xx.x=sin(val.x);
287 xx.dx=fabs(cos(val.x))*val.dx;
288 return xx;
289 }
290
291
292
293
294 double2 asin(double2& val)
295 {
296 double2 xx;
297 xx.x=asin(val.x);
298 xx.dx=fabs(1./sqrt(1-val.x*val.x))*val.dx;
299 return xx;
300 }
301
302
303 double2 asin(const double2& val)
304 {
305 double2 xx;
306 xx.x=asin(val.x);
307 xx.dx=fabs(1./sqrt(1-val.x*val.x))*val.dx;
308 return xx;
309 }
310
311 double2 tan(double2& val)
312 {
313 double2 xx;
314 xx.x=tan(val.x);
315 xx.dx=fabs(1+tan(val.x)*tan(val.x))*val.dx;
316 return xx;
317 }
318
319 double2 tan(const double2& val)
320 {
321 double2 xx;
322 xx.x=tan(val.x);
323 xx.dx=fabs(1+tan(val.x)*tan(val.x))*val.dx;
324 return xx;
325 }
326
327 double2 atan(double2& val)
328 {
329 double2 xx;
330 xx.x=atan(val.x);
331 xx.dx=fabs(1./(1+val.x*val.x))*val.dx;
332 return xx;
333 }
334
335
336 double2 atan(const double2& val)
337 {
338 double2 xx;
339 xx.x=atan(val.x);
340 xx.dx=fabs(1./(1+val.x*val.x))*val.dx;
341 return xx;
342 }
343
344
345 double2 sqrt(double2&val)
346 {
347 double2 ZERO(0.);
348 if (val==ZERO) return ZERO;
349 double2 xx;
350 xx.x=sqrt(val.x);
351 xx.dx=fabs(1./(2*sqrt(val.x)))*val.dx;
352 return xx;
353
354 }
355 double2 sqrt(const double2&val)
356 {
357 double2 ZERO(0.);
358 if (val==ZERO) return ZERO;
359 double2 xx;
360 xx.x=sqrt(val.x);
361 xx.dx=fabs(1./(2*sqrt(val.x)))*val.dx;
362 return xx;
363
364 }
365
366
367 double double2::get_x()
368 {
369 return x;
370 }
371
372
373 double double2::get_dx()
374 {
375 return dx;
376 }
377
378
379
380 void double2:: set_dx(double ddx)
381 {
382 dx=ddx;
383 }
384 void double2::set_x(double xx)
385 {
386 x=xx;
387 }
388
389
390 int operator==(const double2& val1,const double2& val2)
391 {
392 int rep=0;
393 if ((val1.x>=val2.x-val2.dx/2.) && (val1.x<=val2.x+val2.dx/2.) )
394 if ((val2.x>=val1.x-val1.dx/2.) && (val2.x<=val1.x+val1.dx/2.) )
395 rep=1;
396 else rep=0;
397 return rep;
398 }
399
400
401