These are chat archives for symengine/symengine

23rd
Nov 2015
Ralf Stephan
@rwst
Nov 23 2015 09:57

Is this inline wrt to SymEngine design planning?

(in class Rational)
    /*! Constructs Rational as n/d, where n, d can be any Integers. If n/d is an
    *   Integer, it will return an Integer instead.
    * */
    static RCP<const Number> from_two_ints(const Integer &n,
            const Integer &d);

My opinion is it does too much. Now, I cannot write a specialized Rational::from_two_ints that returns a RCP<const Rational> because I cannot overload the return value. How to resolve?

Ondřej Čertík
@certik
Nov 23 2015 15:33
@rwst you can refactor this method into a few lower level methods, so that you can do what you need.
I.e. you can write a lower level method that will assume that the two integers are in canonical form. Then a higher level one which will not assume this.
I would also mention that for speed reasons, it's faster to deal with mpq directly, and only convert to Rational at the very end.
Ralf Stephan
@rwst
Nov 23 2015 15:44
@certik I'll rewrite my previous submission to RCP<const Rational> rational(long n, long d);