Beispiel #1
0
void StrPrinter::bvisit(const Complex &x)
{
    std::ostringstream s;
    if (x.real_ != 0) {
        s << x.real_;
        // Since Complex is in canonical form, imaginary_ is not 0.
        if (mp_sign(x.imaginary_) == 1) {
            s << " + ";
        } else {
            s << " - ";
        }
        // If imaginary_ is not 1 or -1, print the absolute value
        if (x.imaginary_ != mp_sign(x.imaginary_)) {
            s << mp_abs(x.imaginary_);
            s << "*I";
        } else {
            s << "I";
        }
    } else {
        if (x.imaginary_ != mp_sign(x.imaginary_)) {
            s << x.imaginary_;
            s << "*I";
        } else {
            if (mp_sign(x.imaginary_) == 1) {
                s << "I";
            } else {
                s << "-I";
            }
        }
    }
    str_ = s.str();
}
Beispiel #2
0
RCP<const Number> Integer::pow_negint(const Integer &other) const
{
    RCP<const Number> tmp = powint(*other.neg());
    if (is_a<Integer>(*tmp)) {
        const integer_class &j = down_cast<const Integer &>(*tmp).i;
#if SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP
        // boost::multiprecision::cpp_rational lacks an (int, cpp_int)
        // constructor. must use cpp_rational(cpp_int,cpp_int)
        rational_class q(integer_class(mp_sign(j)), mp_abs(j));
#else
        rational_class q(mp_sign(j), mp_abs(j));
#endif
        return Rational::from_mpq(std::move(q));
    } else {
        throw SymEngineException("powint returned non-integer");
    }
}