]> www.ginac.de Git - ginac.git/blobdiff - ginac/utils.h
- Patches needed for cygwin.
[ginac.git] / ginac / utils.h
index 4af88ebada3e0258ea7939a39dfcfd5f6ce5e9e6..13fa2c8b956bafc17d8ca33640b8575467b9ba44 100644 (file)
 #include "config.h"
 #include "assertion.h"
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 template<class T>
-string ToString(T const & t)
+string ToString(const T & t)
 {
     char buf[256];
     ostrstream(buf,sizeof(buf)) << t << ends;
@@ -45,7 +45,10 @@ string ToString(T const & t)
  *  signal that ordinary Taylor expansion is safe. */
 class do_taylor {};
 
+// cygwin defines a macro log2, causing confusion
+#ifndef log2
 unsigned log2(unsigned n);
+#endif
 
 int compare_pointers(const void * a, const void * b);
 
@@ -138,6 +141,26 @@ OutputIterator mymerge3(InputIterator1 first1, InputIterator1 last1,
     }
 }
 
+// Compute the sign of a permutation of a vector of things.
+template <typename T>
+int permutation_sign(vector<T> s)
+{
+    if (s.size() < 2)
+        return 0;
+    int sigma = 1;
+    for (typename vector<T>::iterator i=s.begin(); i!=s.end()-1; ++i) {
+        for (typename vector<T>::iterator j=i+1; j!=s.end(); ++j) {
+            if (*i == *j)
+                return 0;
+            if (*i > *j) {
+                iter_swap(i,j);
+                sigma = -sigma;
+            }
+        }
+    }
+    return sigma;
+}
+
 // Collection of `construct on first use' wrappers for safely avoiding
 // internal object replication without running into the `static
 // initialization order fiasco'.  This chest of numbers helps speed up
@@ -242,8 +265,8 @@ const ex & _ex60(void);
 const numeric & _num120(void);    //  120
 const ex & _ex120(void);
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 #endif // ndef __GINAC_UTILS_H__