From: Richard Kreckel Date: Mon, 20 Dec 1999 22:12:02 +0000 (+0000) Subject: - added a abs() function. haven't you been longing for this? X-Git-Tag: release_0-5-0~83 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=8916b8b2f24b374dfda8a9dd37e6b8d6bf7602c4 - added a abs() function. haven't you been longing for this? --- diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 28cadfb1..dc13eb29 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -41,6 +41,29 @@ 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 ////////// diff --git a/ginac/inifcns.h b/ginac/inifcns.h index fdd33108..6f5f4722 100644 --- a/ginac/inifcns.h +++ b/ginac/inifcns.h @@ -30,6 +30,9 @@ namespace GiNaC { #endif // ndef NO_GINAC_NAMESPACE +/** Absolute value. */ +DECLARE_FUNCTION_1P(abs) + /** Sine. */ DECLARE_FUNCTION_1P(sin)