[gcalctool] Support complex trigonometry
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Support complex trigonometry
- Date: Thu, 27 May 2010 06:58:42 +0000 (UTC)
commit 740ec04af62751f5b486dba9e2cefbdea8f747f8
Author: Robert Ancell <robert ancell gmail com>
Date: Thu May 27 16:58:27 2010 +1000
Support complex trigonometry
NEWS | 4 +++
src/mp-trigonometric.c | 57 ++++++++++++++++++++++++++++++++++++++++++++---
src/unittest.c | 2 +
3 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 34d95df..2355f8d 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@
Overview of changes in gcalctool 5.31.2
+ * Support complex trigonometry
+
+Overview of changes in gcalctool 5.31.2
+
* Replace backspace button with undo button
* Remove memory buttons from basic mode (too complex)
diff --git a/src/mp-trigonometric.c b/src/mp-trigonometric.c
index aef3b84..60bb3ca 100644
--- a/src/mp-trigonometric.c
+++ b/src/mp-trigonometric.c
@@ -154,8 +154,8 @@ mpsin1(const MPNumber *x, MPNumber *z, int do_sin)
}
-void
-mp_sin(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
+static void
+mp_sin_real(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
{
int xs;
MPNumber x_radians;
@@ -223,8 +223,8 @@ mp_sin(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
}
-void
-mp_cos(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
+static void
+mp_cos_real(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
{
/* cos(0) = 1 */
if (mp_is_zero(x)) {
@@ -251,6 +251,55 @@ mp_cos(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
void
+mp_sin(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
+{
+ if (mp_is_complex(x)) {
+ MPNumber x_real, x_im, z_real, z_im, t;
+
+ mp_real_component(x, &x_real);
+ mp_imaginary_component(x, &x_im);
+
+ mp_sin_real(&x_real, unit, &z_real);
+ mp_cosh(&x_im, &t);
+ mp_multiply(&z_real, &t, &z_real);
+
+ mp_cos_real(&x_real, unit, &z_im);
+ mp_sinh(&x_im, &t);
+ mp_multiply(&z_im, &t, &z_im);
+
+ mp_set_from_complex(&z_real, &z_im, z);
+ }
+ else
+ mp_sin_real(x, unit, z);
+}
+
+
+void
+mp_cos(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
+{
+ if (mp_is_complex(x)) {
+ MPNumber x_real, x_im, z_real, z_im, t;
+
+ mp_real_component(x, &x_real);
+ mp_imaginary_component(x, &x_im);
+
+ mp_cos_real(&x_real, unit, &z_real);
+ mp_cosh(&x_im, &t);
+ mp_multiply(&z_real, &t, &z_real);
+
+ mp_sin_real(&x_real, unit, &z_im);
+ mp_sinh(&x_im, &t);
+ mp_multiply(&z_im, &t, &z_im);
+ mp_invert_sign(&z_im, &z_im);
+
+ mp_set_from_complex(&z_real, &z_im, z);
+ }
+ else
+ mp_cos_real(x, unit, z);
+}
+
+
+void
mp_tan(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
{
MPNumber cos_x, sin_x;
diff --git a/src/unittest.c b/src/unittest.c
index ec2575b..65a662d 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -534,6 +534,8 @@ test_equations()
test("e^iÏ?", "â??1", 0);
test("log (â??10) â?? (1 + Ï?i÷ln(10))", "0", 0);
test("ln (â??e) â?? (1 + Ï?i)", "0", 0);
+ test("sin(iÏ?÷4) â?? iÃ?sinh(Ï?÷4)", "0", 0);
+ test("cos(iÏ?÷4) â?? cosh(Ï?÷4)", "0", 0);
/* Boolean */
test("0 and 0", "0", 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]