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