[gnome-calculator/60-split-out-a-backend-library] gcalc: implemented sinh() function
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator/60-split-out-a-backend-library] gcalc: implemented sinh() function
- Date: Sat, 5 Jan 2019 02:34:19 +0000 (UTC)
commit abeb6c4a1ef64a6a6f0d3ccc1cd1b1db7162e52a
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Fri Jan 4 16:33:09 2019 -0600
gcalc: implemented sinh() function
gcalc/gcalc-function-sinh.vala | 54 ++++++++++++++++++++++++++++++++++++++++++
gcalc/meson.build | 1 +
tests/gcalc-solving-basic.vala | 24 +++++++++++++++----
3 files changed, 74 insertions(+), 5 deletions(-)
---
diff --git a/gcalc/gcalc-function-sinh.vala b/gcalc/gcalc-function-sinh.vala
new file mode 100644
index 00000000..fd9dc28b
--- /dev/null
+++ b/gcalc/gcalc-function-sinh.vala
@@ -0,0 +1,54 @@
+/* gcalc-function-sinh.vala
+ *
+ * Copyright (C) 2019 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+public class GCalc.GFunctionSinh : GFunction {
+
+ public GFunctionSinh () {
+ base ("sinh", 1);
+ param_types.add (new GConstant ());
+ }
+
+ public override Expression call () throws GLib.Error
+ {
+ verify_params ();
+ GConstant c = null;
+ var exp = parameters.get_item (0) as Expression;
+ if (exp == null) {
+ throw new FunctionError.INVOCATION_ERROR ("Invalid parameter type. Expected %s",
typeof(Expression).name ());
+ }
+ var ev = exp.solve ();
+ if (ev is ErrorResult) {
+ throw new FunctionError.INVOCATION_ERROR ("Invalid expression: %s", ((ErrorResult) ev).to_string ());
+ }
+ if (ev is Result) {
+ c = ((Result) ev).expression as GConstant;
+ }
+ if (c == null) {
+ throw new FunctionError.INVOCATION_ERROR ("Invalid expression in result");
+ }
+ var p1 = MPC.Complex (1000);
+ p1.set (c.get_complex ());
+ var res = MPC.Complex (1000);
+ res.sinh (p1);
+ var nc = new GConstant.internal_complex (res);
+ return nc as Expression;
+ }
+}
+
diff --git a/gcalc/meson.build b/gcalc/meson.build
index 14380cad..6534ca18 100644
--- a/gcalc/meson.build
+++ b/gcalc/meson.build
@@ -53,6 +53,7 @@ sources = files([
'gcalc-function-exp.vala',
'gcalc-function-log.vala',
'gcalc-function-sin.vala',
+ 'gcalc-function-sinh.vala',
'gcalc-function-sqrt.vala',
'gcalc-function-tan.vala',
'gcalc-error-result.vala',
diff --git a/tests/gcalc-solving-basic.vala b/tests/gcalc-solving-basic.vala
index 1542d18d..764b5729 100644
--- a/tests/gcalc-solving-basic.vala
+++ b/tests/gcalc-solving-basic.vala
@@ -531,7 +531,7 @@ class Tests {
var c2 = f.call () as Constant;
assert (c2 != null);
message (c2.to_string ());
- assert (c2.real () >= 1.0);
+ assert (c2.real () == 1.0);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
}
@@ -545,7 +545,7 @@ class Tests {
var c2 = f.call () as Constant;
assert (c2 != null);
message (c2.to_string ());
- assert (c2.real () >= 0.0);
+ assert (c2.real () == 0.0);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
}
@@ -559,7 +559,7 @@ class Tests {
var c2 = f.call () as Constant;
assert (c2 != null);
message (c2.to_string ());
- assert (c2.real () >= 0.0);
+ assert (c2.real () == 0.0);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
}
@@ -573,7 +573,7 @@ class Tests {
var c2 = f.call () as Constant;
assert (c2 != null);
message (c2.to_string ());
- assert (c2.real () >= 0.0);
+ assert (c2.real () == 0.0);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
}
@@ -587,7 +587,21 @@ class Tests {
var c2 = f.call () as Constant;
assert (c2 != null);
message (c2.to_string ());
- assert (c2.real () >= 0.0);
+ assert (c2.real () == 0.0);
+ } catch (GLib.Error e) {
+ warning ("Error: %s", e.message);
+ }
+ });
+ Test.add_func ("/gcalc/solve/function/sinh",
+ ()=>{
+ try {
+ var c1 = new GConstant.@double (0.0);
+ var f = new GFunctionSinh ();
+ f.parameters.add (c1);
+ var c2 = f.call () as Constant;
+ assert (c2 != null);
+ message (c2.to_string ());
+ assert (c2.real () == 0.0);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]