- added a abs() function. haven't you been longing for this?
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 20 Dec 1999 22:12:02 +0000 (22:12 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 20 Dec 1999 22:12:02 +0000 (22:12 +0000)
ginac/inifcns.cpp
ginac/inifcns.h

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
 //////////
index fdd33108ac199318eae9e2040089086eb6b58936..6f5f47223e3a5a9ea865ee58d789b2c5ef880f56 100644 (file)
@@ -30,6 +30,9 @@
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+/** Absolute value. */
+DECLARE_FUNCTION_1P(abs)
+
 /** Sine. */
 DECLARE_FUNCTION_1P(sin)