3 * Implementation of several small and furry utilities needed within GiNaC
4 * but not of any interest to the user of the library. */
7 * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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;
37 /** ctor for pole_error exception class. */
38 pole_error::pole_error(const std::string& what_arg, int degree)
39 : domain_error(what_arg), deg(degree) { }
41 /** Return the degree of the pole_error exception class. */
42 int pole_error::degree() const
47 /** Integer binary logarithm */
48 unsigned log2(unsigned n)
51 for (k = 0; n > 1; n >>= 1)
58 // flyweight chest of numbers is initialized here:
61 /** How many static objects were created? Only the first one must create
62 * the static flyweights on the heap. */
63 int library_init::count = 0;
65 // static numeric -120
66 const numeric *_num_120_p;
67 const ex _ex_120 = _ex_120;
70 const numeric *_num_60_p;
71 const ex _ex_60 = _ex_60;
74 const numeric *_num_48_p;
75 const ex _ex_48 = _ex_48;
78 const numeric *_num_30_p;
79 const ex _ex_30 = _ex_30;
82 const numeric *_num_25_p;
83 const ex _ex_25 = _ex_25;
86 const numeric *_num_24_p;
87 const ex _ex_24 = _ex_24;
90 const numeric *_num_20_p;
91 const ex _ex_20 = _ex_20;
94 const numeric *_num_18_p;
95 const ex _ex_18 = _ex_18;
98 const numeric *_num_15_p;
99 const ex _ex_15 = _ex_15;
101 // static numeric -12
102 const numeric *_num_12_p;
103 const ex _ex_12 = _ex_12;
105 // static numeric -11
106 const numeric *_num_11_p;
107 const ex _ex_11 = _ex_11;
109 // static numeric -10
110 const numeric *_num_10_p;
111 const ex _ex_10 = _ex_10;
114 const numeric *_num_9_p;
115 const ex _ex_9 = _ex_9;
118 const numeric *_num_8_p;
119 const ex _ex_8 = _ex_8;
122 const numeric *_num_7_p;
123 const ex _ex_7 = _ex_7;
126 const numeric *_num_6_p;
127 const ex _ex_6 = _ex_6;
130 const numeric *_num_5_p;
131 const ex _ex_5 = _ex_5;
134 const numeric *_num_4_p;
135 const ex _ex_4 = _ex_4;
138 const numeric *_num_3_p;
139 const ex _ex_3 = _ex_3;
142 const numeric *_num_2_p;
143 const ex _ex_2 = _ex_2;
146 const numeric *_num_1_p;
147 const ex _ex_1 = _ex_1;
149 // static numeric -1/2
150 const numeric *_num_1_2_p;
151 const ex _ex_1_2= _ex_1_2;
153 // static numeric -1/3
154 const numeric *_num_1_3_p;
155 const ex _ex_1_3= _ex_1_3;
157 // static numeric -1/4
158 const numeric *_num_1_4_p;
159 const ex _ex_1_4= _ex_1_4;
162 const numeric *_num0_p;
163 const basic *_num0_bp;
164 const ex _ex0 = _ex0;
166 // static numeric 1/4
167 const numeric *_num1_4_p;
168 const ex _ex1_4 = _ex1_4;
170 // static numeric 1/3
171 const numeric *_num1_3_p;
172 const ex _ex1_3 = _ex1_3;
174 // static numeric 1/2
175 const numeric *_num1_2_p;
176 const ex _ex1_2 = _ex1_2;
179 const numeric *_num1_p;
180 const ex _ex1 = _ex1;
183 const numeric *_num2_p;
184 const ex _ex2 = _ex2;
187 const numeric *_num3_p;
188 const ex _ex3 = _ex3;
191 const numeric *_num4_p;
192 const ex _ex4 = _ex4;
195 const numeric *_num5_p;
196 const ex _ex5 = _ex5;
199 const numeric *_num6_p;
200 const ex _ex6 = _ex6;
203 const numeric *_num7_p;
204 const ex _ex7 = _ex7;
207 const numeric *_num8_p;
208 const ex _ex8 = _ex8;
211 const numeric *_num9_p;
212 const ex _ex9 = _ex9;
215 const numeric *_num10_p;
216 const ex _ex10 = _ex10;
219 const numeric *_num11_p;
220 const ex _ex11 = _ex11;
223 const numeric *_num12_p;
224 const ex _ex12 = _ex12;
227 const numeric *_num15_p;
228 const ex _ex15 = _ex15;
231 const numeric *_num18_p;
232 const ex _ex18 = _ex18;
235 const numeric *_num20_p;
236 const ex _ex20 = _ex20;
239 const numeric *_num24_p;
240 const ex _ex24 = _ex24;
243 const numeric *_num25_p;
244 const ex _ex25 = _ex25;
247 const numeric *_num30_p;
248 const ex _ex30 = _ex30;
251 const numeric *_num48_p;
252 const ex _ex48 = _ex48;
255 const numeric *_num60_p;
256 const ex _ex60 = _ex60;
258 // static numeric 120
259 const numeric *_num120_p;
260 const ex _ex120 = _ex120;
262 /** Ctor of static initialization helpers. The fist call to this is going
263 * to initialize the library, the others do nothing. */
264 library_init::library_init()
267 (_num_120_p = new numeric(-120))->setflag(status_flags::dynallocated);
268 (_num_60_p = new numeric(-60))->setflag(status_flags::dynallocated);
269 (_num_48_p = new numeric(-48))->setflag(status_flags::dynallocated);
270 (_num_30_p = new numeric(-30))->setflag(status_flags::dynallocated);
271 (_num_25_p = new numeric(-25))->setflag(status_flags::dynallocated);
272 (_num_24_p = new numeric(-24))->setflag(status_flags::dynallocated);
273 (_num_20_p = new numeric(-20))->setflag(status_flags::dynallocated);
274 (_num_18_p = new numeric(-18))->setflag(status_flags::dynallocated);
275 (_num_15_p = new numeric(-15))->setflag(status_flags::dynallocated);
276 (_num_12_p = new numeric(-12))->setflag(status_flags::dynallocated);
277 (_num_11_p = new numeric(-11))->setflag(status_flags::dynallocated);
278 (_num_10_p = new numeric(-10))->setflag(status_flags::dynallocated);
279 (_num_9_p = new numeric(-9))->setflag(status_flags::dynallocated);
280 (_num_8_p = new numeric(-8))->setflag(status_flags::dynallocated);
281 (_num_7_p = new numeric(-7))->setflag(status_flags::dynallocated);
282 (_num_6_p = new numeric(-6))->setflag(status_flags::dynallocated);
283 (_num_5_p = new numeric(-5))->setflag(status_flags::dynallocated);
284 (_num_4_p = new numeric(-4))->setflag(status_flags::dynallocated);
285 (_num_3_p = new numeric(-3))->setflag(status_flags::dynallocated);
286 (_num_2_p = new numeric(-2))->setflag(status_flags::dynallocated);
287 (_num_1_p = new numeric(-1))->setflag(status_flags::dynallocated);
288 (_num_1_2_p = new numeric(-1,2))->setflag(status_flags::dynallocated);
289 (_num_1_3_p = new numeric(-1,3))->setflag(status_flags::dynallocated);
290 (_num_1_4_p = new numeric(-1,4))->setflag(status_flags::dynallocated);
291 (_num0_p = new numeric(0))->setflag(status_flags::dynallocated);
292 _num0_bp = _num0_p; // Cf. class ex default ctor.
293 (_num1_4_p = new numeric(1,4))->setflag(status_flags::dynallocated);
294 (_num1_3_p = new numeric(1,3))->setflag(status_flags::dynallocated);
295 (_num1_2_p = new numeric(1,2))->setflag(status_flags::dynallocated);
296 (_num1_p = new numeric(1))->setflag(status_flags::dynallocated);
297 (_num2_p = new numeric(2))->setflag(status_flags::dynallocated);
298 (_num3_p = new numeric(3))->setflag(status_flags::dynallocated);
299 (_num4_p = new numeric(4))->setflag(status_flags::dynallocated);
300 (_num5_p = new numeric(5))->setflag(status_flags::dynallocated);
301 (_num6_p = new numeric(6))->setflag(status_flags::dynallocated);
302 (_num7_p = new numeric(7))->setflag(status_flags::dynallocated);
303 (_num8_p = new numeric(8))->setflag(status_flags::dynallocated);
304 (_num9_p = new numeric(9))->setflag(status_flags::dynallocated);
305 (_num10_p = new numeric(10))->setflag(status_flags::dynallocated);
306 (_num11_p = new numeric(11))->setflag(status_flags::dynallocated);
307 (_num12_p = new numeric(12))->setflag(status_flags::dynallocated);
308 (_num15_p = new numeric(15))->setflag(status_flags::dynallocated);
309 (_num18_p = new numeric(18))->setflag(status_flags::dynallocated);
310 (_num20_p = new numeric(20))->setflag(status_flags::dynallocated);
311 (_num24_p = new numeric(24))->setflag(status_flags::dynallocated);
312 (_num25_p = new numeric(25))->setflag(status_flags::dynallocated);
313 (_num30_p = new numeric(30))->setflag(status_flags::dynallocated);
314 (_num48_p = new numeric(48))->setflag(status_flags::dynallocated);
315 (_num60_p = new numeric(60))->setflag(status_flags::dynallocated);
316 (_num120_p = new numeric(120))->setflag(status_flags::dynallocated);
318 new((void*)&_ex_120) ex(*_num_120_p);
319 new((void*)&_ex_60) ex(*_num_60_p);
320 new((void*)&_ex_48) ex(*_num_48_p);
321 new((void*)&_ex_30) ex(*_num_30_p);
322 new((void*)&_ex_25) ex(*_num_25_p);
323 new((void*)&_ex_24) ex(*_num_24_p);
324 new((void*)&_ex_20) ex(*_num_20_p);
325 new((void*)&_ex_18) ex(*_num_18_p);
326 new((void*)&_ex_15) ex(*_num_15_p);
327 new((void*)&_ex_12) ex(*_num_12_p);
328 new((void*)&_ex_11) ex(*_num_11_p);
329 new((void*)&_ex_10) ex(*_num_10_p);
330 new((void*)&_ex_9) ex(*_num_9_p);
331 new((void*)&_ex_8) ex(*_num_8_p);
332 new((void*)&_ex_7) ex(*_num_7_p);
333 new((void*)&_ex_6) ex(*_num_6_p);
334 new((void*)&_ex_5) ex(*_num_5_p);
335 new((void*)&_ex_4) ex(*_num_4_p);
336 new((void*)&_ex_3) ex(*_num_3_p);
337 new((void*)&_ex_2) ex(*_num_2_p);
338 new((void*)&_ex_1) ex(*_num_1_p);
339 new((void*)&_ex_1_2) ex(*_num_1_2_p);
340 new((void*)&_ex_1_3) ex(*_num_1_3_p);
341 new((void*)&_ex_1_4) ex(*_num_1_4_p);
342 new((void*)&_ex0) ex(*_num0_p);
343 new((void*)&_ex1_4) ex(*_num1_4_p);
344 new((void*)&_ex1_3) ex(*_num1_3_p);
345 new((void*)&_ex1_2) ex(*_num1_2_p);
346 new((void*)&_ex1) ex(*_num1_p);
347 new((void*)&_ex2) ex(*_num2_p);
348 new((void*)&_ex3) ex(*_num3_p);
349 new((void*)&_ex4) ex(*_num4_p);
350 new((void*)&_ex5) ex(*_num5_p);
351 new((void*)&_ex6) ex(*_num6_p);
352 new((void*)&_ex7) ex(*_num7_p);
353 new((void*)&_ex8) ex(*_num8_p);
354 new((void*)&_ex9) ex(*_num9_p);
355 new((void*)&_ex10) ex(*_num10_p);
356 new((void*)&_ex11) ex(*_num11_p);
357 new((void*)&_ex12) ex(*_num12_p);
358 new((void*)&_ex15) ex(*_num15_p);
359 new((void*)&_ex18) ex(*_num18_p);
360 new((void*)&_ex20) ex(*_num20_p);
361 new((void*)&_ex24) ex(*_num24_p);
362 new((void*)&_ex25) ex(*_num25_p);
363 new((void*)&_ex30) ex(*_num30_p);
364 new((void*)&_ex48) ex(*_num48_p);
365 new((void*)&_ex60) ex(*_num60_p);
366 new((void*)&_ex120) ex(*_num120_p);
368 // Initialize print context class info (this is not strictly necessary
369 // but we do it anyway to make print_context_class_info::dump_hierarchy()
370 // output the whole hierarchy whether or not the classes are actually
372 print_context::get_class_info_static();
373 print_dflt::get_class_info_static();
374 print_latex::get_class_info_static();
375 print_python::get_class_info_static();
376 print_python_repr::get_class_info_static();
377 print_tree::get_class_info_static();
378 print_csrc::get_class_info_static();
379 print_csrc_float::get_class_info_static();
380 print_csrc_double::get_class_info_static();
381 print_csrc_cl_N::get_class_info_static();
386 /** Dtor of static initialization helpers. The last call to this is going
387 * to shut down the library, the others do nothing. */
388 library_init::~library_init()
391 // In theory, we would have to clean up here. But since we were
392 // only initializing memory in the ctor and that memory is reclaimed
393 // anyways by the OS when the program exits, we skip this.
397 // comment skeleton for header files
402 // default constructor, destructor, copy constructor and assignment operator
405 // other constructors
408 // functions overriding virtual functions from base classes
411 // new virtual functions which can be overridden by derived classes
414 // non-virtual functions in this class
422 // comment skeleton for implementation files
426 // default constructor, destructor, copy constructor and assignment operator
433 // other constructors
440 // functions overriding virtual functions from base classes
448 // new virtual functions which can be overridden by derived classes
456 // non-virtual functions in this class
464 // static member variables