]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns.cpp
- added a abs() function. haven't you been longing for this?
[ginac.git] / ginac / inifcns.cpp
index 28cadfb174ecf16680dd18d37d9af8ad0f1af1d2..dc13eb2929f8345ffc99c1cf5483f6bc35abfb3d 100644 (file)
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+//////////
+// absolute value
+//////////
+
+static ex abs_evalf(ex const & x)
+{
+    BEGIN_TYPECHECK
+        TYPECHECK(x,numeric)
+    END_TYPECHECK(abs(x))
+    
+    return abs(ex_to_numeric(x));
+}
+
+static ex abs_eval(ex const & x)
+{
+    if (is_ex_exactly_of_type(x, numeric))
+        return abs(ex_to_numeric(x));
+    else
+        return abs(x).hold();
+}
+
+REGISTER_FUNCTION(abs, abs_eval, abs_evalf, NULL, NULL);
+
 //////////
 // dilogarithm
 //////////