Nicer output for factorial().
authorJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Thu, 21 Apr 2005 15:38:36 +0000 (15:38 +0000)
committerJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Thu, 21 Apr 2005 15:38:36 +0000 (15:38 +0000)
ginac/inifcns.cpp

index b576ebcf52e39d56fddbf9294830e2575b2e1c7f..ad4e035aaf6d793904e63d641654962508af2b78 100644 (file)
@@ -467,6 +467,17 @@ static ex factorial_eval(const ex & x)
                return factorial(x).hold();
 }
 
+static void factorial_print_dflt_latex(const ex & x, const print_context & c)
+{
+       if (is_exactly_a<symbol>(x) ||
+           is_exactly_a<constant>(x) ||
+               is_exactly_a<function>(x)) {
+               x.print(c); c.s << "!";
+       } else {
+               c.s << "("; x.print(c); c.s << ")!";
+       }
+}
+
 static ex factorial_conjugate(const ex & x)
 {
        return factorial(x);
@@ -474,6 +485,8 @@ static ex factorial_conjugate(const ex & x)
 
 REGISTER_FUNCTION(factorial, eval_func(factorial_eval).
                              evalf_func(factorial_evalf).
+                             print_func<print_dflt>(factorial_print_dflt_latex).
+                             print_func<print_latex>(factorial_print_dflt_latex).
                              conjugate_func(factorial_conjugate));
 
 //////////