Borderbasix

Scl_mpfr.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 template<class T> inline
3 Scl<T>& rem (const Scl<T>& dividend, const Scl<T>& divisor) NRVAL(r(dividend))
4 {
5  NRCODE(r.rem(divisor);)
6  NONRCODE(Scl<T> r(dividend); r.rem(divisor); return r;)
7 }
8 * (C) B. Mourrain, GALAAD, INRIA *
9 **********************************************************************
10 History:
11 $Id: Scl_mpf.hpp,v 1.1.1.1 2006/10/06 08:01:40 trebuche Exp $
12 **********************************************************************/
13 #ifndef _SCL_MPFR_H_
14 #define _SCL_MPFR_H_
15 //----------------------------------------------------------------------
16 //#include <cmath>
17 #include <iostream>
18 #include <iomanip>
19 #include <string>
20 #include <borderbasix/mdebug.hpp>
21 #include "Scl.hpp"
22 #include <mpfr.h>
23 
24 //----------------------------------------------------------------------
25 typedef mpfr_t MPFR;
26 #define _MPFR_
27 unsigned long MPFR_PRECISION;
28 //----------------------------------------------------------------------
29 
30 //----------------------------------------------------------------------
31 template<> inline Scl<MPFR>::~Scl (){
32  mpfr_clear(rep());
33 }
34 //----------------------------------------------------------------------
35 template<> inline
36 void Scl<MPFR>::init ( ) {
37  mpfr_init(rep());
38 }
39 //----------------------------------------------------------------------
40 template<> inline
42  // cout<<"default construct "<<endl;
43  mpfr_init(rep());
44 }
45 //----------------------------------------------------------------------
46 template<> inline
47 Scl<MPFR>::operator int () const
48 {
49  return (int) mpfr_get_d(rep(),MPFR_RNDN);
50 }
51 //----------------------------------------------------------------------
52 template<> inline
54 {
55  return mpfr_get_d(ref.rep(),MPFR_RNDN);
56 }
57 //----------------------------------------------------------------------
58 template<> inline
60 {
61  //cout<<"const SCl "<<endl;
62  mpfr_init_set(rep(),rhs.rep(),MPFR_RNDN);
63 }
64 
65 //----------------------------------------------------------------------
66 template<> inline
67 Scl<MPFR>::Scl (signed long int sl) {
68  mpfr_init_set_si(rep(),sl,MPFR_RNDN);
69 }
70 //----------------------------------------------------------------------
71 template<> inline
72 Scl<MPFR>::Scl (unsigned long int ul) {
73  mpfr_init_set_ui(rep(),ul,MPFR_RNDN);
74 }
75 //----------------------------------------------------------------------
76 template<> inline
77 Scl<MPFR>::Scl (int si) {
78  // cout<<"init set si "<<endl;
79  mpfr_init_set_si(rep(), si,MPFR_RNDN);
80 }
81 //----------------------------------------------------------------------
82 template<> inline
83 Scl<MPFR>::Scl (const char *str, unsigned int base)
84 {
85  mpfr_set_default_prec(64);
86  if (mpfr_init_set_str(rep(), str, base, MPFR_RNDN))
87  std::cerr << "Scl<MPFR>: The string " << str
88  << " is not a valid number in base " << base << std::endl;
89 }
90 //----------------------------------------------------------------------
91 template<> inline
92 Scl<MPFR>::Scl (double d)
93 {
94  //cout<<"je passe dans construct double "<<endl;
95  mpfr_init_set_d(rep(),d,MPFR_RNDN);
96 }
97 //----------------------------------------------------------------------
98 template<> inline
100 {
101  //COUNT<MPFR>('=');
102  if (this != &rhs) {
103  // mpfr_init(rep());
104  mpfr_set(rep(), rhs.rep(),MPFR_RNDN);
105  }
106  return *this;
107 }
108 
109 // == ------------------------------------------------------------------
110 template<> inline
111 bool Scl<MPFR>::operator == (const Scl<MPFR>& rhs) const
112 {
113  return mpfr_cmp(rep(), rhs.rep()) == 0;
114 }
115 
116 template<> inline
117 bool Scl<MPFR>::operator == (long sl) const {
118  return mpfr_cmp_si(rep(), sl) == 0;
119 }
120 
121 template<> inline
122 bool Scl<MPFR>::operator == (int si) const {
123  return mpfr_cmp_si(rep(), (long) si) == 0;
124 }
125 
126 template<> inline
127 bool Scl<MPFR>::operator == (unsigned long ul) const
128 {
129  return mpfr_cmp_ui(rep(), ul) == 0;
130 }
131 template<> inline
132 bool Scl<MPFR>::operator == (double ul) const
133 {
134  return mpfr_cmp_d(rep(), ul) == 0;
135 }
136 
137 // != ------------------------------------------------------------------
138 template<> inline
139 bool Scl<MPFR>::operator != (const Scl<MPFR>& rhs) const
140 {
141  return mpfr_cmp(rep(), rhs.rep()) != 0;
142 }
143 template<> inline
144 bool Scl<MPFR>::operator != (double sl) const {
145  return mpfr_cmp_d(rep(), sl) != 0;
146 }
147 
148 
149 template<> inline
150 bool Scl<MPFR>::operator != (long sl) const {
151  return mpfr_cmp_si(rep(), sl) != 0;
152 }
153 
154 template<> inline
155 bool Scl<MPFR>::operator != (int si) const {
156  return mpfr_cmp_si(rep(), (long) si) != 0;
157 }
158 
159 template<> inline
160 bool Scl<MPFR>::operator != (unsigned long ul) const
161 {
162  return mpfr_cmp_ui(rep(), ul) != 0;
163 }
164 // > -------------------------------------------------------------------
165 template<> inline
166 bool Scl<MPFR>::operator > (const Scl<MPFR>& rhs) const
167 {
168  //)<<"RR > RR";
169  return mpfr_cmp(rep(), rhs.rep()) > 0;
170 }
171 
172 template<> inline
173 bool Scl<MPFR>::operator > (double sl) const {
174  return mpfr_cmp_d(rep(), sl) > 0;
175 }
176 
177 template<> inline
178 bool Scl<MPFR>::operator > (long sl) const {
179  return mpfr_cmp_si(rep(), sl) > 0;
180 }
181 
182 template<> inline
183 bool Scl<MPFR>::operator > (int si) const {
184  return mpfr_cmp_si(rep(), (long) si) > 0;
185 }
186 
187 template<> inline
188 bool Scl<MPFR>::operator > (unsigned long ul) const
189 {
190  return mpfr_cmp_ui(rep(), ul) > 0;
191 }
192 
193 
194 // <= --------------------------------------------------------------------
195 template<> inline
196 bool Scl<MPFR>::operator >= (const Scl<MPFR>& rhs) const
197 {
198  return mpfr_cmp(rep(), rhs.rep()) >= 0;
199 }
200 
201 template<> inline
202 bool Scl<MPFR>::operator >= (long sl) const {
203  return mpfr_cmp_si(rep(), sl) >= 0;
204 }
205 template<> inline
206 bool Scl<MPFR>::operator >= (double sl) const {
207  return mpfr_cmp_d(rep(), sl) >= 0;
208 }
209 
210 template<> inline
211 bool Scl<MPFR>::operator >= (int si) const
212 {
213  return mpfr_cmp_si(rep(), (long) si) >= 0;
214 }
215 
216 template<> inline
217 bool Scl<MPFR>::operator >= (unsigned long ul) const
218 {
219  return mpfr_cmp_ui(rep(), ul) >= 0;
220 }
221 
222 // < -------------------------------------------------------------------
223 template<> inline
224 bool Scl<MPFR>::operator < (const Scl<MPFR>& rhs) const
225 {
226  return mpfr_cmp(rep(), rhs.rep()) < 0;
227 }
228 
229 template<> inline
230 bool Scl<MPFR>::operator < (long sl) const {
231  return mpfr_cmp_si(rep(), sl) < 0;
232 }
233 template<> inline
234 bool Scl<MPFR>::operator < (double sl) const {
235  return mpfr_cmp_d(rep(), sl) < 0;
236 }
237 
238 template<> inline
239 bool Scl<MPFR>::operator < (int si) const
240 {
241  return mpfr_cmp_si(rep(), (long) si) < 0;
242 }
243 
244 
245 template<> inline
246 bool Scl<MPFR>::operator < (unsigned long ul) const
247 {
248  return mpfr_cmp_ui(rep(), ul) < 0;
249 }
250 
251 // <= ------------------------------------------------------------------
252 
253 template<> inline
254 bool Scl<MPFR>::operator <= (const Scl<MPFR>& rhs) const
255 {
256  return mpfr_cmp(rep(), rhs.rep()) <= 0;
257 }
258 template<> inline
259 bool Scl<MPFR>::operator <= (double sl) const {
260  return mpfr_cmp_d(rep(), sl) <= 0;
261 }
262 
263 
264 template<> inline
265 bool Scl<MPFR>::operator <= (long sl) const {
266  return mpfr_cmp_si(rep(), sl) <= 0;
267 }
268 
269 template<> inline
270 bool Scl<MPFR>::operator <= (int si) const
271 {
272  return mpfr_cmp_si(rep(), (long) si) <= 0;
273 }
274 
275 template<> inline
276 bool Scl<MPFR>::operator <= (unsigned long ul) const
277 {
278  return mpfr_cmp_ui(rep(), ul) <= 0;
279 }
280 
281 // = -------------------------------------------------------------------
282 template<> inline
284 {
285  mpfr_set_ui(rep(), ul,MPFR_RNDN); return *this;
286 }
287 
288 template<> inline
290 {
291  mpfr_set_d(rep(), ul,MPFR_RNDN); return *this;
292 }
293 
294 template<> inline
296 {
297  mpfr_set_si(rep(), sl,MPFR_RNDN); return *this;
298 }
299 
300 template<> inline
302 {
303  mpfr_set_si(rep(), ul,MPFR_RNDN); return *this;
304 }
305 // += -------------------------------------------------------------------
306 template<> inline
308 {
309  Scl<MPFR> tmp;
310  //mpfr_init(tmp.rep());
311  mpfr_add(tmp.rep(), rep(), rhs.rep(),MPFR_RNDN);
312  mpfr_swap(tmp.rep(),rep());
313  return *this;
314 
315 }
316 
317 template<> inline
319 {
320  mpfr_add_ui(rep(), rep(), ul,MPFR_RNDN);
321  return *this;
322 }
323 
324 template<> inline
326 {
327  if (sl >= 0)
328  mpfr_add_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
329  else
330  mpfr_sub_ui(rep(), rep(), ((unsigned long) -sl),MPFR_RNDN);
331  return *this;
332 }
333 
334 template<> inline
336 {
337  if (sl >= 0)
338  mpfr_add_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
339  else
340  mpfr_sub_ui(rep(), rep(), ((unsigned long) -sl),MPFR_RNDN);
341  return *this;
342 }
343 
344 
345 template<> inline
347 {
348  *this += Scl<MPFR>(ul); return *this;
349 }
350 
351 // -= -------------------------------------------------------------------
352 template<> inline
354 {
355  mpfr_sub(rep(), rep(), rhs.rep(),MPFR_RNDN);
356  return *this;
357 }
358 
359 template<> inline
361 {
362  Scl<MPFR> tmp(ul);
363  *this-=tmp;
364  return *this;
365 }
366 template<> inline
368 {
369  mpfr_sub_ui(rep(), rep(), ul,MPFR_RNDN);
370  return *this;
371 }
372 
373 template<> inline
375 {
376  if (sl >= 0)
377  mpfr_sub_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
378  else
379  mpfr_add_ui(rep(), rep(), (unsigned long) -sl,MPFR_RNDN);
380  return *this;
381 }
382 
383 template<> inline
385 {
386  if (sl >= 0)
387  mpfr_sub_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
388  else
389  mpfr_add_ui(rep(), rep(), (unsigned long) -sl,MPFR_RNDN);
390  return *this;
391  // *this -= Scl<MPFR>(ul); return *this;
392 }
393 // *= -----------------------------------------------------------------
394 template<> inline
396 {
397  mpfr_mul(rep(), rep(), rhs.rep(),MPFR_RNDN);
398  return *this;
399 }
400 template<> inline
402 {
403  mpfr_mul_ui(rep(), rep(), ul,MPFR_RNDN);
404  return *this;
405 }
406 template<> inline
408 {
409  if (sl >= 0)
410  mpfr_mul_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
411  else
412  {
413  mpfr_neg(rep(),rep(),MPFR_RNDN);
414  mpfr_mul_ui(rep(), rep(),(unsigned long)(-sl),MPFR_RNDN);
415  }
416  return *this;
417 }
418 template<> inline
420 {
421  return *this*=(Scl<MPFR>)d;
422 }
423 
424 template<> inline
426 {
427  if (ul >= 0)
428  mpfr_mul_ui(rep(), rep(), (unsigned long) ul,MPFR_RNDN);
429  else {
430  mpfr_mul_ui(rep(), rep(), (unsigned long) (-ul),MPFR_RNDN);
431  mpfr_neg(rep(), rep(),MPFR_RNDN);
432  }
433  return *this;
434 }
435 // /= ------------------------------------------------------------------
436 template<>
438 {
439  mpfr_div(rep(), rep(), rhs.rep(),MPFR_RNDN);
440  //mpfr_divexact(&rep(), &rep(), &rhs.rep());
441  return *this;
442 }
443 template<> inline
445 {
446  mpfr_div_ui(rep(), rep(), ul,MPFR_RNDN);
447  return *this;
448 }
449 
450 template<> inline
452 {
453  if (sl >= 0)
454  mpfr_div_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
455  else
456  {
457  mpfr_neg(rep(),rep(),MPFR_RNDN);
458  mpfr_div_ui(rep(), rep(), ((unsigned long) -sl),MPFR_RNDN);
459  }
460  return *this;
461 }
462 template<> inline
464 {
465  if (sl >= 0)
466  mpfr_div_ui(rep(), rep(), (unsigned long) sl,MPFR_RNDN);
467  else
468  {
469  mpfr_neg(rep(),rep(),MPFR_RNDN);
470  mpfr_div_ui(rep(), rep(), ((unsigned long) -sl),MPFR_RNDN);
471  }
472  return *this;
473 }
474 
475 //======================================================================
476 // ARITHMETIC OPERATORS
477 //======================================================================
478 #if 0
479 Scl<MPFR> operator -(const Scl<MPFR>& a1)
480 {
481  Scl<MPFR> result(a1);
482  result*=(-1);
483  return result;
484 }
485 #endif
487 {
488  Scl<MPFR> result;
489  mpfr_add(result.rep(), a1.rep(), a2.rep(),MPFR_RNDN);
490  return result;
491 }
492 // //----------------------------------------------------------------------
494 {
495  Scl<MPFR> result;
496  mpfr_sub(result.rep(), a1.rep(), a2.rep(),MPFR_RNDN);
497  return result;
498 }
499 //----------------------------------------------------------------------
501 {
502  Scl<MPFR> result;
503  mpfr_mul(result.rep(), a1.rep(), a2.rep(),MPFR_RNDN);
504  return result;
505 }
506 Scl<MPFR> operator *(const Scl<MPFR>& a1, double a2)
507 {
508  Scl<MPFR> result(a1);
509  result*=a2;
510  return result;
511 }
512 
513 //----------------------------------------------------------------------
515 {
516  Scl<MPFR> result;
517  mpfr_div(result.rep(), a1.rep(), a2.rep(),MPFR_RNDN);
518  return result;
519 }
520 Scl<MPFR> operator /(double a2,const Scl<MPFR>& a1)
521 {
522  Scl<MPFR> result(a2);
523  result/=a1;
524  return result;
525 }
526 Scl<MPFR> operator /(const Scl<MPFR>& a1, double a2)
527 {
528  Scl<MPFR> result=a1;
529  Scl<MPFR>tmp(a2);
530  result/=tmp;
531  return result;
532 }
533 Scl<MPFR> operator /(int a2,const Scl<MPFR>& a1)
534 {
535  Scl<MPFR> result(a2);
536  result/=a1;
537  return result;
538 }
539 Scl<MPFR> operator /(const Scl<MPFR>& a1, int a2)
540 {
541  Scl<MPFR> result(a1);
542  Scl<MPFR>tmp(a2);
543  result/=tmp;
544  return result;
545 }
546 
547 Scl<MPFR> operator /(long int a2,const Scl<MPFR>& a1)
548 {
549  Scl<MPFR> result(a2);
550  result/=a1;
551  return result;
552 }
553 //Scl<MPFR> operator /(const Scl<MPFR>& a1, long int a2)
554 //{
555 // Scl<MPFR> result(a1);
556 // Scl<MPFR>tmp(a2);
557 // result/=tmp;
558 // return result;
559 //}
560 
561 
562 
564 template<> inline
566 {
567  mpfr_add_ui(rep(), rep(), 1,MPFR_RNDN);
568 }
569 //----------------------------------------------------------------------
571 template<> inline
573 {
574  mpfr_sub_ui(rep(), rep(), 1,MPFR_RNDN);
575 }
576 //======================================================================
577 inline void convert(Scl<MPFR>& n, char *s)
578 {
579  // printf("%s\n",s);
580  mpfr_init_set_str(n.rep(), s, 10,MPFR_RNDN);
581  //cout<<"apres convert "<<mpfr_get_d(n.rep())<<endl;;
582 }
583 
584 //======================================================================
585 // INPUT OUTPUT
586 //======================================================================
587 std::ostream& operator << (std::ostream& os, const Scl<MPFR>& x)
588 {
589  //std::cout<<"\nrrr ";
590  //mpfr_out_str(stdout,10,mpfr_get_prec(x.rep()),x.rep(),MPFR_RNDN);
591  //std::cout<<"\n";
592 
593  //os<<std::setprecision(40);
594  unsigned sz= mpfr_get_prec(x.rep())+1;
595  //std::cout<<" prec "<<sz<<std::endl;
596  char* tmp = new char [sz];
597 
598  int n = os.precision();
599  mpfr_exp_t e;
600  mpfr_get_str (tmp+1, &e, 10, n, x.rep(), MPFR_RNDN);
601 
602  int s=(x<0?2:1);
603  tmp[0] = tmp[1];
604  tmp[s-1]= tmp[s];
605  tmp[s] = '.';
606 
607 
608  //mpfr_sprintf(tmp,"%.RNf",x.rep());
609  os<< tmp;
610  if(e!=1)
611  os << "e" << e-1;
612  //delete[] tmp;
613  return os;
614 }
615 //----------------------------------------------------------------------
616 std::istream& operator >> (std::istream& is, Scl<MPFR>& b)
617 {
618  std::string s; is >> s;
619  //cout<<"ici string "<<s<<endl;
620  mpfr_init_set_str(b.rep(), s.c_str(), 10, MPFR_RNDN);
621 
622  return is;
623 }
624 
625 bool has_positive_sign(const Scl<MPFR>& b) {
626  return (b>0);
627 }
628 
629 //======================================================================
630 // SPECIAL FUNCTIONS
631 //======================================================================
635 void Precision(unsigned long l)
636 {
637  mpfr_set_default_prec(l);
638 }
639 //----------------------------------------------------------------------
643 void Precision( Scl<MPFR>& b, unsigned long l)
644 {
645  mpfr_set_prec(b.rep(),l);
646 }
647 //======================================================================
648 template<> inline
649 void Scl<MPFR>::Div2Exp (unsigned long exponent_of_2)
650 {
651  mpfr_div_2exp(rep(), rep(), exponent_of_2,MPFR_RNDN);
652 }
653 
654 template<> inline void
656 {
657  if (mpfr_sgn(rep()) < 0)
658  mpfr_neg(rep(),rep(),MPFR_RNDN);
659 }
660 
661 template<> inline
663 {
664  mpfr_neg(rep(),rep(),MPFR_RNDN);
665  //rep()._mp_size = - rep()._mp_size;
666  return *this;
667 }
668 
669 template<> inline
671 {
672  mpfr_sqrt(rep(), rep(),MPFR_RNDN);
673 }
674 
675 //-------------------------- log(...) -----------------------------------
676 inline Scl<MPFR> log (const Scl<MPFR>& b)
677 {
678  mpfr_t tmp;
679  Scl<MPFR> res;
680  mpfr_set_default_prec(mpfr_get_default_prec()+10);
681  mpfr_init(tmp);
682  mpfr_set(tmp,b.rep(),MPFR_RNDN);
683  mpfr_log(tmp,tmp,MPFR_RNDN);
684  mpfr_set(res.rep(),tmp,MPFR_RNDN);
685  mpfr_clear(tmp);
686  return res;
687 
688  //return mpfr_size(b.rep());
689 }
690 //-------------------------- sign ---------------------------------------------
691 inline int sign (const Scl<MPFR>& b)
692 {
693  return mpfr_sgn(b.rep());
694 }
695 //--------------------------------------------------------------------------------
696 //#ifdef ONEMORETIME
697 
698 
699 template<> inline
701 
702  mpfr_pow_ui(rep(),rep(),exp,MPFR_RNDN);
703  return *this;
704 }
705 
706 
707 inline Scl<MPFR> pow(const Scl<MPFR>& b1, const Scl<MPFR>& b2)
708 {
709  //cout<<"puissance "<<b1<<" "<<b2<<endl;
710  mpfr_t tmpb1,tmpb2;
711  Scl<MPFR> res;
712  if(1)
713  {
714  // mpfr_set_default_prec(mpfr_get_default_prec()+10);
715  mpfr_init(tmpb1);
716  mpfr_init(tmpb2);
717  mpfr_set(tmpb1,b1.rep(),MPFR_RNDN);
718  mpfr_set(tmpb2,b2.rep(),MPFR_RNDN);
719  mpfr_pow(tmpb1,tmpb1,tmpb2,MPFR_RNDN);
720  mpfr_set(res.rep(),tmpb1,MPFR_RNDN);
721  //cout<<"res puissance pos"<<res<<endl;
722  mpfr_clear(tmpb1);
723  mpfr_clear(tmpb2);
724  }
725  else
726  {
727  mpfr_init(tmpb1);
728  mpfr_init(tmpb2);
729  mpfr_set(tmpb1,b1.rep(),MPFR_RNDN);
730  mpfr_set(tmpb2,b2.rep(),MPFR_RNDN);
731  mpfr_neg(tmpb2,tmpb2,MPFR_RNDN);
732  //mpfr_printf("le tmpb1 : %Rf\n",tmpb1);
733  //mpfr_printf("le tmpb2 : %Rf\n",tmpb2);
734  mpfr_pow(tmpb1,tmpb1,tmpb2,MPFR_RNDN);
735  //mpfr_printf("le temp : %Rf\n",tmpb1);
736  fflush(stdout);
737  mpfr_ui_div(tmpb1,1l,tmpb1,MPFR_RNDN);
738  mpfr_set(res.rep(),tmpb1,MPFR_RNDN);
739  //cout<<"res puissance neg "<<res<<endl;
740  mpfr_clear(tmpb1);
741  mpfr_clear(tmpb2);
742 
743  }
744  return res;
745 
746 }
747 
748 //-------------------------- compare (...) ------------------------------------
749 inline int compare (const Scl<MPFR>& b1, const Scl<MPFR>& b2)
750 {
751  return mpfr_cmp(b1.rep(), b2.rep());
752 }
753 
754 inline int compare (const Scl<MPFR>& b, unsigned long ul)
755 {
756  return mpfr_cmp_ui(b.rep(), ul);
757 }
758 
759 inline int compare (const Scl<MPFR>& b, long sl)
760 {
761  return mpfr_cmp_si(b.rep(), sl);
762 }
763 
764 bool operator > (double ul, const Scl<MPFR> &rhs)
765 {
766  //mdebug()<<"double > RR"<<ul<<rhs;
767  return mpfr_cmp_d(rhs.rep(), ul) < 0;
768 }
769 bool operator < (double ul, const Scl<MPFR> &rhs)
770 {
771  return mpfr_cmp_d(rhs.rep(), ul) > 0;
772 }
773 bool operator < (int ul, const Scl<MPFR> &rhs)
774 {
775  return mpfr_cmp_si(rhs.rep(), ul) > 0;
776 }
777 bool operator > (int ul, const Scl<MPFR> &rhs)
778 {
779  //mdebug()<<"int > RR"<<ul<<rhs<<(mpfr_cmp_si(rhs.rep(), ul) < 0);
780  return mpfr_cmp_si(rhs.rep(), ul) < 0;
781 }
782 //----------------------------------------------------------------------
783 Scl<MPFR> fmax(const Scl<MPFR>& a, const Scl<MPFR>& b) {
784  if(b>a)
785  return b;
786  else
787  return a;
788 }
789 
791  mpfr_t tmp;
792  Scl<MPFR> res;
793  mpfr_set_default_prec(mpfr_get_default_prec()+10);
794  mpfr_init(tmp);
795  mpfr_set(tmp,x.rep(),GMP_RNDN);
796  if(x<0)
797  mpfr_neg(tmp,tmp,GMP_RNDN);
798  mpfr_log2(tmp,tmp,GMP_RNDN);
799  mpfr_set(res.rep(),tmp,GMP_RNDN);
800  mpfr_clear(tmp);
801  return res;
802 }
803 
804 int isinf(const Scl<MPFR>& x) {
805  return mpfr_inf_p(x.rep());
806 }
807 
808 int isfinite(const Scl<MPFR>& x) {
809  return (mpfr_inf_p(x.rep())==0?1:0);
810 }
811 
812 int isnan(const Scl<MPFR>& x) {
813  return mpfr_nan_p(x.rep());
814 }
815 
817  Scl<MPFR> result(x);
818  result.abs();
819  return result;
820 }
821 
823  Scl<MPFR> res;
824  mpfr_copysign(res.rep(),a.rep(),b.rep(), MPFR_RNDN);
825  return res;
826 }
827 namespace std {
829  return fabs(x);
830  }
831 }
832 #endif // //SCL_MPF_H
int sign(const Scl< MPFR > &b)
Definition: Scl_mpfr.hpp:691
bool has_positive_sign(const Scl< MPFR > &b)
Definition: Scl_mpfr.hpp:625
unsigned long MPFR_PRECISION
Definition: Scl_mpfr.hpp:27
bool operator>(double ul, const Scl< MPFR > &rhs)
Definition: Scl_mpfr.hpp:764
int isfinite(const Scl< MPFR > &x)
Definition: Scl_mpfr.hpp:808
int isinf(const Scl< MPFR > &x)
Definition: Scl_mpfr.hpp:804
Scl< T > & negate()
void sqrt()
void Div2Exp(unsigned long exponent_of_2)
Definition: Scl_mpfr.hpp:827
Scl< T > operator-=(const Scl< T > &rhs)
MSKaccmodee MSKint32t MSKsoltypee MSKstakeye MSKrealt MSKrealt * sl
Definition: mosek.h:3209
Scl< MPFR > logb(const Scl< MPFR > &x)
Definition: Scl_mpfr.hpp:790
Scl< T > operator+=(const Scl< T > &rhs)
int compare(const Scl< MPFR > &b1, const Scl< MPFR > &b2)
Definition: Scl_mpfr.hpp:749
static double castDouble(Scl< T > &ref)
bool operator>=(const Scl< T > &rhs) const
void operator--()
Scl< MPFR > log(const Scl< MPFR > &b)
Definition: Scl_mpfr.hpp:676
MSKaccmodee MSKint32t MSKsoltypee MSKstakeye MSKrealt * x
Definition: mosek.h:3209
Scl< T > operator*=(const Scl< T > &rhs)
void operator++()
bool operator==(const Scl< T > &rhs) const
MSKCONST char * str
Definition: mosek.h:2317
Scl< MPFR > fmax(const Scl< MPFR > &a, const Scl< MPFR > &b)
Definition: Scl_mpfr.hpp:783
Scl< MPFR > copysign(const Scl< MPFR > &a, const Scl< MPFR > &b)
Definition: Scl_mpfr.hpp:822
Scl< MPFR > operator/(const Scl< MPFR > &a1, const Scl< MPFR > &a2)
Definition: Scl_mpfr.hpp:514
mpfr_t MPFR
Definition: Scl_mpfr.hpp:25
Scl()
Definition: Scl.hpp:38
bool operator<=(const Scl< T > &rhs) const
Scl< T > & pow(int exp)
Scl< T > operator/=(const Scl< T > &rhs)
int isnan(const Scl< MPFR > &x)
Definition: Scl_mpfr.hpp:812
Definition: Scl.hpp:26
Scl< MPFR > operator-(const Scl< MPFR > &a1, const Scl< MPFR > &a2)
Definition: Scl_mpfr.hpp:493
void convert(Scl< MPFR > &n, char *s)
Definition: Scl_mpfr.hpp:577
Scl< MPFR > fabs(const Scl< MPFR > &x)
Definition: Scl_mpfr.hpp:816
void Precision(unsigned long l)
Definition: Scl_mpfr.hpp:635
std::istream & operator>>(std::istream &is, Scl< MPFR > &b)
Definition: Scl_mpfr.hpp:616
Scl< T > operator=(const Scl< T > &rhs)
Scl< MPFR > operator+(const Scl< MPFR > &a1, const Scl< MPFR > &a2)
Definition: Scl_mpfr.hpp:486
bool operator>(const Scl< T > &rhs) const
MSKstreamtypee MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t a
Definition: mosek.h:3833
void abs()
Scl< MPFR > pow(const Scl< MPFR > &b1, const Scl< MPFR > &b2)
Definition: Scl_mpfr.hpp:707
T & rep()
Definition: Scl.hpp:35
~Scl()
Definition: Scl.hpp:49
bool operator!=(const Scl< T > &rhs) const
Scl< MPFR > operator*(const Scl< MPFR > &a1, const Scl< MPFR > &a2)
Definition: Scl_mpfr.hpp:500
bool operator<(const Scl< T > &rhs) const
Scl< MPFR > abs(const Scl< MPFR > &x)
Definition: Scl_mpfr.hpp:828
Home  |  Download & InstallContributions