]> www.ginac.de Git - ginac.git/blob - ginac/utils.cpp
- See if __GNUC__ < 2.97 before using std::vector<..,malloc_alloc>. Sorry,
[ginac.git] / ginac / utils.cpp
1 /** @file utils.cpp
2  *
3  *  Implementation of several small and furry utilities needed within GiNaC
4  *  but not of any interest to the user of the library. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program 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
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "ex.h"
25 #include "numeric.h"
26 #include "utils.h"
27 #include "version.h"
28
29 #ifndef NO_NAMESPACE_GINAC
30 namespace GiNaC {
31 #endif // ndef NO_NAMESPACE_GINAC
32
33 /* Version information buried into the library */
34 const int version_major = GINACLIB_MAJOR_VERSION;
35 const int version_minor = GINACLIB_MINOR_VERSION;
36 const int version_micro = GINACLIB_MICRO_VERSION;
37
38
39 /** ctor for pole_error exception class. */
40 pole_error::pole_error(const std::string& what_arg, int degree)
41   : domain_error(what_arg)
42 {
43         deg = degree;
44 }
45
46 /** Return the degree of the pole_error exception class. */
47 int pole_error::degree(void) const
48 {
49         return deg;
50 }
51
52 // some compilers (e.g. cygwin) define a macro log2, causing confusion
53 #ifndef log2
54 /** Integer binary logarithm */
55 unsigned log2(unsigned n)
56 {
57         unsigned k;
58         for (k = 0; n > 1; n >>= 1) ++k;
59         return k;
60 }
61 #endif
62
63 /** Compare two pointers (just to establish some sort of canonical order).
64  *  @return -1, 0, or 1 */
65 int compare_pointers(const void * a, const void * b)
66 {
67         if (a<b) {
68                 return -1;
69         } else if (a>b) {
70                 return 1;
71         }
72         return 0;
73 }
74
75 //////////
76 // `construct on first use' chest of numbers
77 //////////
78
79 // numeric -120
80 const numeric & _num_120(void)
81 {
82         const static ex e = ex(numeric(-120));
83         const static numeric * n = static_cast<const numeric *>(e.bp);
84         return *n;
85 }
86
87 const ex & _ex_120(void)
88 {
89         static ex * e = new ex(_num_120());
90         return *e;
91 }
92
93 // numeric -60
94 const numeric & _num_60(void)
95 {
96         const static ex e = ex(numeric(-60));
97         const static numeric * n = static_cast<const numeric *>(e.bp);
98         return *n;
99 }
100
101 const ex & _ex_60(void)
102 {
103         static ex * e = new ex(_num_60());
104         return *e;
105 }
106
107 // numeric -48
108 const numeric & _num_48(void)
109 {
110         const static ex e = ex(numeric(-48));
111         const static numeric * n = static_cast<const numeric *>(e.bp);
112         return *n;
113 }
114
115 const ex & _ex_48(void)
116 {
117         static ex * e = new ex(_num_48());
118         return *e;
119 }
120
121 // numeric -30
122 const numeric & _num_30(void)
123 {
124         const static ex e = ex(numeric(-30));
125         const static numeric * n = static_cast<const numeric *>(e.bp);
126         return *n;
127 }
128
129 const ex & _ex_30(void)
130 {
131         static ex * e = new ex(_num_30());
132         return *e;
133 }
134
135 // numeric -25
136 const numeric & _num_25(void)
137 {
138         const static ex e = ex(numeric(-25));
139         const static numeric * n = static_cast<const numeric *>(e.bp);
140         return *n;
141 }
142
143 const ex & _ex_25(void)
144 {
145         static ex * e = new ex(_num_25());
146         return *e;
147 }
148
149 // numeric -24
150 const numeric & _num_24(void)
151 {
152         const static ex e = ex(numeric(-24));
153         const static numeric * n = static_cast<const numeric *>(e.bp);
154         return *n;
155 }
156
157 const ex & _ex_24(void)
158 {
159         static ex * e = new ex(_num_24());
160         return *e;
161 }
162
163 // numeric -20
164 const numeric & _num_20(void)
165 {
166         const static ex e = ex(numeric(-20));
167         const static numeric * n = static_cast<const numeric *>(e.bp);
168         return *n;
169 }
170
171 const ex & _ex_20(void)
172 {
173         static ex * e = new ex(_num_20());
174         return *e;
175 }
176
177 // numeric -18
178 const numeric & _num_18(void)
179 {
180         const static ex e = ex(numeric(-18));
181         const static numeric * n = static_cast<const numeric *>(e.bp);
182         return *n;
183 }
184
185 const ex & _ex_18(void)
186 {
187         static ex * e = new ex(_num_18());
188         return *e;
189 }
190
191 // numeric -15
192 const numeric & _num_15(void)
193 {
194         const static ex e = ex(numeric(-15));
195         const static numeric * n = static_cast<const numeric *>(e.bp);
196         return *n;
197 }
198
199 const ex & _ex_15(void)
200 {
201         static ex * e = new ex(_num_15());
202         return *e;
203 }
204
205 // numeric -12
206 const numeric & _num_12(void)
207 {
208         const static ex e = ex(numeric(-12));
209         const static numeric * n = static_cast<const numeric *>(e.bp);
210         return *n;
211 }
212
213 const ex & _ex_12(void)
214 {
215         static ex * e = new ex(_num_12());
216         return *e;
217 }
218
219 // numeric -11
220 const numeric & _num_11(void)
221 {
222         const static ex e = ex(numeric(-11));
223         const static numeric * n = static_cast<const numeric *>(e.bp);
224         return *n;
225 }
226
227 const ex & _ex_11(void)
228 {
229         static ex * e = new ex(_num_11());
230         return *e;
231 }
232
233 // numeric -10
234 const numeric & _num_10(void)
235 {
236         const static ex e = ex(numeric(-10));
237         const static numeric * n = static_cast<const numeric *>(e.bp);
238         return *n;
239 }
240
241 const ex & _ex_10(void)
242 {
243         static ex * e = new ex(_num_10());
244         return *e;
245 }
246
247 // numeric -9
248 const numeric & _num_9(void)
249 {
250         const static ex e = ex(numeric(-9));
251         const static numeric * n = static_cast<const numeric *>(e.bp);
252         return *n;
253 }
254
255 const ex & _ex_9(void)
256 {
257         static ex * e = new ex(_num_9());
258         return *e;
259 }
260
261 // numeric -8
262 const numeric & _num_8(void)
263 {
264         const static ex e = ex(numeric(-8));
265         const static numeric * n = static_cast<const numeric *>(e.bp);
266         return *n;
267 }
268
269 const ex & _ex_8(void)
270 {
271         static ex * e = new ex(_num_8());
272         return *e;
273 }
274
275 // numeric -7
276 const numeric & _num_7(void)
277 {
278         const static ex e = ex(numeric(-7));
279         const static numeric * n = static_cast<const numeric *>(e.bp);
280         return *n;
281 }
282
283 const ex & _ex_7(void)
284 {
285         static ex * e = new ex(_num_7());
286         return *e;
287 }
288
289 // numeric -6
290 const numeric & _num_6(void)
291 {
292         const static ex e = ex(numeric(-6));
293         const static numeric * n = static_cast<const numeric *>(e.bp);
294         return *n;
295 }
296
297 const ex & _ex_6(void)
298 {
299         static ex * e = new ex(_num_6());
300         return *e;
301 }
302
303 // numeric -5
304 const numeric & _num_5(void)
305 {
306         const static ex e = ex(numeric(-5));
307         const static numeric * n = static_cast<const numeric *>(e.bp);
308         return *n;
309 }
310
311 const ex & _ex_5(void)
312 {
313         static ex * e = new ex(_num_5());
314         return *e;
315 }
316
317 // numeric -4
318 const numeric & _num_4(void)
319 {
320         const static ex e = ex(numeric(-4));
321         const static numeric * n = static_cast<const numeric *>(e.bp);
322         return *n;
323 }
324
325 const ex & _ex_4(void)
326 {
327         static ex * e = new ex(_num_4());
328         return *e;
329 }
330
331 // numeric -3
332 const numeric & _num_3(void)
333 {
334         const static ex e = ex(numeric(-3));
335         const static numeric * n = static_cast<const numeric *>(e.bp);
336         return *n;
337 }
338
339 const ex & _ex_3(void)
340 {
341         static ex * e = new ex(_num_3());
342         return *e;
343 }
344
345 // numeric -2
346 const numeric & _num_2(void)
347 {
348         const static ex e = ex(numeric(-2));
349         const static numeric * n = static_cast<const numeric *>(e.bp);
350         return *n;
351 }
352
353 const ex & _ex_2(void)
354 {
355         static ex * e = new ex(_num_2());
356         return *e;
357 }
358
359 // numeric -1
360 const numeric & _num_1(void)
361 {
362         const static ex e = ex(numeric(-1));
363         const static numeric * n = static_cast<const numeric *>(e.bp);
364         return *n;
365 }
366
367 const ex & _ex_1(void)
368 {
369         static ex * e = new ex(_num_1());
370         return *e;
371 }
372
373 // numeric -1/2
374 const numeric & _num_1_2(void)
375 {
376         const static ex e = ex(numeric(-1,2));
377         const static numeric * n = static_cast<const numeric *>(e.bp);
378         return *n;
379 }
380
381 const ex & _ex_1_2(void)
382 {
383         static ex * e = new ex(_num_1_2());
384         return *e;
385 }    
386
387 // numeric -1/3
388 const numeric & _num_1_3(void)
389 {
390         const static ex e = ex(numeric(-1,3));
391         const static numeric * n = static_cast<const numeric *>(e.bp);
392         return *n;
393 }
394
395 const ex & _ex_1_3(void)
396 {
397         static ex * e = new ex(_num_1_3());
398         return *e;
399 }    
400
401 // numeric -1/4
402 const numeric & _num_1_4(void)
403 {
404         const static ex e = ex(numeric(-1,4));
405         const static numeric * n = static_cast<const numeric *>(e.bp);
406         return *n;
407 }
408
409 const ex & _ex_1_4(void)
410 {
411         static ex * e = new ex(_num_1_4());
412         return *e;
413 }    
414
415 // numeric  0
416 const numeric & _num0(void)
417 {
418         const static ex e = ex(numeric(0));
419         const static numeric * n = static_cast<const numeric *>(e.bp);
420         return *n;
421 }
422
423 const ex & _ex0(void)
424 {
425         static ex * e = new ex(_num0());
426         return *e;
427 }
428
429 // numeric  1/4
430 const numeric & _num1_4(void)
431 {
432         const static ex e = ex(numeric(1,4));
433         const static numeric * n = static_cast<const numeric *>(e.bp);
434         return *n;
435 }
436
437 const ex & _ex1_4(void)
438 {
439         static ex * e = new ex(_num1_4());
440         return *e;
441 }    
442
443 // numeric  1/3
444 const numeric & _num1_3(void)
445 {
446         const static ex e = ex(numeric(1,3));
447         const static numeric * n = static_cast<const numeric *>(e.bp);
448         return *n;
449 }
450
451 const ex & _ex1_3(void)
452 {
453         static ex * e = new ex(_num1_3());
454         return *e;
455 }    
456
457 // numeric  1/2
458 const numeric & _num1_2(void)
459 {
460         const static ex e = ex(numeric(1,2));
461         const static numeric * n = static_cast<const numeric *>(e.bp);
462         return *n;
463 }
464
465 const ex & _ex1_2(void)
466 {
467         static ex * e = new ex(_num1_2());
468         return *e;
469 }    
470
471 // numeric  1
472 const numeric & _num1(void)
473 {
474         const static ex e = ex(numeric(1));
475         const static numeric * n = static_cast<const numeric *>(e.bp);
476         return *n;
477 }
478
479 const ex & _ex1(void)
480 {
481         static ex * e = new ex(_num1());
482         return *e;
483 }
484
485 // numeric  2
486 const numeric & _num2(void)
487 {
488         const static ex e = ex(numeric(2));
489         const static numeric * n = static_cast<const numeric *>(e.bp);
490         return *n;
491 }
492
493 const ex & _ex2(void)
494 {
495         static ex * e = new ex(_num2());
496         return *e;
497 }
498
499 // numeric  3
500 const numeric & _num3(void)
501 {
502         const static ex e = ex(numeric(3));
503         const static numeric * n = static_cast<const numeric *>(e.bp);
504         return *n;
505 }
506
507 const ex & _ex3(void)
508 {
509         static ex * e = new ex(_num3());
510         return *e;
511 }
512
513 // numeric  4
514 const numeric & _num4(void)
515 {
516         const static ex e = ex(numeric(4));
517         const static numeric * n = static_cast<const numeric *>(e.bp);
518         return *n;
519 }
520
521 const ex & _ex4(void)
522 {
523         static ex * e = new ex(_num4());
524         return *e;
525 }
526
527 // numeric  5
528 const numeric & _num5(void)
529 {
530         const static ex e = ex(numeric(5));
531         const static numeric * n = static_cast<const numeric *>(e.bp);
532         return *n;
533 }
534
535 const ex & _ex5(void)
536 {
537         static ex * e = new ex(_num5());
538         return *e;
539 }
540
541 // numeric  6
542 const numeric & _num6(void)
543 {
544         const static ex e = ex(numeric(6));
545         const static numeric * n = static_cast<const numeric *>(e.bp);
546         return *n;
547 }
548
549 const ex & _ex6(void)
550 {
551         static ex * e = new ex(_num6());
552         return *e;
553 }
554
555 // numeric  7
556 const numeric & _num7(void)
557 {
558         const static ex e = ex(numeric(7));
559         const static numeric * n = static_cast<const numeric *>(e.bp);
560         return *n;
561 }
562
563 const ex & _ex7(void)
564 {
565         static ex * e = new ex(_num7());
566         return *e;
567 }
568
569 // numeric  8
570 const numeric & _num8(void)
571 {
572         const static ex e = ex(numeric(8));
573         const static numeric * n = static_cast<const numeric *>(e.bp);
574         return *n;
575 }
576
577 const ex & _ex8(void)
578 {
579         static ex * e = new ex(_num8());
580         return *e;
581 }
582
583 // numeric  9
584 const numeric & _num9(void)
585 {
586         const static ex e = ex(numeric(9));
587         const static numeric * n = static_cast<const numeric *>(e.bp);
588         return *n;
589 }
590
591 const ex & _ex9(void)
592 {
593         static ex * e = new ex(_num9());
594         return *e;
595 }
596
597 // numeric  10
598 const numeric & _num10(void)
599 {
600         const static ex e = ex(numeric(10));
601         const static numeric * n = static_cast<const numeric *>(e.bp);
602         return *n;
603 }
604
605 const ex & _ex10(void)
606 {
607         static ex * e = new ex(_num10());
608         return *e;
609 }
610
611 // numeric  11
612 const numeric & _num11(void)
613 {
614         const static ex e = ex(numeric(11));
615         const static numeric * n = static_cast<const numeric *>(e.bp);
616         return *n;
617 }
618
619 const ex & _ex11(void)
620 {
621         static ex * e = new ex(_num11());
622         return *e;
623 }
624
625 // numeric  12
626 const numeric & _num12(void)
627 {
628         const static ex e = ex(numeric(12));
629         const static numeric * n = static_cast<const numeric *>(e.bp);
630         return *n;
631 }
632
633 const ex & _ex12(void)
634 {
635         static ex * e = new ex(_num12());
636         return *e;
637 }
638
639 // numeric  15
640 const numeric & _num15(void)
641 {
642         const static ex e = ex(numeric(15));
643         const static numeric * n = static_cast<const numeric *>(e.bp);
644         return *n;
645 }
646
647 const ex & _ex15(void)
648 {
649         static ex * e = new ex(_num15());
650         return *e;
651 }
652
653 // numeric  18
654 const numeric & _num18(void)
655 {
656         const static ex e = ex(numeric(18));
657         const static numeric * n = static_cast<const numeric *>(e.bp);
658         return *n;
659 }
660
661 const ex & _ex18(void)
662 {
663         static ex * e = new ex(_num18());
664         return *e;
665 }
666
667 // numeric  20
668 const numeric & _num20(void)
669 {
670         const static ex e = ex(numeric(20));
671         const static numeric * n = static_cast<const numeric *>(e.bp);
672         return *n;
673 }
674
675 const ex & _ex20(void)
676 {
677         static ex * e = new ex(_num20());
678         return *e;
679 }
680
681 // numeric  24
682 const numeric & _num24(void)
683 {
684         const static ex e = ex(numeric(24));
685         const static numeric * n = static_cast<const numeric *>(e.bp);
686         return *n;
687 }
688
689 const ex & _ex24(void)
690 {
691         static ex * e = new ex(_num24());
692         return *e;
693 }
694
695 // numeric  25
696 const numeric & _num25(void)
697 {
698         const static ex e = ex(numeric(25));
699         const static numeric * n = static_cast<const numeric *>(e.bp);
700         return *n;
701 }
702
703 const ex & _ex25(void)
704 {
705         static ex * e = new ex(_num25());
706         return *e;
707 }
708
709 // numeric  30
710 const numeric & _num30(void)
711 {
712         const static ex e = ex(numeric(30));
713         const static numeric * n = static_cast<const numeric *>(e.bp);
714         return *n;
715 }
716
717 const ex & _ex30(void)
718 {
719         static ex * e = new ex(_num30());
720         return *e;
721 }
722
723 // numeric  48
724 const numeric & _num48(void)
725 {
726         const static ex e = ex(numeric(48));
727         const static numeric * n = static_cast<const numeric *>(e.bp);
728         return *n;
729 }
730
731 const ex & _ex48(void)
732 {
733         static ex * e = new ex(_num48());
734         return *e;
735 }
736
737 // numeric  60
738 const numeric & _num60(void)
739 {
740         const static ex e = ex(numeric(60));
741         const static numeric * n = static_cast<const numeric *>(e.bp);
742         return *n;
743 }
744
745 const ex & _ex60(void)
746 {
747         static ex * e = new ex(_num60());
748         return *e;
749 }
750
751 // numeric  120
752 const numeric & _num120(void)
753 {
754         const static ex e = ex(numeric(120));
755         const static numeric * n = static_cast<const numeric *>(e.bp);
756         return *n;
757 }
758
759 const ex & _ex120(void)
760 {
761         static ex * e = new ex(_num120());
762         return *e;
763 }
764
765 // comment skeleton for header files
766
767
768 // member functions
769
770         // default constructor, destructor, copy constructor assignment operator and helpers
771         // none
772
773         // other constructors
774         // none
775
776         // functions overriding virtual functions from bases classes
777         // none
778         
779         // new virtual functions which can be overridden by derived classes
780         // none
781
782         // non-virtual functions in this class
783         // none
784
785 // member variables
786 // none
787         
788
789
790 // comment skeleton for implementation files
791
792
793 //////////
794 // default constructor, destructor, copy constructor assignment operator and helpers
795 //////////
796
797 // public
798 // protected
799
800 //////////
801 // other constructors
802 //////////
803
804 // public
805 // none
806
807 //////////
808 // functions overriding virtual functions from bases classes
809 //////////
810
811 // public
812 // protected
813 // none
814
815 //////////
816 // new virtual functions which can be overridden by derived classes
817 //////////
818
819 // public
820 // protected
821 // none
822
823 //////////
824 // non-virtual functions in this class
825 //////////
826
827 // public
828 // protected
829 // none
830
831 //////////
832 // static member variables
833 //////////
834
835 // protected
836 // private
837 // none
838
839
840 #ifndef NO_NAMESPACE_GINAC
841 } // namespace GiNaC
842 #endif // ndef NO_NAMESPACE_GINAC