]> www.ginac.de Git - ginac.git/blobdiff - ginac/utils.cpp
* Simplified creation of flyweight objects (by Chris Dams).
[ginac.git] / ginac / utils.cpp
index 12a8d1b3251db17dcc19a23fba05c5fd6a311c4b..274c23678f235bf8f5ef619cade80562f639d5b6 100644 (file)
@@ -4,7 +4,7 @@
  *  but not of any interest to the user of the library. */
 
 /*
- *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -44,8 +44,6 @@ int pole_error::degree() const
        return deg;
 }
 
-// some compilers (e.g. cygwin) define a macro log2, causing confusion
-#ifndef log2
 /** Integer binary logarithm */
 unsigned log2(unsigned n)
 {
@@ -54,7 +52,6 @@ unsigned log2(unsigned n)
                ++k;
        return k;
 }
-#endif
 
 
 //////////
@@ -316,56 +313,71 @@ const ex _ex120 = _num120;
 library_init::library_init()
 {
        if (count++==0) {
-               _num_120_p= reinterpret_cast<const numeric*>(&((new numeric(-120))->setflag(status_flags::dynallocated)));
-               _num_60_p = reinterpret_cast<const numeric*>(&((new numeric(-60))->setflag(status_flags::dynallocated)));
-               _num_48_p = reinterpret_cast<const numeric*>(&((new numeric(-48))->setflag(status_flags::dynallocated)));
-               _num_30_p = reinterpret_cast<const numeric*>(&((new numeric(-30))->setflag(status_flags::dynallocated)));
-               _num_25_p = reinterpret_cast<const numeric*>(&((new numeric(-25))->setflag(status_flags::dynallocated)));
-               _num_24_p = reinterpret_cast<const numeric*>(&((new numeric(-24))->setflag(status_flags::dynallocated)));
-               _num_20_p = reinterpret_cast<const numeric*>(&((new numeric(-20))->setflag(status_flags::dynallocated)));
-               _num_18_p = reinterpret_cast<const numeric*>(&((new numeric(-18))->setflag(status_flags::dynallocated)));
-               _num_15_p = reinterpret_cast<const numeric*>(&((new numeric(-15))->setflag(status_flags::dynallocated)));
-               _num_12_p = reinterpret_cast<const numeric*>(&((new numeric(-12))->setflag(status_flags::dynallocated)));
-               _num_11_p = reinterpret_cast<const numeric*>(&((new numeric(-11))->setflag(status_flags::dynallocated)));
-               _num_10_p = reinterpret_cast<const numeric*>(&((new numeric(-10))->setflag(status_flags::dynallocated)));
-               _num_9_p  = reinterpret_cast<const numeric*>(&((new numeric(-9))->setflag(status_flags::dynallocated)));
-               _num_8_p  = reinterpret_cast<const numeric*>(&((new numeric(-8))->setflag(status_flags::dynallocated)));
-               _num_7_p  = reinterpret_cast<const numeric*>(&((new numeric(-7))->setflag(status_flags::dynallocated)));
-               _num_6_p  = reinterpret_cast<const numeric*>(&((new numeric(-6))->setflag(status_flags::dynallocated)));
-               _num_5_p  = reinterpret_cast<const numeric*>(&((new numeric(-5))->setflag(status_flags::dynallocated)));
-               _num_4_p  = reinterpret_cast<const numeric*>(&((new numeric(-4))->setflag(status_flags::dynallocated)));
-               _num_3_p  = reinterpret_cast<const numeric*>(&((new numeric(-3))->setflag(status_flags::dynallocated)));
-               _num_2_p  = reinterpret_cast<const numeric*>(&((new numeric(-2))->setflag(status_flags::dynallocated)));
-               _num_1_p  = reinterpret_cast<const numeric*>(&((new numeric(-1))->setflag(status_flags::dynallocated)));
-               _num_1_2_p= reinterpret_cast<const numeric*>(&((new numeric(-1,2))->setflag(status_flags::dynallocated)));
-               _num_1_3_p= reinterpret_cast<const numeric*>(&((new numeric(-1,3))->setflag(status_flags::dynallocated)));
-               _num_1_4_p= reinterpret_cast<const numeric*>(&((new numeric(-1,4))->setflag(status_flags::dynallocated)));
-               _num0_p   = reinterpret_cast<const numeric*>(&((new numeric(0))->setflag(status_flags::dynallocated)));
-               _num0_bp  = _num0_p;
-               _num1_4_p = reinterpret_cast<const numeric*>(&((new numeric(1,4))->setflag(status_flags::dynallocated)));
-               _num1_3_p = reinterpret_cast<const numeric*>(&((new numeric(1,3))->setflag(status_flags::dynallocated)));
-               _num1_2_p = reinterpret_cast<const numeric*>(&((new numeric(1,2))->setflag(status_flags::dynallocated)));
-               _num1_p   = reinterpret_cast<const numeric*>(&((new numeric(1))->setflag(status_flags::dynallocated)));
-               _num2_p   = reinterpret_cast<const numeric*>(&((new numeric(2))->setflag(status_flags::dynallocated)));
-               _num3_p   = reinterpret_cast<const numeric*>(&((new numeric(3))->setflag(status_flags::dynallocated)));
-               _num4_p   = reinterpret_cast<const numeric*>(&((new numeric(4))->setflag(status_flags::dynallocated)));
-               _num5_p   = reinterpret_cast<const numeric*>(&((new numeric(5))->setflag(status_flags::dynallocated)));
-               _num6_p   = reinterpret_cast<const numeric*>(&((new numeric(6))->setflag(status_flags::dynallocated)));
-               _num7_p   = reinterpret_cast<const numeric*>(&((new numeric(7))->setflag(status_flags::dynallocated)));
-               _num8_p   = reinterpret_cast<const numeric*>(&((new numeric(8))->setflag(status_flags::dynallocated)));
-               _num9_p   = reinterpret_cast<const numeric*>(&((new numeric(9))->setflag(status_flags::dynallocated)));
-               _num10_p  = reinterpret_cast<const numeric*>(&((new numeric(10))->setflag(status_flags::dynallocated)));
-               _num11_p  = reinterpret_cast<const numeric*>(&((new numeric(11))->setflag(status_flags::dynallocated)));
-               _num12_p  = reinterpret_cast<const numeric*>(&((new numeric(12))->setflag(status_flags::dynallocated)));
-               _num15_p  = reinterpret_cast<const numeric*>(&((new numeric(15))->setflag(status_flags::dynallocated)));
-               _num18_p  = reinterpret_cast<const numeric*>(&((new numeric(18))->setflag(status_flags::dynallocated)));
-               _num20_p  = reinterpret_cast<const numeric*>(&((new numeric(20))->setflag(status_flags::dynallocated)));
-               _num24_p  = reinterpret_cast<const numeric*>(&((new numeric(24))->setflag(status_flags::dynallocated)));
-               _num25_p  = reinterpret_cast<const numeric*>(&((new numeric(25))->setflag(status_flags::dynallocated)));
-               _num30_p  = reinterpret_cast<const numeric*>(&((new numeric(30))->setflag(status_flags::dynallocated)));
-               _num48_p  = reinterpret_cast<const numeric*>(&((new numeric(48))->setflag(status_flags::dynallocated)));
-               _num60_p  = reinterpret_cast<const numeric*>(&((new numeric(60))->setflag(status_flags::dynallocated)));
-               _num120_p = reinterpret_cast<const numeric*>(&((new numeric(120))->setflag(status_flags::dynallocated)));
+               (_num_120_p = new numeric(-120))->setflag(status_flags::dynallocated);
+               (_num_60_p = new numeric(-60))->setflag(status_flags::dynallocated);
+               (_num_48_p = new numeric(-48))->setflag(status_flags::dynallocated);
+               (_num_30_p = new numeric(-30))->setflag(status_flags::dynallocated);
+               (_num_25_p = new numeric(-25))->setflag(status_flags::dynallocated);
+               (_num_24_p = new numeric(-24))->setflag(status_flags::dynallocated);
+               (_num_20_p = new numeric(-20))->setflag(status_flags::dynallocated);
+               (_num_18_p = new numeric(-18))->setflag(status_flags::dynallocated);
+               (_num_15_p = new numeric(-15))->setflag(status_flags::dynallocated);
+               (_num_12_p = new numeric(-12))->setflag(status_flags::dynallocated);
+               (_num_11_p = new numeric(-11))->setflag(status_flags::dynallocated);
+               (_num_10_p = new numeric(-10))->setflag(status_flags::dynallocated);
+               (_num_9_p = new numeric(-9))->setflag(status_flags::dynallocated);
+               (_num_8_p = new numeric(-8))->setflag(status_flags::dynallocated);
+               (_num_7_p = new numeric(-7))->setflag(status_flags::dynallocated);
+               (_num_6_p = new numeric(-6))->setflag(status_flags::dynallocated);
+               (_num_5_p = new numeric(-5))->setflag(status_flags::dynallocated);
+               (_num_4_p = new numeric(-4))->setflag(status_flags::dynallocated);
+               (_num_3_p = new numeric(-3))->setflag(status_flags::dynallocated);
+               (_num_2_p = new numeric(-2))->setflag(status_flags::dynallocated);
+               (_num_1_p = new numeric(-1))->setflag(status_flags::dynallocated);
+               (_num_1_2_p = new numeric(-1,2))->setflag(status_flags::dynallocated);
+               (_num_1_3_p = new numeric(-1,3))->setflag(status_flags::dynallocated);
+               (_num_1_4_p = new numeric(-1,4))->setflag(status_flags::dynallocated);
+               (_num0_p = new numeric(0))->setflag(status_flags::dynallocated);
+               _num0_bp  = _num0_p;  // Cf. class ex default ctor.
+               (_num1_4_p = new numeric(1,4))->setflag(status_flags::dynallocated);
+               (_num1_3_p = new numeric(1,3))->setflag(status_flags::dynallocated);
+               (_num1_2_p = new numeric(1,2))->setflag(status_flags::dynallocated);
+               (_num1_p = new numeric(1))->setflag(status_flags::dynallocated);
+               (_num2_p = new numeric(2))->setflag(status_flags::dynallocated);
+               (_num3_p = new numeric(3))->setflag(status_flags::dynallocated);
+               (_num4_p = new numeric(4))->setflag(status_flags::dynallocated);
+               (_num5_p = new numeric(5))->setflag(status_flags::dynallocated);
+               (_num6_p = new numeric(6))->setflag(status_flags::dynallocated);
+               (_num7_p = new numeric(7))->setflag(status_flags::dynallocated);
+               (_num8_p = new numeric(8))->setflag(status_flags::dynallocated);
+               (_num9_p = new numeric(9))->setflag(status_flags::dynallocated);
+               (_num10_p = new numeric(10))->setflag(status_flags::dynallocated);
+               (_num11_p = new numeric(11))->setflag(status_flags::dynallocated);
+               (_num12_p = new numeric(12))->setflag(status_flags::dynallocated);
+               (_num15_p = new numeric(15))->setflag(status_flags::dynallocated);
+               (_num18_p = new numeric(18))->setflag(status_flags::dynallocated);
+               (_num20_p = new numeric(20))->setflag(status_flags::dynallocated);
+               (_num24_p = new numeric(24))->setflag(status_flags::dynallocated);
+               (_num25_p = new numeric(25))->setflag(status_flags::dynallocated);
+               (_num30_p = new numeric(30))->setflag(status_flags::dynallocated);
+               (_num48_p = new numeric(48))->setflag(status_flags::dynallocated);
+               (_num60_p = new numeric(60))->setflag(status_flags::dynallocated);
+               (_num120_p = new numeric(120))->setflag(status_flags::dynallocated);
+
+               // Initialize print context class info (this is not strictly necessary
+               // but we do it anyway to make print_context_class_info::dump_hierarchy()
+               // output the whole hierarchy whether or not the classes are actually
+               // used)
+               print_context::get_class_info_static();
+               print_dflt::get_class_info_static();
+               print_latex::get_class_info_static();
+               print_python::get_class_info_static();
+               print_python_repr::get_class_info_static();
+               print_tree::get_class_info_static();
+               print_csrc::get_class_info_static();
+               print_csrc_float::get_class_info_static();
+               print_csrc_double::get_class_info_static();
+               print_csrc_cl_N::get_class_info_static();
        }
 }