]> www.ginac.de Git - ginac.git/blobdiff - ginac/numeric.cpp
Alexeis patches for better handling of collect_common_factors.
[ginac.git] / ginac / numeric.cpp
index 18943d3fdfb1f37f5b32506b4a96a27f82328a0a..582bfdcfb5be19229c56e7239217c3a3c0ff93b0 100644 (file)
@@ -92,10 +92,16 @@ numeric::numeric(int i) : basic(&numeric::tinfo_static)
        // emphasizes efficiency.  However, if the integer is small enough
        // we save space and dereferences by using an immediate type.
        // (C.f. <cln/object.h>)
+       // The #if clause prevents compiler warnings on 64bit machines where the
+       // comparision is always true.
+#if cl_value_len >= 32
+       value = cln::cl_I(i);
+#else
        if (i < (1L << (cl_value_len-1)) && i >= -(1L << (cl_value_len-1)))
                value = cln::cl_I(i);
        else
                value = cln::cl_I(static_cast<long>(i));
+#endif
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
@@ -107,10 +113,16 @@ numeric::numeric(unsigned int i) : basic(&numeric::tinfo_static)
        // emphasizes efficiency.  However, if the integer is small enough
        // we save space and dereferences by using an immediate type.
        // (C.f. <cln/object.h>)
+       // The #if clause prevents compiler warnings on 64bit machines where the
+       // comparision is always true.
+#if cl_value_len >= 32
+       value = cln::cl_I(i);
+#else
        if (i < (1UL << (cl_value_len-1)))
                value = cln::cl_I(i);
        else
                value = cln::cl_I(static_cast<unsigned long>(i));
+#endif
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
@@ -603,6 +615,11 @@ bool numeric::info(unsigned inf) const
        return false;
 }
 
+bool numeric::is_polynomial(const ex & var) const
+{
+       return true;
+}
+
 int numeric::degree(const ex & s) const
 {
        return 0;
@@ -682,6 +699,16 @@ ex numeric::conjugate() const
        return numeric(cln::conjugate(this->value));
 }
 
+ex numeric::real_part() const
+{
+       return numeric(cln::realpart(value));
+}
+
+ex numeric::imag_part() const
+{
+       return numeric(cln::imagpart(value));
+}
+
 // protected
 
 int numeric::compare_same_type(const basic &other) const
@@ -931,10 +958,10 @@ const numeric numeric::inverse() const
  *  ignored because the step function is generally considered real but
  *  a numeric may develop a small imaginary part due to rounding errors.
  */
-int numeric::step() const
+numeric numeric::step() const
 {      cln::cl_R r = cln::realpart(value);
        if(cln::zerop(r))
-               return 1;
+               return numeric(1,2);
        if(cln::plusp(r))
                return 1;
        return 0;