]> www.ginac.de Git - ginac.git/commitdiff
- rotate_31() and golden_hash_ratio() moved to utils.h
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 19 Nov 1999 19:22:11 +0000 (19:22 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 19 Nov 1999 19:22:11 +0000 (19:22 +0000)
- golden_hash_ratio() looks for a suitable data type by means of defines
  from config.h

ginac/basic.h
ginac/expairseq.cpp
ginac/inifcns.cpp
ginac/inifcns.h
ginac/utils.cpp
ginac/utils.h

index f397b778e15d0492d0a139854c3bbf91f9e7cb7b..ef4e8cfbc5786801bee454d905df1353cf5d4d3b 100644 (file)
@@ -179,6 +179,7 @@ extern type_info const & typeid_basic;
 extern int max_recursion_level;
 
 // convenience macros
+
 #define is_of_type(OBJ,TYPE) \
     (dynamic_cast<TYPE *>(const_cast<GiNaC::basic *>(&OBJ))!=0)
 
@@ -191,40 +192,6 @@ extern int max_recursion_level;
 #define is_ex_exactly_of_type(OBJ,TYPE) \
     ((*(OBJ).bp).tinfo()==GiNaC::TINFO_##TYPE)
 
-
-// global functions
-
-inline unsigned rotate_left_31(unsigned n)
-{
-    // clear highest bit and shift 1 bit to the left
-    n=(n & 0x7FFFFFFFU) << 1;
-
-    // overflow? clear highest bit and set lowest bit
-    if (n & 0x80000000U) {
-        n=(n & 0x7FFFFFFFU) | 0x00000001U;
-    }
-
-    ASSERT(n<0x80000000U);
-
-    return n;
-}
-
-inline unsigned golden_ratio_hash(unsigned n)
-{
-#if 0
-       // This requires ´long long´ (or an equivalent 64 bit type)---which is,
-    // unfortunately, not ANSI-compliant:
-       unsigned long long l = n * 0x4f1bbcddLL;
-       return (l & 0x7fffffffU) ^ (l >> 32);
-#else
-       // This requires ´long double´ to have a mantissa of at least 64 bit---
-    // which is not guaranteed by any standard:
-    const static long double golden_ratio=.618033988749894848204586834370;
-    long double m=golden_ratio*n;
-    return unsigned((m-int(m))*0x80000000);
-#endif
-}
-
 } // namespace GiNaC
 
 #endif // ndef __GINAC_BASIC_H__
index f74be45e84da27a15e273ea8a14df0ee70d044a9..05b7233d108e259b951009e018fda8b6ee707fa1 100644 (file)
@@ -27,6 +27,7 @@
 #include "expairseq.h"
 #include "lst.h"
 #include "debugmsg.h"
+#include "utils.h"
 
 namespace GiNaC {
 
index cee71b182c3d136d919bee38aff89f70634ccc29..de48b858452b01c3e2bde8c857e8046de4c06fc0 100644 (file)
@@ -247,4 +247,9 @@ ex ncpower(ex const &basis, unsigned exponent)
     return ncmul(v,1);
 }
 
+/** Force inclusion of functions from initcns_gamma and inifcns_zeta
+ *  for static lib (so ginsh will see them). */
+unsigned force_include_gamma = function_index_gamma;
+unsigned force_include_zeta = function_index_zeta;
+
 } // namespace GiNaC
index f7622dd43b9500e3099387c136db4bc168b38616..ee7378180684df7fc2abf2d0df95696cc46e96ca 100644 (file)
@@ -81,13 +81,13 @@ DECLARE_FUNCTION_1P(Li3)
 
 /** Riemann's Zeta-function. */
 DECLARE_FUNCTION_1P(zeta)
-DECLARE_FUNCTION_2P(zeta)
-    
+//DECLARE_FUNCTION_2P(zeta)
+
 /** Gamma-function. */
 DECLARE_FUNCTION_1P(gamma)
 
 /** Psi-function (aka polygamma-function). */
-DECLARE_FUNCTION_1P(psi)
+//DECLARE_FUNCTION_1P(psi)
 DECLARE_FUNCTION_2P(psi)
     
 /** Factorial function. */
index 446377b219ecbd7c4d7d6c6b14ff3f0af82cf552..0c99ad59976a47a293bd1e7c18f8e1a93556d7f1 100644 (file)
@@ -24,6 +24,7 @@
 
 namespace GiNaC {
 
+/** Integer binary logarithm */
 unsigned log2(unsigned n)
 {
     unsigned k;
@@ -31,6 +32,8 @@ unsigned log2(unsigned n)
     return k;
 }
 
+/** Compare two pointers (just to establish some sort of canonical order).
+ *  @return -1, 0, or 1 */
 int compare_pointers(void const * a, void const * b)
 {
     if (a<b) {
@@ -41,7 +44,8 @@ int compare_pointers(void const * a, void const * b)
     return 0;
 }
 
-// comment skeletton for header files
+
+// comment skeleton for header files
 
 
 // member functions
@@ -66,7 +70,7 @@ int compare_pointers(void const * a, void const * b)
     
 
 
-// comment skeletton for implementation files
+// comment skeleton for implementation files
 
 
 //////////
index edde75fcde3ff071cd7e8ed4b88bcfc9a6840d99..814654c65563b65c8a0b81009fee94c330526429 100644 (file)
@@ -26,6 +26,7 @@
 #include <strstream>
 #include <string>
 #include "config.h"
+#include "assertion.h"
 
 namespace GiNaC {
 
@@ -41,6 +42,47 @@ unsigned log2(unsigned n);
 
 int compare_pointers(void const * a, void const * b);
 
+/** Rotate lower 31 bits of unsigned value by one bit to the left
+ *  (upper bits get cleared). */
+inline unsigned rotate_left_31(unsigned n)
+{
+    // clear highest bit and shift 1 bit to the left
+    n=(n & 0x7FFFFFFFU) << 1;
+
+    // overflow? clear highest bit and set lowest bit
+    if (n & 0x80000000U) {
+        n=(n & 0x7FFFFFFFU) | 0x00000001U;
+    }
+    ASSERT(n<0x80000000U);
+
+    return n;
+}
+
+/** Golden ratio hash function. */
+inline unsigned golden_ratio_hash(unsigned n)
+{
+       // This function requires arithmetic with at least 64 significant bits
+#if SIZEOF_LONG_DOUBLE > 8
+       // If "long double" is bigger than 64 bits, we assume that the mantissa
+       // has at least 64 bits. This is not guaranteed but it's a good guess.
+    const static long double golden_ratio = .618033988749894848204586834370;
+    long double m = golden_ratio * n;
+    return unsigned((m - int(m)) * 0x80000000);
+#elif SIZEOF_LONG >= 8
+       // "long" has 64 bits, so we prefer it because it might be more efficient
+       // than "long long"
+       unsigned long l = n * 0x4f1bbcddL;
+       return (l & 0x7fffffffU) ^ (l >> 32);
+#elif SIZEOF_LONG_LONG >= 8
+       // This requires ´long long´ (or an equivalent 64 bit type)---which is,
+    // unfortunately, not ANSI-compliant:
+       unsigned long long l = n * 0x4f1bbcddLL;
+       return (l & 0x7fffffffU) ^ (l >> 32);
+#else
+#error "No 64 bit data type. You lose."
+#endif
+}
+
 // modified from stl_algo.h: always do com(*first1,*first2) instead of comp(*first2,*first1)
 template <class InputIterator1, class InputIterator2, class OutputIterator,
           class Compare>