These are chat archives for symengine/symengine

14th
Jun 2017
Shikhar Jaiswal
@ShikharJ
Jun 14 2017 16:35
@isuruf I'm trying something like this for converting mpfr_t to mpz_t:
virtual RCP<const Basic> ceiling(const Basic &x) const override
    {
        SYMENGINE_ASSERT(is_a<RealMPFR>(x))
        mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
        mpfr_class t(mpfr_get_prec(x_));
        mpfr_ceil(t.get_mpfr_t(), x_);
        integer_class i;
        return integer(mpfr_get_z(get_mpz_t(i), t.get_mpfr_t(), MPFR_RNDN));
    }
But the result returned is always integer(0)
Isuru Fernando
@isuruf
Jun 14 2017 16:36
virtual RCP<const Basic> ceiling(const Basic &x) const override
    {
        SYMENGINE_ASSERT(is_a<RealMPFR>(x))
        mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
        mpfr_class t(mpfr_get_prec(x_));
        mpfr_ceil(t.get_mpfr_t(), x_);
        integer_class i;
        mpfr_get_z(get_mpz_t(i), t.get_mpfr_t(), MPFR_RNDN);
        return integer(std::move(i));
    }
Simply you can do
virtual RCP<const Basic> ceiling(const Basic &x) const override
{
        SYMENGINE_ASSERT(is_a<RealMPFR>(x))
        mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
        integer_class i;
        mpfr_get_z(get_mpz_t(i), x_, MPFR_RNDU);
        return integer(std::move(i));
}