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-2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 // some compilers (e.g. cygwin) define a macro log2, causing confusion
49 /** Integer binary logarithm */
50 unsigned log2(unsigned n)
53 for (k = 0; n > 1; n >>= 1)
61 // flyweight chest of numbers is initialized here:
64 /** How many static objects were created? Only the first one must create
65 * the static flyweights on the heap. */
66 int library_init::count = 0;
68 // static numeric -120
69 const numeric *_num_120_p;
70 const numeric &_num_120 = *_num_120_p;
71 const ex _ex_120 = _num_120;
74 const numeric *_num_60_p;
75 const numeric &_num_60 = *_num_60_p;
76 const ex _ex_60 = _num_60;
79 const numeric *_num_48_p;
80 const numeric &_num_48 = *_num_48_p;
81 const ex _ex_48 = _num_48;
84 const numeric *_num_30_p;
85 const numeric &_num_30 = *_num_30_p;
86 const ex _ex_30 = _num_30;
89 const numeric *_num_25_p;
90 const numeric &_num_25 = *_num_25_p;
91 const ex _ex_25 = _num_25;
94 const numeric *_num_24_p;
95 const numeric &_num_24 = *_num_24_p;
96 const ex _ex_24 = _num_24;
99 const numeric *_num_20_p;
100 const numeric &_num_20 = *_num_20_p;
101 const ex _ex_20 = _num_20;
103 // static numeric -18
104 const numeric *_num_18_p;
105 const numeric &_num_18 = *_num_18_p;
106 const ex _ex_18 = _num_18;
108 // static numeric -15
109 const numeric *_num_15_p;
110 const numeric &_num_15 = *_num_15_p;
111 const ex _ex_15 = _num_15;
113 // static numeric -12
114 const numeric *_num_12_p;
115 const numeric &_num_12 = *_num_12_p;
116 const ex _ex_12 = _num_12;
118 // static numeric -11
119 const numeric *_num_11_p;
120 const numeric &_num_11 = *_num_11_p;
121 const ex _ex_11 = _num_11;
123 // static numeric -10
124 const numeric *_num_10_p;
125 const numeric &_num_10 = *_num_10_p;
126 const ex _ex_10 = _num_10;
129 const numeric *_num_9_p;
130 const numeric &_num_9 = *_num_9_p;
131 const ex _ex_9 = _num_9;
134 const numeric *_num_8_p;
135 const numeric &_num_8 = *_num_8_p;
136 const ex _ex_8 = _num_8;
139 const numeric *_num_7_p;
140 const numeric &_num_7 = *_num_7_p;
141 const ex _ex_7 = _num_7;
144 const numeric *_num_6_p;
145 const numeric &_num_6 = *_num_6_p;
146 const ex _ex_6 = _num_6;
149 const numeric *_num_5_p;
150 const numeric &_num_5 = *_num_5_p;
151 const ex _ex_5 = _num_5;
154 const numeric *_num_4_p;
155 const numeric &_num_4 = *_num_4_p;
156 const ex _ex_4 = _num_4;
159 const numeric *_num_3_p;
160 const numeric &_num_3 = *_num_3_p;
161 const ex _ex_3 = _num_3;
164 const numeric *_num_2_p;
165 const numeric &_num_2 = *_num_2_p;
166 const ex _ex_2 = _num_2;
169 const numeric *_num_1_p;
170 const numeric &_num_1 = *_num_1_p;
171 const ex _ex_1 = _num_1;
173 // static numeric -1/2
174 const numeric *_num_1_2_p;
175 const numeric &_num_1_2= *_num_1_2_p;
176 const ex _ex_1_2= _num_1_2;
178 // static numeric -1/3
179 const numeric *_num_1_3_p;
180 const numeric &_num_1_3= *_num_1_3_p;
181 const ex _ex_1_3= _num_1_3;
183 // static numeric -1/4
184 const numeric *_num_1_4_p;
185 const numeric &_num_1_4= *_num_1_4_p;
186 const ex _ex_1_4= _num_1_4;
189 const numeric *_num0_p;
190 const basic *_num0_bp;
191 const numeric &_num0 = *_num0_p;
192 const ex _ex0 = _num0;
194 // static numeric 1/4
195 const numeric *_num1_4_p;
196 const numeric &_num1_4 = *_num1_4_p;
197 const ex _ex1_4 = _num1_4;
199 // static numeric 1/3
200 const numeric *_num1_3_p;
201 const numeric &_num1_3 = *_num1_3_p;
202 const ex _ex1_3 = _num1_3;
204 // static numeric 1/2
205 const numeric *_num1_2_p;
206 const numeric &_num1_2 = *_num1_2_p;
207 const ex _ex1_2 = _num1_2;
210 const numeric *_num1_p;
211 const numeric &_num1 = *_num1_p;
212 const ex _ex1 = _num1;
215 const numeric *_num2_p;
216 const numeric &_num2 = *_num2_p;
217 const ex _ex2 = _num2;
220 const numeric *_num3_p;
221 const numeric &_num3 = *_num3_p;
222 const ex _ex3 = _num3;
225 const numeric *_num4_p;
226 const numeric &_num4 = *_num4_p;
227 const ex _ex4 = _num4;
230 const numeric *_num5_p;
231 const numeric &_num5 = *_num5_p;
232 const ex _ex5 = _num5;
235 const numeric *_num6_p;
236 const numeric &_num6 = *_num6_p;
237 const ex _ex6 = _num6;
240 const numeric *_num7_p;
241 const numeric &_num7 = *_num7_p;
242 const ex _ex7 = _num7;
245 const numeric *_num8_p;
246 const numeric &_num8 = *_num8_p;
247 const ex _ex8 = _num8;
250 const numeric *_num9_p;
251 const numeric &_num9 = *_num9_p;
252 const ex _ex9 = _num9;
255 const numeric *_num10_p;
256 const numeric &_num10 = *_num10_p;
257 const ex _ex10 = _num10;
260 const numeric *_num11_p;
261 const numeric &_num11 = *_num11_p;
262 const ex _ex11 = _num11;
265 const numeric *_num12_p;
266 const numeric &_num12 = *_num12_p;
267 const ex _ex12 = _num12;
270 const numeric *_num15_p;
271 const numeric &_num15 = *_num15_p;
272 const ex _ex15 = _num15;
275 const numeric *_num18_p;
276 const numeric &_num18 = *_num18_p;
277 const ex _ex18 = _num18;
280 const numeric *_num20_p;
281 const numeric &_num20 = *_num20_p;
282 const ex _ex20 = _num20;
285 const numeric *_num24_p;
286 const numeric &_num24 = *_num24_p;
287 const ex _ex24 = _num24;
290 const numeric *_num25_p;
291 const numeric &_num25 = *_num25_p;
292 const ex _ex25 = _num25;
295 const numeric *_num30_p;
296 const numeric &_num30 = *_num30_p;
297 const ex _ex30 = _num30;
300 const numeric *_num48_p;
301 const numeric &_num48 = *_num48_p;
302 const ex _ex48 = _num48;
305 const numeric *_num60_p;
306 const numeric &_num60 = *_num60_p;
307 const ex _ex60 = _num60;
309 // static numeric 120
310 const numeric *_num120_p;
311 const numeric &_num120 = *_num120_p;
312 const ex _ex120 = _num120;
314 /** Ctor of static initialization helpers. The fist call to this is going
315 * to initialize the library, the others do nothing. */
316 library_init::library_init()
319 _num_120_p= reinterpret_cast<const numeric*>(&((new numeric(-120))->setflag(status_flags::dynallocated)));
320 _num_60_p = reinterpret_cast<const numeric*>(&((new numeric(-60))->setflag(status_flags::dynallocated)));
321 _num_48_p = reinterpret_cast<const numeric*>(&((new numeric(-48))->setflag(status_flags::dynallocated)));
322 _num_30_p = reinterpret_cast<const numeric*>(&((new numeric(-30))->setflag(status_flags::dynallocated)));
323 _num_25_p = reinterpret_cast<const numeric*>(&((new numeric(-25))->setflag(status_flags::dynallocated)));
324 _num_24_p = reinterpret_cast<const numeric*>(&((new numeric(-24))->setflag(status_flags::dynallocated)));
325 _num_20_p = reinterpret_cast<const numeric*>(&((new numeric(-20))->setflag(status_flags::dynallocated)));
326 _num_18_p = reinterpret_cast<const numeric*>(&((new numeric(-18))->setflag(status_flags::dynallocated)));
327 _num_15_p = reinterpret_cast<const numeric*>(&((new numeric(-15))->setflag(status_flags::dynallocated)));
328 _num_12_p = reinterpret_cast<const numeric*>(&((new numeric(-12))->setflag(status_flags::dynallocated)));
329 _num_11_p = reinterpret_cast<const numeric*>(&((new numeric(-11))->setflag(status_flags::dynallocated)));
330 _num_10_p = reinterpret_cast<const numeric*>(&((new numeric(-10))->setflag(status_flags::dynallocated)));
331 _num_9_p = reinterpret_cast<const numeric*>(&((new numeric(-9))->setflag(status_flags::dynallocated)));
332 _num_8_p = reinterpret_cast<const numeric*>(&((new numeric(-8))->setflag(status_flags::dynallocated)));
333 _num_7_p = reinterpret_cast<const numeric*>(&((new numeric(-7))->setflag(status_flags::dynallocated)));
334 _num_6_p = reinterpret_cast<const numeric*>(&((new numeric(-6))->setflag(status_flags::dynallocated)));
335 _num_5_p = reinterpret_cast<const numeric*>(&((new numeric(-5))->setflag(status_flags::dynallocated)));
336 _num_4_p = reinterpret_cast<const numeric*>(&((new numeric(-4))->setflag(status_flags::dynallocated)));
337 _num_3_p = reinterpret_cast<const numeric*>(&((new numeric(-3))->setflag(status_flags::dynallocated)));
338 _num_2_p = reinterpret_cast<const numeric*>(&((new numeric(-2))->setflag(status_flags::dynallocated)));
339 _num_1_p = reinterpret_cast<const numeric*>(&((new numeric(-1))->setflag(status_flags::dynallocated)));
340 _num_1_2_p= reinterpret_cast<const numeric*>(&((new numeric(-1,2))->setflag(status_flags::dynallocated)));
341 _num_1_3_p= reinterpret_cast<const numeric*>(&((new numeric(-1,3))->setflag(status_flags::dynallocated)));
342 _num_1_4_p= reinterpret_cast<const numeric*>(&((new numeric(-1,4))->setflag(status_flags::dynallocated)));
343 _num0_p = reinterpret_cast<const numeric*>(&((new numeric(0))->setflag(status_flags::dynallocated)));
345 _num1_4_p = reinterpret_cast<const numeric*>(&((new numeric(1,4))->setflag(status_flags::dynallocated)));
346 _num1_3_p = reinterpret_cast<const numeric*>(&((new numeric(1,3))->setflag(status_flags::dynallocated)));
347 _num1_2_p = reinterpret_cast<const numeric*>(&((new numeric(1,2))->setflag(status_flags::dynallocated)));
348 _num1_p = reinterpret_cast<const numeric*>(&((new numeric(1))->setflag(status_flags::dynallocated)));
349 _num2_p = reinterpret_cast<const numeric*>(&((new numeric(2))->setflag(status_flags::dynallocated)));
350 _num3_p = reinterpret_cast<const numeric*>(&((new numeric(3))->setflag(status_flags::dynallocated)));
351 _num4_p = reinterpret_cast<const numeric*>(&((new numeric(4))->setflag(status_flags::dynallocated)));
352 _num5_p = reinterpret_cast<const numeric*>(&((new numeric(5))->setflag(status_flags::dynallocated)));
353 _num6_p = reinterpret_cast<const numeric*>(&((new numeric(6))->setflag(status_flags::dynallocated)));
354 _num7_p = reinterpret_cast<const numeric*>(&((new numeric(7))->setflag(status_flags::dynallocated)));
355 _num8_p = reinterpret_cast<const numeric*>(&((new numeric(8))->setflag(status_flags::dynallocated)));
356 _num9_p = reinterpret_cast<const numeric*>(&((new numeric(9))->setflag(status_flags::dynallocated)));
357 _num10_p = reinterpret_cast<const numeric*>(&((new numeric(10))->setflag(status_flags::dynallocated)));
358 _num11_p = reinterpret_cast<const numeric*>(&((new numeric(11))->setflag(status_flags::dynallocated)));
359 _num12_p = reinterpret_cast<const numeric*>(&((new numeric(12))->setflag(status_flags::dynallocated)));
360 _num15_p = reinterpret_cast<const numeric*>(&((new numeric(15))->setflag(status_flags::dynallocated)));
361 _num18_p = reinterpret_cast<const numeric*>(&((new numeric(18))->setflag(status_flags::dynallocated)));
362 _num20_p = reinterpret_cast<const numeric*>(&((new numeric(20))->setflag(status_flags::dynallocated)));
363 _num24_p = reinterpret_cast<const numeric*>(&((new numeric(24))->setflag(status_flags::dynallocated)));
364 _num25_p = reinterpret_cast<const numeric*>(&((new numeric(25))->setflag(status_flags::dynallocated)));
365 _num30_p = reinterpret_cast<const numeric*>(&((new numeric(30))->setflag(status_flags::dynallocated)));
366 _num48_p = reinterpret_cast<const numeric*>(&((new numeric(48))->setflag(status_flags::dynallocated)));
367 _num60_p = reinterpret_cast<const numeric*>(&((new numeric(60))->setflag(status_flags::dynallocated)));
368 _num120_p = reinterpret_cast<const numeric*>(&((new numeric(120))->setflag(status_flags::dynallocated)));
370 // Initialize print context class info (this is not strictly necessary
371 // but we do it anyway to make print_context_class_info::dump_hierarchy()
372 // output the whole hierarchy whether or not the classes are actually
374 print_context::get_class_info_static();
375 print_dflt::get_class_info_static();
376 print_latex::get_class_info_static();
377 print_python::get_class_info_static();
378 print_python_repr::get_class_info_static();
379 print_tree::get_class_info_static();
380 print_csrc::get_class_info_static();
381 print_csrc_float::get_class_info_static();
382 print_csrc_double::get_class_info_static();
383 print_csrc_cl_N::get_class_info_static();
388 /** Dtor of static initialization helpers. The last call to this is going
389 * to shut down the library, the others do nothing. */
390 library_init::~library_init()
393 // In theory, we would have to clean up here. But since we were
394 // only initializing memory in the ctor and that memory is reclaimed
395 // anyways by the OS when the program exits, we skip this.
399 // comment skeleton for header files
404 // default constructor, destructor, copy constructor and assignment operator
407 // other constructors
410 // functions overriding virtual functions from base classes
413 // new virtual functions which can be overridden by derived classes
416 // non-virtual functions in this class
424 // comment skeleton for implementation files
428 // default constructor, destructor, copy constructor and assignment operator
435 // other constructors
442 // functions overriding virtual functions from base classes
450 // new virtual functions which can be overridden by derived classes
458 // non-virtual functions in this class
466 // static member variables