#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(const T & t)
+std::string ToString(const T & t)
{
- char buf[256];
- ostrstream(buf,sizeof(buf)) << t << ends;
- return buf;
+ char buf[256];
+ 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 {};
-// cygwin defines a macro log2, causing confusion
+/** 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
* (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;
+ // 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;
- }
- GINAC_ASSERT(n<0x80000000U);
+ // overflow? clear highest bit and set lowest bit
+ if (n & 0x80000000U) {
+ n=(n & 0x7FFFFFFFU) | 0x00000001U;
+ }
+ GINAC_ASSERT(n<0x80000000U);
- return n;
+ return n;
}
/** Golden ratio hash function. */
#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);
+ 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"
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:
+ // unfortunately, not ANSI-compliant:
unsigned long long l = n * 0x4f1bbcddLL;
return (l & 0x7fffffffU) ^ (l >> 32);
#else
}
// modified from stl_algo.h: always do com(*first1,*first2) instead of comp(*first2,*first1)
-template <class InputIterator1, class InputIterator2, class OutputIterator,
- class Compare>
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator mymerge(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp) {
- while (first1 != last1 && first2 != last2) {
- if (comp(*first1, *first2)) {
- *result = *first1;
- ++first1;
- }
- else {
- *result = *first2;
- ++first2;
- }
- ++result;
- }
- return copy(first2, last2, copy(first1, last1, result));
+ while (first1 != last1 && first2 != last2) {
+ if (comp(*first1, *first2)) {
+ *result = *first1;
+ ++first1;
+ }
+ else {
+ *result = *first2;
+ ++first2;
+ }
+ ++result;
+ }
+ return copy(first2, last2, copy(first1, last1, result));
}
// like merge(), but three lists with *last2<*first3
InputIterator2 first2, InputIterator2 last2,
InputIterator3 first3, InputIterator3 last3,
OutputIterator result, Compare comp) {
- while (first1 != last1 && first2 != last2) {
- if (comp(*first1, *first2)) {
- *result = *first1;
- ++first1;
- }
- else {
- *result = *first2;
- ++first2;
- }
- ++result;
- }
-
- if (first1==last1) {
- // list1 empty, copy rest of list2, then list3
- return copy(first3, last3, copy(first2, last2, result));
- } else {
- // list2 empty, merge rest of list1 with list3
- return mymerge(first1,last1,first3,last3,result,comp);
- }
+ while (first1 != last1 && first2 != last2) {
+ if (comp(*first1, *first2)) {
+ *result = *first1;
+ ++first1;
+ }
+ else {
+ *result = *first2;
+ ++first2;
+ }
+ ++result;
+ }
+
+ if (first1==last1) {
+ // list1 empty, copy rest of list2, then list3
+ return copy(first3, last3, copy(first2, last2, result));
+ } else {
+ // list2 empty, merge rest of list1 with list3
+ return mymerge(first1,last1,first3,last3,result,comp);
+ }
}
// Compute the sign of a permutation of a vector of things.
template <typename T>
-int permutation_sign(vector<T> s)
+int permutation_sign(std::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;
+ 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
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