#include <strstream>
#include <string>
+#include <stdexcept>
#include "config.h"
#include "assertion.h"
namespace GiNaC {
#endif // ndef NO_NAMESPACE_GINAC
+// This should be obsoleted once <sstream> is widely available.
template<class T>
-string ToString(T const & t)
+std::string ToString(const T & t)
{
char buf[256];
- ostrstream(buf,sizeof(buf)) << t << ends;
+ std::ostrstream(buf,sizeof(buf)) << t << std::ends;
return buf;
}
-/** Exception thrown by classes which provide their own series expansion to
- * signal that ordinary Taylor expansion is safe. */
+/** Exception class thrown by classes which provide their own series expansion
+ * to signal that ordinary Taylor expansion is safe. */
class do_taylor {};
+/** Exception class thrown when a singularity is encountered. */
+class pole_error : public std::domain_error {
+public:
+ explicit pole_error(const std::string& what_arg, int degree);
+ int degree(void) const;
+private:
+ int deg;
+};
+
+// some compilers (e.g. cygwin) define a macro log2, causing confusion
+#ifndef log2
unsigned log2(unsigned n);
+#endif
int compare_pointers(const void * a, const void * b);
}
}
+// Compute the sign of a permutation of a vector of things.
+template <typename T>
+int permutation_sign(std::vector<T> s)
+{
+ if (s.size() < 2)
+ return 0;
+ int sigma = 1;
+ for (typename std::vector<T>::iterator i=s.begin(); i!=s.end()-1; ++i) {
+ for (typename std::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
const ex & _ex_120(void);
const numeric & _num_60(void); // -60
const ex & _ex_60(void);
+const numeric & _num_48(void); // -48
+const ex & _ex_48(void);
const numeric & _num_30(void); // -30
const ex & _ex_30(void);
const numeric & _num_25(void); // -25
const ex & _ex25(void);
const numeric & _num30(void); // 30
const ex & _ex30(void);
+const numeric & _num48(void); // 48
+const ex & _ex48(void);
const numeric & _num60(void); // 60
const ex & _ex60(void);
const numeric & _num120(void); // 120