C-XSC - A C++ Class Library for Extended Scientific Computing 2.5.4
l_real.cpp
1/*
2** CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
3**
4** Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
5** Universitaet Karlsruhe, Germany
6** (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
7** Universitaet Wuppertal, Germany
8**
9** This library is free software; you can redistribute it and/or
10** modify it under the terms of the GNU Library General Public
11** License as published by the Free Software Foundation; either
12** version 2 of the License, or (at your option) any later version.
13**
14** This library is distributed in the hope that it will be useful,
15** but WITHOUT ANY WARRANTY; without even the implied warranty of
16** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17** Library General Public License for more details.
18**
19** You should have received a copy of the GNU Library General Public
20** License along with this library; if not, write to the Free
21** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24/* CVS $Id: l_real.cpp,v 1.34 2014/01/30 17:23:46 cxsc Exp $ */
25
26#include <memory.h>
27
28#include "l_real.hpp"
29#include "dot.hpp"
30#include "idot.hpp"
31#include "interval.hpp"
32#include "l_interval.hpp"
33
34namespace cxsc {
35
36#ifdef CXSC_USE_TLS_PREC
37
38#ifdef _WIN32
39__declspec(thread) int stagprec = 2;
40#else
41__thread int stagprec = 2;
42#endif
43
44#else
45
46int stagprec = 2;
47
48#endif
49
50
51interval::interval(const l_real & a) noexcept
52{
53 dotprecision dot(a);
54 rnd(dot,inf,sup);
55}
56
58{
59 dotprecision dot(a);
60 rnd(dot,inf,sup);
61 return *this;
62}
63
64idotprecision::idotprecision(const l_real & a) noexcept : inf(0),
65 sup(0)
66{
67 *this+=a;
68}
69
71 inf(0),
72 sup(0)
73{
74 inf+=a;
75 sup+=b;
76}
77
78
79
80void l_real::_clear(int p) noexcept
81{
82 // filling a l_real number from element p up to the end with zero.
83 for (int i=p; i<=prec; i++)
84 this->elem(i)=0.0;
85}
86
87
88void l_real::_akku_out(const dotprecision& d) noexcept
89{
90 // The dotprecision value is rounded to the activated l_real number
91 // in its own precision.
92 dotprecision dot(d);
93 _clear(1);
94 this->elem(1) = rnd(dot);
95 if (prec>1)
96 {
97 int i=2, weiter;
98 do {
99 dot -= this->elem(i-1);
100 this->elem(i) = rnd(dot);
101 i++;
102 weiter = this->elem(i-1) != 0; // Blomquist 02.10.02.
103 } while (weiter && (i <= prec));
104 }
105}
106
107void l_real::_akku_out_up(const dotprecision& d) noexcept
108{
109 // The dotprecision value is rounded up to the activated l_real
110 // number in its own precision.
111 // Blomquist, 20.11.2006;
112 bool weiter;
113 dotprecision dot(d);
114 _clear(1);
115 this->elem(1) = (prec==1)? rnd(dot,RND_UP) : rnd(dot);
116 if (prec>1)
117 {
118 int i=2;
119 do {
120 dot -= this->elem(i-1);
121 weiter = (sign(dot) != 0);
122 if (weiter)
123 this->elem(i) = (i==prec)?
124 rnd(dot,RND_UP) : rnd(dot);
125 i++;
126 } while (weiter && (i <= prec));
127 }
128}
129
130void l_real::_akku_out_down(const dotprecision& d) noexcept
131{
132 // The dotprecision value is rounded up to the activated l_real
133 // number in its own precision.
134 // Blomquist, 20.11.2006;
135 bool weiter;
136 dotprecision dot(d);
137 _clear(1);
138 this->elem(1) = (prec==1)? rnd(dot,RND_DOWN) : rnd(dot);
139 if (prec>1)
140 {
141 int i=2;
142 do {
143 dot -= this->elem(i-1);
144 weiter = (sign(dot) != 0);
145 if (weiter)
146 this->elem(i) = (i==prec)?
147 rnd(dot,RND_DOWN) : rnd(dot);
148 i++;
149 } while (weiter && (i <= prec));
150 }
151}
152
153void l_real::_akku_add(dotprecision& d) const noexcept
154{
155 // adding the activated l_real number to the accumulator d.
156 for (int i=1; i<=prec; i++)
157 {
158 if (this->elem(i) != 0) d += this->elem(i);
159 }
160}
161
162void l_real::_akku_sub(dotprecision& d) const noexcept
163{
164 // subtracting the activated l_real number from the accumulator d.
165 for (int i=1; i<=prec; i++)
166 {
167 if (this->elem(i) != 0) d -= this->elem(i);
168 }
169}
170
171//---------------------------------------------------------------------------
172// Constructors and destructors
173//
175{
176 data=new real[stagprec];
177 if(data)
178 prec=stagprec;
179 else
180 prec=0;
181}
182
183l_real::~l_real() noexcept
184{
185 delete [] data;
186}
187
188l_real::l_real(const l_real& lr) noexcept
189 : data(new real[lr.prec])
190{
191 if(data)
192 {
193 prec=lr.prec;
194 memcpy(data,lr.data,sizeof(real)*prec);
195 } else
196 prec=0;
197}
198
199l_real::l_real(const real & r) noexcept
200 : prec(1),
201 data(new real[1])
202{
203 data[0]=r;
204}
205
206l_real::l_real(const double & db) noexcept
207 : prec(1), data(new real[1])
208{
209 data[0] = db; // Blomquist 10.09.02. Deklaration in l_real.hpp
210}
211
212l_real::l_real(int i) noexcept
213 : prec(1),
214 data(new real[1])
215{
216 data[0]=i;
217}
218
219l_real::l_real(long i) noexcept
220 : prec(1),
221 data(new real[1])
222{
223 data[0]=i;
224}
225//---------------------------------------------------------------------------
226// Type transfers
227
228real::real(const l_real& lr) noexcept
229{
230 dotprecision dot(0.0);
231 lr._akku_add(dot);
232 w=rnd(dot).w;
233}
234
235dotprecision::dotprecision(const l_real& lr) noexcept : akku(new a_btyp[A_LENGTH])
236{
237 memset(akku,0,BUFFERSIZE);
238 lr._akku_add(*this);
239}
240
242{
243 memset(akku,0,BUFFERSIZE);
244 lr._akku_add(*this);
245 return *this;
246}
247
248l_real::l_real(const dotprecision & d) noexcept : prec(stagprec),
249 data(new real[prec])
250{
251 _akku_out(d);
252}
253
254//---------------------------------------------------------------------------
255// assignments
256//
257l_real& l_real::operator=(const real& r) noexcept
258{
259 // Siehe _l_real(real..)
260
261 if(prec!=1)
262 {
263 delete [] data;
264 data=new real[1];
265 if(data)
266 prec=1;
267 else
268 prec=0;
269 }
270 elem(1)=r;
271 return *this;
272}
273
274l_real& l_real::operator=(const l_real& lr) noexcept
275{
276 // Siehe c++-FAQ assignment-operators.html#[12.1]
277
278 // This code gracefully (albeit implicitly) handles self assignment
279 real* tmp = new real[lr.prec];
280 // It would be OK if an exception got thrown here
281
282 if((prec=lr.prec)>0)
283 memcpy(tmp,lr.data,sizeof(real)*prec);
284
285 delete [] data;
286 data = tmp;
287 return *this;
288}
289
290l_real& l_real::operator=(const dotprecision & d) noexcept
291{
292 if(prec!=stagprec)
293 {
294 delete [] data;
295 data=new real[prec=stagprec];
296 }
297 _akku_out(d);
298 return *this;
299}
300
301
302real& l_real::operator[](int i) const noexcept
303{
304 if (i<1 || i>prec)
305 {
306 // throw!
307 i=1;
308 }
309 return data[i-1];
310}
311
312int StagPrec(const l_real& lr) noexcept
313{
314 return lr.prec;
315}
316
317std::istream& operator>>(std::istream& s, l_real& lr) noexcept
318{
319 dotprecision dot;
320 s >> dot;
321 lr._akku_out(dot);
322 return s;
323}
324
325std::ostream& operator<<(std::ostream& s, const l_real& lr) noexcept
326{
327 dotprecision dot(0.0);
328 lr._akku_add(dot);
329 s << dot;
330 return s;
331}
332std::string& operator>>(std::string& s, l_real& lr) noexcept
333{
334 dotprecision dot;
335 s >> dot;
336 lr._akku_out(dot);
337 return s;
338}
339
340std::string& operator<<(std::string& s, const l_real& lr) noexcept
341{
342 dotprecision dot(0.0);
343 lr._akku_add(dot);
344 s << dot;
345 return s;
346}
347void operator>>(const std::string& s, l_real& lr) noexcept
348{
349 std::string r(s);
350 r>>lr;
351}
352void operator>>(const char *s, l_real& lr) noexcept
353{
354 std::string r(s);
355 r>>lr;
356}
357
358
359void accumulate(dotprecision& d, const real& r, const l_real& lr) noexcept
360{
361// accumulate(d, l_real(r), lr); Blomquist: Old version, not from me!
362 for (int i=1; i<=lr.prec; i++) // Blomquist: My new version, 24.09.02
363 accumulate(d, lr.elem(i), r);
364}
365
366void accumulate(dotprecision& d, const l_real& lr, const real& r) noexcept
367{
368// accumulate(d, lr, l_real(r)); Blomquist: Old version, not from me!
369 for (int i=1; i<=lr.prec; i++) // Blomquist: My new version, 24.09.02
370 accumulate(d, lr.elem(i), r);
371}
372
373void accumulate(dotprecision& d, const l_real& lr1, const l_real&lr2) noexcept
374{
375 int i, j;
376
377 for (i=1; i<=lr1.prec; i++)
378 for (j=1; j<=lr2.prec; j++)
379// if (abs(lr1.elem(i) * lr2.elem(j)) > MinReal) // alte Zeile von Toussaint
380 accumulate(d, lr1.elem(i), lr2.elem(j));
381}
382
383void accumulate(idotprecision & a, const real & b, const l_real & c) noexcept { accumulate(a,l_interval(b),l_interval(c)); }
384void accumulate(idotprecision & a, const l_real & b, const real & c) noexcept { accumulate(a,l_interval(b),l_interval(c)); }
385void accumulate(idotprecision & a, const l_real & b, const l_real & c) noexcept { accumulate(a,l_interval(b),l_interval(c)); }
386
388{ // Blomquist, 20.11.2006;
389 l_real lr;
390 lr._akku_out_up(a);
391 return lr;
392}
393
395{ // Blomquist, 20.11.2006;
396 l_real lr;
397 lr._akku_out_down(a);
398 return lr;
399}
400
401l_real operator-(const l_real& lr, const real& r) noexcept { return lr-_l_real(r); }
402l_real operator-(const real& r, const l_real& lr) noexcept { return _l_real(r)-lr; }
403l_real operator+(const l_real& lr, const real& r) noexcept { return lr+_l_real(r); }
404l_real operator+(const real& r, const l_real& lr) noexcept { return _l_real(r)+lr; }
405l_real operator*(const l_real& lr, const real& r) noexcept { return lr*_l_real(r); }
406l_real operator*(const real& r, const l_real& lr) noexcept { return _l_real(r)*lr; }
407l_real operator/(const l_real& lr, const real& r) noexcept { return lr/_l_real(r); }
408l_real operator/(const real& r, const l_real& lr) noexcept { return _l_real(r)/lr; }
409
410dotprecision operator-(const l_real& lr, const dotprecision& r) noexcept
411{
412 return _dotprecision(lr)-r;
413}
414dotprecision operator-(const dotprecision& r, const l_real& lr) noexcept
415{
416 return r-_dotprecision(lr);
417}
418dotprecision operator+(const l_real& lr, const dotprecision& r) noexcept
419{
420 return _dotprecision(lr)+r;
421}
422dotprecision operator+(const dotprecision& r, const l_real& lr) noexcept
423{
424 return r+_dotprecision(lr);
425}
426
427
428l_real& operator-=(l_real& lr, const real& r) noexcept
429{ lr = lr-_l_real(r); return lr; }
430
431l_real& operator+=(l_real& lr, const real& r) noexcept
432{ lr = lr+_l_real(r); return lr; }
433
434l_real& operator*=(l_real& lr, const real& r) noexcept
435{ lr = lr*_l_real(r); return lr; }
436
437l_real& operator/=(l_real& lr, const real& r) noexcept
438{ lr = lr/_l_real(r); return lr; }
439
440real& operator-=(real& r, const l_real& lr) noexcept { r = r-_real(lr); return r; }
441real& operator+=(real& r, const l_real& lr) noexcept { r = r+_real(lr); return r; }
442real& operator*=(real& r, const l_real& lr) noexcept { r = r*_real(lr); return r; }
443real& operator/=(real& r, const l_real& lr) noexcept { r = r/_real(lr); return r; }
444
445bool operator==(const l_real& lr, const real& r) noexcept { return lr==_l_real(r); }
446bool operator==(const real& r, const l_real& lr) noexcept { return _l_real(r)==lr; }
447bool operator!=(const l_real& lr, const real& r) noexcept { return lr!=_l_real(r); }
448bool operator!=(const real& r, const l_real& lr) noexcept { return _l_real(r)!=lr; }
449
450bool operator<=(const l_real& lr, const real& r) noexcept { return lr<=_l_real(r); }
451bool operator<=(const real& r, const l_real& lr) noexcept { return _l_real(r)<=lr; }
452bool operator>=(const l_real& lr, const real& r) noexcept { return lr>=_l_real(r); }
453bool operator>=(const real& r, const l_real& lr) noexcept { return _l_real(r)>=lr; }
454
455bool operator<(const l_real& lr, const real& r) noexcept { return lr<_l_real(r); }
456bool operator<(const real& r, const l_real& lr) noexcept { return _l_real(r)<lr; }
457bool operator>(const l_real& lr, const real& r) noexcept { return lr>_l_real(r); }
458bool operator>(const real& r, const l_real& lr) noexcept { return _l_real(r)>lr; }
459
460bool operator==(const l_real& lr, const dotprecision& d) noexcept { return _dotprecision(lr)==d; }
461bool operator==(const dotprecision& d, const l_real& lr) noexcept { return d==_dotprecision(lr); }
462bool operator!=(const l_real& lr, const dotprecision& d) noexcept { return _dotprecision(lr)!=d; }
463bool operator!=(const dotprecision& d, const l_real& lr) noexcept { return d!=_dotprecision(lr); }
464
465bool operator<=(const l_real& lr, const dotprecision& d) noexcept { return _dotprecision(lr)<=d; }
466bool operator<=(const dotprecision& d, const l_real& lr) noexcept { return d<=_dotprecision(lr); }
467bool operator>=(const l_real& lr, const dotprecision& d) noexcept { return _dotprecision(lr)>=d; }
468bool operator>=(const dotprecision& d, const l_real& lr) noexcept { return d>=_dotprecision(lr); }
469
470bool operator<(const l_real& lr, const dotprecision& d) noexcept { return _dotprecision(lr)<d; }
471bool operator<(const dotprecision& d, const l_real& lr) noexcept { return d<_dotprecision(lr); }
472bool operator>(const l_real& lr, const dotprecision& d) noexcept { return _dotprecision(lr)>d; }
473bool operator>(const dotprecision& d, const l_real& lr) noexcept { return d>_dotprecision(lr); }
474
475l_real operator-(const l_real& lr1) noexcept
476{
477 l_real lr2(lr1);
478 for (int i=1; i<=lr1.prec; i++)
479 lr2.elem(i) = -(lr1.elem(i));
480 return lr2;
481}
482l_real operator+(const l_real& lr1) noexcept
483{
484 return lr1;
485}
486
487l_real operator-(const l_real& lr1, const l_real& lr2) noexcept
488{
489 l_real lr3;
490 dotprecision dot(0.0);
491 lr1._akku_add(dot);
492 lr2._akku_sub(dot);
493 lr3._akku_out(dot);
494 return lr3;
495}
496
497l_real operator+(const l_real& lr1, const l_real& lr2) noexcept
498{
499 l_real lr3;
500 dotprecision dot(0.0);
501 lr1._akku_add(dot);
502 lr2._akku_add(dot);
503 lr3._akku_out(dot);
504
505 return lr3;
506}
507
508l_real operator*(const l_real& lr1, const l_real& lr2) noexcept
509{
510 l_real lr3;
511 dotprecision dot(0.0);
512 accumulate(dot, lr1, lr2);
513 lr3._akku_out(dot);
514 return lr3;
515}
516
517l_real operator/(const l_real& lr1, const l_real& lr2)
518{ // Blomquist, 09.12.02; noexcept --->
519 real a, b;
520 l_real lr3;
521 lr3._clear(1);
522 dotprecision dot1(0.0);
523 dotprecision dot2(0.0);
524 lr1._akku_add(dot1);
525 lr2._akku_add(dot2);
526 a = rnd(dot1, RND_DOWN);
527 b = rnd(dot2, RND_UP);
528 if (!b)
529 { // Blomquist: cxscthrow(DIV_BY_ ... )
530 cxscthrow(DIV_BY_ZERO("l_real operator/(const l_real&, const l_real&)"));
531 } else
532 {
533 lr3.elem(1) = a/b;
534 for (int i=2; i<=stagprec; i++)
535 {
536 if (!a)
537 break;
538 for (int j=1; j<=lr2.prec; j++)
539 if (!!lr3.elem(i-1) && !!lr2.elem(j) )
540 accumulate(dot1, lr3.elem(i-1), -lr2.elem(j));
541 a = rnd(dot1, RND_DOWN);
542 lr3.elem(i) = a/b;
543 }
544 } // no division by zero
545 return lr3;
546}
547
548
549l_real & operator-=(l_real& lr1, const l_real& lr2) noexcept { return lr1 = lr1-lr2; }
550l_real & operator+=(l_real& lr1, const l_real& lr2) noexcept { return lr1 = lr1+lr2; }
551l_real & operator*=(l_real& lr1, const l_real& lr2) noexcept { return lr1 = lr1*lr2; }
552l_real & operator/=(l_real& lr1, const l_real& lr2) noexcept { return lr1 = lr1/lr2; }
553
554bool operator==(const l_real& lr1, const l_real& lr2) noexcept
555{
556 dotprecision dot1(0.0);
557 dotprecision dot2(0.0);
558 lr1._akku_add(dot1);
559 lr2._akku_add(dot2);
560 return (dot1==dot2);
561}
562
563bool operator<=(const l_real& lr1, const l_real& lr2) noexcept
564{
565 dotprecision dot1(0.0);
566 dotprecision dot2(0.0);
567 lr1._akku_add(dot1);
568 lr2._akku_add(dot2);
569 return (dot1<=dot2);
570}
571
572bool operator!(const l_real& lr) noexcept
573{
574 dotprecision dot(0.0);
575 lr._akku_add(dot);
576 return (!dot);
577}
578
579bool operator!=(const l_real& lr1, const l_real& lr2) noexcept { return !(lr1==lr2); }
580bool operator< (const l_real& lr1, const l_real& lr2) noexcept { return !(lr2<=lr1); }
581bool operator> (const l_real& lr1, const l_real& lr2) noexcept { return !(lr1<=lr2); }
582bool operator>=(const l_real& lr1, const l_real& lr2) noexcept { return (lr2<=lr1); }
583
584// ID-LR
585
586 idotprecision operator +(const idotprecision &a,const l_real &b) noexcept
587{
588 return idotprecision(a.inf+b,a.sup+b);
589}
590
591 idotprecision operator +(const l_real &b,const idotprecision &a) noexcept
592{
593 return idotprecision(a.inf+b,a.sup+b);
594}
595
596 idotprecision operator -(const idotprecision &a,const l_real &b) noexcept
597{
598 return idotprecision(a.inf-b,a.sup-b);
599}
600
601 idotprecision operator -(const l_real &a,const idotprecision &b) noexcept
602{
603 return idotprecision(a-b.sup,a-b.inf);
604}
605
606idotprecision operator |(const l_real &a,const idotprecision &b) noexcept
607{
608 return idotprecision((a<b.inf)?_dotprecision(a):b.inf,(a>b.sup)?_dotprecision(a):b.sup);
609}
610
611 idotprecision operator |(const idotprecision &a,const l_real &b) noexcept
612{
613 return idotprecision((a.inf<b)?a.inf:_dotprecision(b),(a.sup>b)?a.sup:_dotprecision(b));
614}
615
616 idotprecision operator &(const l_real &a,const idotprecision &b)
617{
618 return idotprecision((a>b.inf)?_dotprecision(a):b.inf,(a<b.sup)?_dotprecision(a):b.sup);
619}
620
621 idotprecision operator &(const idotprecision &a,const l_real &b)
622{
623 return idotprecision((a.inf>b)?a.inf:_dotprecision(b),(a.sup<b)?a.sup:_dotprecision(b));
624}
625
626// LR-ID
627idotprecision & operator +=(idotprecision &a,const l_real &b) noexcept { return a+=dotprecision(b); }
628idotprecision & operator -=(idotprecision &a,const l_real &b) noexcept { return a-=dotprecision(b); }
629idotprecision & operator |=(idotprecision &a,const l_real &b) noexcept { return a|=dotprecision(b); }
630idotprecision & operator &=(idotprecision &a,const l_real &b) { return a&=dotprecision(b); }
631
632
633bool operator ==(const interval &i,const l_real &r) noexcept { return Inf(i)==r && Sup(i)==r; }
634bool operator !=(const interval &i,const l_real &r) noexcept { return Inf(i)!=r || Sup(i)!=r; }
635bool operator <(const interval &i,const l_real &r) noexcept { return false; }
636bool operator >(const interval &i,const l_real &r) noexcept { return Inf(i)<r && Sup(i)>r; }
637bool operator <=(const interval &i,const l_real &r) noexcept { return Inf(i)==r && Sup(i)==r; }
638bool operator >=(const interval &i,const l_real &r) noexcept { return Inf(i)<=r && Sup(i)>=r; }
639
640bool operator ==(const l_real &r,const interval &i) noexcept { return Inf(i)==r && Sup(i)==r; }
641bool operator !=(const l_real &r,const interval &i) noexcept { return Inf(i)!=r || Sup(i)!=r; }
642bool operator <(const l_real &r,const interval &i) noexcept { return Inf(i)<r && Sup(i)>r; }
643bool operator >(const l_real &r,const interval &i) noexcept { return false; }
644bool operator <=(const l_real &r,const interval &i) noexcept { return Inf(i)<=r && Sup(i)>=r; }
645bool operator >=(const l_real &r,const interval &i) noexcept { return Inf(i)==r && Sup(i)==r; }
646
647bool operator ==(const idotprecision &i,const l_real &r) noexcept { return Inf(i)==r && Sup(i)==r; }
648bool operator !=(const idotprecision &i,const l_real &r) noexcept { return Inf(i)!=r || Sup(i)!=r; }
649bool operator <(const idotprecision &i,const l_real &r) noexcept { return false; }
650bool operator >(const idotprecision &i,const l_real &r) noexcept { return Inf(i)<r && Sup(i)>r; }
651bool operator <=(const idotprecision &i,const l_real &r) noexcept { return Inf(i)==r && Sup(i)==r; }
652bool operator >=(const idotprecision &i,const l_real &r) noexcept { return Inf(i)<=r && Sup(i)>=r; }
653
654bool operator ==(const l_real &r,const idotprecision &i) noexcept { return Inf(i)==r && Sup(i)==r; }
655bool operator !=(const l_real &r,const idotprecision &i) noexcept { return Inf(i)!=r || Sup(i)!=r; }
656bool operator <(const l_real &r,const idotprecision &i) noexcept { return Inf(i)<r && Sup(i)>r; }
657bool operator >(const l_real &r,const idotprecision &i) noexcept { return false; }
658bool operator <=(const l_real &r,const idotprecision &i) noexcept { return Inf(i)<=r && Sup(i)>=r; }
659bool operator >=(const l_real &r,const idotprecision &i) noexcept { return Inf(i)==r && Sup(i)==r; }
660
661real & real::operator = (const l_real& a) noexcept
662{ // Blomquist, 12.11.2008;
663 real x(a);
664 return *this = x;
665}
666
667//---------------------------------------------------------------------------
668// Other functions:
669//
670l_real abs(const l_real& lr1) noexcept
671{
672 l_real lr2;
673 dotprecision dot(0.0);
674 lr1._akku_add(dot);
675
676 if (dot < 0.0)
677 dot = -dot;
678
679 lr2._akku_out(dot);
680
681 return lr2;
682}
683
684int sign(const l_real& lr) noexcept
685{
686 dotprecision dot(0.0);
687 lr._akku_add(dot);
688 return sign(dot);
689}
690
691l_real adjust(const l_real & x) noexcept
692{
693 l_real y;
694
695 if (x.prec == stagprec)
696 y = x;
697 else if (x.prec > stagprec)
698 {
699 dotprecision dot(0.0);
700 x._akku_add(dot);
701 y._akku_out(dot);
702 } else
703 {
704 int i;
705 for (i = 0; i <= stagprec-x.prec-1; i++)
706 y.data[i] = 0;
707 for (i = stagprec-x.prec; i <= stagprec-1; i++)
708 y.data[i] = x.data[i-(stagprec-x.prec)];
709 }
710
711 return y;
712}
713
725int expo_sm(const l_real& x)
726// Calculating expo(x[k]) of the smallest |x[k]|<>0.
727{
728 int k(x.prec);
729 l_real y(x);
730
731 while (y.elem(k)==0 && k>1) k--;
732 return expo(y.elem(k));
733}
734
744int expo_gr(const l_real& x)
745// Calculating expo(x[k]) of the greatest |x[k]|.
746{
747 int k(1),p(x.prec);
748 l_real y(x);
749
750 while (y.elem(k)==0 && k<p) k++;
751 return expo(y.elem(k));
752}
753
754
755} // namespace cxsc
756
The Data Type dotprecision.
Definition dot.hpp:112
dotprecision(void) noexcept
Constructor of class dotprecision.
Definition dot.cpp:62
dotprecision & operator=(const dotprecision &) noexcept
Implementation of standard assigning operator.
Definition dot.cpp:84
The Data Type idotprecision.
Definition idot.hpp:48
idotprecision()
Constructor of class idotprecision.
Definition idot.hpp:57
The Scalar Type interval.
Definition interval.hpp:55
interval & operator=(const real &a)
Implementation of standard assigning operator.
Definition interval.inl:52
interval()
Constructor of class interval.
Definition interval.hpp:64
The Multiple-Precision Data Type l_interval.
The Multiple-Precision Data Type l_real.
Definition l_real.hpp:78
real & operator[](int) const noexcept
Access to the single components used to store the long data type value.
Definition l_real.cpp:302
l_real(void) noexcept
Constructor of class l_real.
Definition l_real.cpp:174
The Scalar Type real.
Definition real.hpp:114
real(void) noexcept
Constructor of class real.
Definition real.hpp:122
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition cdot.cpp:29
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition cdot.inl:251
l_real rnd_up(const dotprecision &a)
Rounds the argument up to the next l_real value.
Definition l_real.cpp:387
civector operator/(const cimatrix_subv &rv, const cinterval &s) noexcept
Implementation of division operation.
Definition cimatrix.inl:730
int expo_gr(const l_interval &x)
l_real rnd_down(const dotprecision &a)
Rounds the argument down to the next l_real value.
Definition l_real.cpp:394
cimatrix & operator*=(cimatrix &m, const cinterval &c) noexcept
Implementation of multiplication and allocation operation.
ivector abs(const cimatrix_subv &mv) noexcept
Returns the absolute value of the matrix.
Definition cimatrix.inl:737
civector operator*(const cimatrix_subv &rv, const cinterval &s) noexcept
Implementation of multiplication operation.
Definition cimatrix.inl:731
int expo_sm(const l_interval &x)
dotprecision _dotprecision(const real &d) noexcept
Definition dot.hpp:304
cimatrix & operator/=(cimatrix &m, const cinterval &c) noexcept
Implementation of division and allocation operation.