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