[gnumeric] Functions: implement COT and ACOT.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] Functions: implement COT and ACOT.
- Date: Tue, 9 Jun 2009 13:51:32 -0400 (EDT)
commit 9134889a5fe917ebd99ef8be4f2cf981a0e3a0cb
Author: Morten Welinder <terra gnome org>
Date: Tue Jun 9 13:51:02 2009 -0400
Functions: implement COT and ACOT.
---
ChangeLog | 2 +
NEWS | 1 +
plugins/fn-math/ChangeLog | 4 +++
plugins/fn-math/functions.c | 44 ++++++++++++++++++++++++++++++++++++++--
plugins/fn-math/plugin.xml.in | 2 +
src/mathfunc.c | 27 +++++++++++++++++++++++++
src/mathfunc.h | 3 ++
7 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e6bbfa7..29fce41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2009-06-09 Morten Welinder <terra gnome org>
+ * src/mathfunc.c (gnm_cot, gnm_acot): New functions.
+
* src/sheet-style.c (sheet_style_find): Keep style hash entries
unique. Fixes #585178.
diff --git a/NEWS b/NEWS
index de09941..dcb10fa 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ Morten:
* Fix array editing criticals. [#584746]
* Fix style problems with operator.xls. [#585178]
* Fix NPER problems.
+ * Implement new functions COT and ACOT. [#585270]
--------------------------------------------------------------------------
Gnumeric 1.9.8
diff --git a/plugins/fn-math/ChangeLog b/plugins/fn-math/ChangeLog
index 74c50dd..bfc9648 100644
--- a/plugins/fn-math/ChangeLog
+++ b/plugins/fn-math/ChangeLog
@@ -1,3 +1,7 @@
+2009-06-09 Morten Welinder <terra gnome org>
+
+ * functions.c (gnumeric_acot, gnumeric_cot): New functions.
+
2009-05-23 Morten Welinder <terra gnome org>
* Release 1.9.8
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index 1fd1abc..5f026d0 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -312,6 +312,22 @@ gnumeric_acosh (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
/***************************************************************************/
+static GnmFuncHelp const help_acot[] = {
+ { GNM_FUNC_HELP_NAME, F_("ACOT:inverse cotangent of a value")},
+ { GNM_FUNC_HELP_ARG, F_("x:value")},
+ { GNM_FUNC_HELP_EXAMPLES, F_("ACOT(0.2) equals 1.3734") },
+ { GNM_FUNC_HELP_SEEALSO, "COT,TAN"},
+ { GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_acot (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+ return value_new_float (gnm_acot (value_get_as_float (argv[0])));
+}
+
+/***************************************************************************/
+
static GnmFuncHelp const help_asin[] = {
{ GNM_FUNC_HELP_OLD,
F_("@FUNCTION=ASIN\n"
@@ -802,6 +818,22 @@ gnumeric_cosh (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
/***************************************************************************/
+static GnmFuncHelp const help_cot[] = {
+ { GNM_FUNC_HELP_NAME, F_("COT:cotangent of a value")},
+ { GNM_FUNC_HELP_ARG, F_("x:value")},
+ { GNM_FUNC_HELP_EXAMPLES, F_("COT(0.12) equals 8.293") },
+ { GNM_FUNC_HELP_SEEALSO, "TAN,ACOT"},
+ { GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_cot (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+ return value_new_float (gnm_cot (value_get_as_float (argv[0])));
+}
+
+/***************************************************************************/
+
static GnmFuncHelp const help_degrees[] = {
{ GNM_FUNC_HELP_OLD,
F_("@FUNCTION=DEGREES\n"
@@ -3106,6 +3138,9 @@ GnmFuncDescriptor const math_functions[] = {
{ "acosh", "f", N_("number"), help_acosh,
gnumeric_acosh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
+ { "acot", "f", N_("number"), help_acot,
+ gnumeric_acot, NULL, NULL, NULL, NULL,
+ GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "asin", "f", N_("number"), help_asin,
gnumeric_asin, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
@@ -3121,18 +3156,21 @@ GnmFuncDescriptor const math_functions[] = {
{ "atan2", "ff", N_("xnum,ynum"), help_atan2,
gnumeric_atan2, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
- { "cos", "f", N_("number"), help_cos,
- gnumeric_cos, NULL, NULL, NULL, NULL,
- GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "beta", "ff", N_("a,b"), help_beta,
gnumeric_beta, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "betaln", "ff", N_("a,b"), help_betaln,
gnumeric_betaln, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+ { "cos", "f", N_("number"), help_cos,
+ gnumeric_cos, NULL, NULL, NULL, NULL,
+ GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "cosh", "f", N_("number"), help_cosh,
gnumeric_cosh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
+ { "cot", "f", N_("number"), help_cot,
+ gnumeric_cot, NULL, NULL, NULL, NULL,
+ GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
/* MS Excel puts this in statistical */
{ "countif", "rS", N_("range,criteria"), help_countif,
diff --git a/plugins/fn-math/plugin.xml.in b/plugins/fn-math/plugin.xml.in
index e520d70..ad519bb 100644
--- a/plugins/fn-math/plugin.xml.in
+++ b/plugins/fn-math/plugin.xml.in
@@ -14,6 +14,7 @@
<function name="abs"/>
<function name="acos"/>
<function name="acosh"/>
+ <function name="acot"/>
<function name="asin"/>
<function name="asinh"/>
<function name="atan"/>
@@ -23,6 +24,7 @@
<function name="betaln"/>
<function name="cos"/>
<function name="cosh"/>
+ <function name="cot"/>
<function name="countif"/>
<function name="ceil"/>
<function name="ceiling"/>
diff --git a/src/mathfunc.c b/src/mathfunc.c
index 623c0ba..69fdfea 100644
--- a/src/mathfunc.c
+++ b/src/mathfunc.c
@@ -105,6 +105,33 @@ mathfunc_init (void)
/* Nothing, for the time being. */
}
+gnm_float
+gnm_cot (gnm_float x)
+{
+ gnm_float s = gnm_sin (x);
+ gnm_float c = gnm_cos (x);
+
+ if (s == 0)
+ return gnm_nan;
+ else
+ return c / s;
+}
+
+gnm_float
+gnm_acot (gnm_float x)
+{
+ if (gnm_finite (x)) {
+ if (x == 0)
+ return M_PIgnum / 2;
+ return gnm_atan (1 / x);
+ } else {
+ /* +inf -> +0 */
+ /* -Inf -> -0 */
+ /* +-NaN -> +-NaN */
+ return 1 / x;
+ }
+}
+
/* ------------------------------------------------------------------------- */
/* --- BEGIN MAGIC R SOURCE MARKER --- */
diff --git a/src/mathfunc.h b/src/mathfunc.h
index 04d8d80..0c8d644 100644
--- a/src/mathfunc.h
+++ b/src/mathfunc.h
@@ -34,6 +34,9 @@ gnm_float logfbit (gnm_float x);
gnm_float logspace_add (gnm_float logx, gnm_float logy);
gnm_float logspace_sub (gnm_float logx, gnm_float logy);
+gnm_float gnm_cot (gnm_float x);
+gnm_float gnm_acot (gnm_float x);
+
gnm_float beta (gnm_float a, gnm_float b);
gnm_float lbeta3 (gnm_float a, gnm_float b, int *sign);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]