summaryrefslogtreecommitdiff
path: root/src/elementaryFunctions/tan
diff options
context:
space:
mode:
Diffstat (limited to 'src/elementaryFunctions/tan')
-rw-r--r--src/elementaryFunctions/tan/Makefile.am22
-rw-r--r--src/elementaryFunctions/tan/Makefile.in37
-rw-r--r--src/elementaryFunctions/tan/ctana.c20
-rw-r--r--src/elementaryFunctions/tan/ctans.c38
-rw-r--r--src/elementaryFunctions/tan/dtana.c20
-rw-r--r--src/elementaryFunctions/tan/dtans.c22
-rw-r--r--src/elementaryFunctions/tan/stana.c20
-rw-r--r--src/elementaryFunctions/tan/testDoubleTan.c3
-rw-r--r--src/elementaryFunctions/tan/testTan.h21
-rw-r--r--src/elementaryFunctions/tan/ztana.c20
-rw-r--r--src/elementaryFunctions/tan/ztans.c91
11 files changed, 226 insertions, 88 deletions
diff --git a/src/elementaryFunctions/tan/Makefile.am b/src/elementaryFunctions/tan/Makefile.am
index e5ce210f..6ec27a09 100644
--- a/src/elementaryFunctions/tan/Makefile.am
+++ b/src/elementaryFunctions/tan/Makefile.am
@@ -10,8 +10,9 @@
##
##
-libTan_la_CFLAGS = -I ../../type \
- -I ../includes
+libTan_la_CFLAGS = -I $(top_builddir)/type \
+ -I $(top_builddir)/elementaryFunctions/includes \
+ -I $(top_builddir)/auxiliaryFunctions/includes
instdir = $(top_builddir)/lib
@@ -37,9 +38,20 @@ HEAD = ../includes/tan.h
check_INCLUDES = -I $(top_builddir)/elementaryFunctions/includes \
-I $(top_builddir)/type
-check_LDADD = $(top_builddir)/type/libDoubleComplex.la \
+check_LDADD = $(top_builddir)/lib/lapack/libscilapack.la \
+ $(top_builddir)/type/libDoubleComplex.la \
$(top_builddir)/type/libFloatComplex.la \
$(top_builddir)/elementaryFunctions/tan/libTan.la \
+ $(top_builddir)/elementaryFunctions/sin/libSin.la \
+ $(top_builddir)/elementaryFunctions/cos/libCos.la \
+ $(top_builddir)/elementaryFunctions/sinh/libSinh.la \
+ $(top_builddir)/elementaryFunctions/cosh/libCosh.la \
+ $(top_builddir)/elementaryFunctions/exp/libExp.la \
+ $(top_builddir)/elementaryFunctions/log/libLog.la \
+ $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \
+ $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \
+ $(top_builddir)/auxiliaryFunctions/abs/libAbs.la \
+ $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la \
@LIBMATH@
check_PROGRAMS = testFloatTan testDoubleTan
@@ -50,9 +62,9 @@ TESTS = testFloatTan testDoubleTan
# -*- Tangeant Tests -*-
#
testFloatTan_SOURCES = testFloatTan.c
-testFloatTan_CFLAGS = $(check_INCLUDES)
+testFloatTan_CFLAGS = $(check_INCLUDES) -g
testFloatTan_LDADD = $(check_LDADD)
testDoubleTan_SOURCES = testDoubleTan.c
-testDoubleTan_CFLAGS = $(check_INCLUDES)
+testDoubleTan_CFLAGS = $(check_INCLUDES) -g
testDoubleTan_LDADD = $(check_LDADD)
diff --git a/src/elementaryFunctions/tan/Makefile.in b/src/elementaryFunctions/tan/Makefile.in
index 733b478f..43df58f2 100644
--- a/src/elementaryFunctions/tan/Makefile.in
+++ b/src/elementaryFunctions/tan/Makefile.in
@@ -64,9 +64,20 @@ libTan_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
am_testDoubleTan_OBJECTS = testDoubleTan-testDoubleTan.$(OBJEXT)
testDoubleTan_OBJECTS = $(am_testDoubleTan_OBJECTS)
-am__DEPENDENCIES_1 = $(top_builddir)/type/libDoubleComplex.la \
+am__DEPENDENCIES_1 = $(top_builddir)/lib/lapack/libscilapack.la \
+ $(top_builddir)/type/libDoubleComplex.la \
$(top_builddir)/type/libFloatComplex.la \
- $(top_builddir)/elementaryFunctions/tan/libTan.la
+ $(top_builddir)/elementaryFunctions/tan/libTan.la \
+ $(top_builddir)/elementaryFunctions/sin/libSin.la \
+ $(top_builddir)/elementaryFunctions/cos/libCos.la \
+ $(top_builddir)/elementaryFunctions/sinh/libSinh.la \
+ $(top_builddir)/elementaryFunctions/cosh/libCosh.la \
+ $(top_builddir)/elementaryFunctions/exp/libExp.la \
+ $(top_builddir)/elementaryFunctions/log/libLog.la \
+ $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \
+ $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \
+ $(top_builddir)/auxiliaryFunctions/abs/libAbs.la \
+ $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la
testDoubleTan_DEPENDENCIES = $(am__DEPENDENCIES_1)
testDoubleTan_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(testDoubleTan_CFLAGS) \
@@ -206,8 +217,9 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-libTan_la_CFLAGS = -I ../../type \
- -I ../includes
+libTan_la_CFLAGS = -I $(top_builddir)/type \
+ -I $(top_builddir)/elementaryFunctions/includes \
+ -I $(top_builddir)/auxiliaryFunctions/includes
instdir = $(top_builddir)/lib
pkglib_LTLIBRARIES = libTan.la
@@ -229,9 +241,20 @@ HEAD = ../includes/tan.h
check_INCLUDES = -I $(top_builddir)/elementaryFunctions/includes \
-I $(top_builddir)/type
-check_LDADD = $(top_builddir)/type/libDoubleComplex.la \
+check_LDADD = $(top_builddir)/lib/lapack/libscilapack.la \
+ $(top_builddir)/type/libDoubleComplex.la \
$(top_builddir)/type/libFloatComplex.la \
$(top_builddir)/elementaryFunctions/tan/libTan.la \
+ $(top_builddir)/elementaryFunctions/sin/libSin.la \
+ $(top_builddir)/elementaryFunctions/cos/libCos.la \
+ $(top_builddir)/elementaryFunctions/sinh/libSinh.la \
+ $(top_builddir)/elementaryFunctions/cosh/libCosh.la \
+ $(top_builddir)/elementaryFunctions/exp/libExp.la \
+ $(top_builddir)/elementaryFunctions/log/libLog.la \
+ $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \
+ $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \
+ $(top_builddir)/auxiliaryFunctions/abs/libAbs.la \
+ $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la \
@LIBMATH@
@@ -239,10 +262,10 @@ check_LDADD = $(top_builddir)/type/libDoubleComplex.la \
# -*- Tangeant Tests -*-
#
testFloatTan_SOURCES = testFloatTan.c
-testFloatTan_CFLAGS = $(check_INCLUDES)
+testFloatTan_CFLAGS = $(check_INCLUDES) -g
testFloatTan_LDADD = $(check_LDADD)
testDoubleTan_SOURCES = testDoubleTan.c
-testDoubleTan_CFLAGS = $(check_INCLUDES)
+testDoubleTan_CFLAGS = $(check_INCLUDES) -g
testDoubleTan_LDADD = $(check_LDADD)
all: all-am
diff --git a/src/elementaryFunctions/tan/ctana.c b/src/elementaryFunctions/tan/ctana.c
index 339dda27..731407ee 100644
--- a/src/elementaryFunctions/tan/ctana.c
+++ b/src/elementaryFunctions/tan/ctana.c
@@ -1,14 +1,14 @@
/*
-** -*- C -*-
-**
-** ctana.c
-** Made by Bruno JOFRET <bruno.jofret@inria.fr>
-**
-** Started on Thu Dec 7 14:54:24 2006 jofret
-** Last update Mon Oct 22 09:49:00 2007 bruno
-**
-** Copyright INRIA 2006
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#include "tan.h"
diff --git a/src/elementaryFunctions/tan/ctans.c b/src/elementaryFunctions/tan/ctans.c
index ee3396f1..9a6bd8c1 100644
--- a/src/elementaryFunctions/tan/ctans.c
+++ b/src/elementaryFunctions/tan/ctans.c
@@ -10,22 +10,36 @@
*
*/
+#include <math.h>
+#include "lapack.h"
#include "tan.h"
-/*
- #include "log.h"
-*/
#include "sqrt.h"
-/*
- #include "lapack.h"
-*/
+#include "cos.h"
+#include "sinh.h"
+#include "sin.h"
+#include "log.h"
+#include "abs.h"
+
+#define localSign(x) x >= 0 ? 1.0f : -1.0f
floatComplex ctans(floatComplex z) {
- /*
+ float Temp = 0.0f;
+ float Lim = 1.0f + slogs(2.0f / ssqrts((float) getRelativeMachinePrecision()));
+ float RealIn = creals(z);
+ float ImagIn = cimags(z);
+ float RealOut = 0.0f;
+ float ImagOut = 0.0f;
- double out_real = 0;
- double out_imag = 0;
- double L = 1 + dlogs(2 / dsqrts(dlamch('e', 1)));
- */
+ Temp = powf(scoss(RealIn), 2.0f) + powf(ssinhs(ImagIn), 2.0f);
+ RealOut = 0.5f * ssins(2 * RealIn) / Temp;
+ if(sabss(ImagIn) < Lim)
+ {
+ ImagOut = 0.5f * ssinhs(2.0f * ImagIn) / Temp;
+ }
+ else
+ {
+ ImagOut = localSign(ImagIn);
+ }
- return z;
+ return FloatComplex(RealOut, ImagOut);
}
diff --git a/src/elementaryFunctions/tan/dtana.c b/src/elementaryFunctions/tan/dtana.c
index d74dd3bf..8a5f4f68 100644
--- a/src/elementaryFunctions/tan/dtana.c
+++ b/src/elementaryFunctions/tan/dtana.c
@@ -1,14 +1,14 @@
/*
-** -*- C -*-
-**
-** dtana.c
-** Made by Bruno JOFRET <bruno.jofret@inria.fr>
-**
-** Started on Thu Dec 7 14:54:56 2006 jofret
-** Last update Mon Oct 22 09:48:46 2007 bruno
-**
-** Copyright INRIA 2006
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#include "tan.h"
diff --git a/src/elementaryFunctions/tan/dtans.c b/src/elementaryFunctions/tan/dtans.c
index 0391e146..888a2dae 100644
--- a/src/elementaryFunctions/tan/dtans.c
+++ b/src/elementaryFunctions/tan/dtans.c
@@ -1,18 +1,18 @@
/*
-** -*- C -*-
-**
-** dtans.c
-** Made by Bruno JOFRET <bruno.jofret@inria.fr>
-**
-** Started on Thu Dec 7 12:02:41 2006 jofret
-** Last update Fri Apr 20 14:40:21 2007 jofret
-**
-** Copyright INRIA 2006
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#include <math.h>
#include "tan.h"
double dtans(double x) {
- return (tan(x));
+ return tan(x);
}
diff --git a/src/elementaryFunctions/tan/stana.c b/src/elementaryFunctions/tan/stana.c
index 95cc287e..c228afe1 100644
--- a/src/elementaryFunctions/tan/stana.c
+++ b/src/elementaryFunctions/tan/stana.c
@@ -1,14 +1,14 @@
/*
-** -*- C -*-
-**
-** stana.c
-** Made by Bruno JOFRET <bruno.jofret@inria.fr>
-**
-** Started on Thu Dec 7 16:03:27 2006 jofret
-** Last update Mon Oct 22 09:46:19 2007 bruno
-**
-** Copyright INRIA 2006
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#include "tan.h"
diff --git a/src/elementaryFunctions/tan/testDoubleTan.c b/src/elementaryFunctions/tan/testDoubleTan.c
index 970ef0c7..74be72e9 100644
--- a/src/elementaryFunctions/tan/testDoubleTan.c
+++ b/src/elementaryFunctions/tan/testDoubleTan.c
@@ -10,8 +10,11 @@
*
*/
+#include <math.h>
#include "testTan.h"
+double dtans(double);
+
void dtansTest() {
printf(">> Double scalar\n");
printf("dtans(0) = %e\n", dtans(0.0));
diff --git a/src/elementaryFunctions/tan/testTan.h b/src/elementaryFunctions/tan/testTan.h
index 1e1cac62..b213f105 100644
--- a/src/elementaryFunctions/tan/testTan.h
+++ b/src/elementaryFunctions/tan/testTan.h
@@ -1,20 +1,21 @@
/*
-** -*- C -*-
-**
-** testTan.h
-** Made by Bruno JOFRET <bruno.jofret@inria.fr>
-**
-** Started on Fri Mar 30 11:22:40 2007 jofret
-** Last update Fri Mar 30 12:05:07 2007 jofret
-**
-** Copyright INRIA 2007
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#ifndef _TESTTAN_H_
#define _TESTTAN_H_
#include <stdio.h>
#include <assert.h>
+
#include "tan.h"
#include "constant.h"
diff --git a/src/elementaryFunctions/tan/ztana.c b/src/elementaryFunctions/tan/ztana.c
index ef296d6a..6634d422 100644
--- a/src/elementaryFunctions/tan/ztana.c
+++ b/src/elementaryFunctions/tan/ztana.c
@@ -1,14 +1,14 @@
/*
-** -*- C -*-
-**
-** ztana.c
-** Made by Bruno JOFRET <bruno.jofret@inria.fr>
-**
-** Started on Thu Dec 7 16:12:02 2006 jofret
-** Last update Mon Oct 22 09:46:07 2007 bruno
-**
-** Copyright INRIA 2006
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#include "tan.h"
diff --git a/src/elementaryFunctions/tan/ztans.c b/src/elementaryFunctions/tan/ztans.c
index 0065ea0d..ff130dcc 100644
--- a/src/elementaryFunctions/tan/ztans.c
+++ b/src/elementaryFunctions/tan/ztans.c
@@ -1,6 +1,6 @@
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
+ * Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
@@ -10,9 +10,94 @@
*
*/
+/*
+ ALGORITHM
+ based on the formula :
+
+ 0.5 sin(2 xr) + i 0.5 sinh(2 xi)
+ tan(xr + i xi) = ---------------------------------
+ cos(xr)^2 + sinh(xi)^2
+
+ noting d = cos(xr)^2 + sinh(xi)^2, we have :
+
+ yr = 0.5 * sin(2 * xr) / d (1)
+
+ yi = 0.5 * sinh(2 * xi) / d (2)
+
+ to avoid spurious overflows in computing yi with
+ formula (2) (which results in NaN for yi)
+ we use also the following formula :
+
+ yi = sign(xi) when |xi| > LIM (3)
+
+ Explanations for (3) :
+
+ we have d = sinh(xi)^2 ( 1 + (cos(xr)/sinh(xi))^2 ),
+ so when :
+
+ (cos(xr)/sinh(xi))^2 < epsm ( epsm = max relative error
+ for coding a real in a f.p.
+ number set F(b,p,emin,emax)
+ epsm = 0.5 b^(1-p) )
+ which is forced when :
+
+ 1/sinh(xi)^2 < epsm (4)
+ <=> |xi| > asinh(1/sqrt(epsm)) (= 19.06... in ieee 754 double)
+
+ sinh(xi)^2 is a good approximation for d (relative to the f.p.
+ arithmetic used) and then yr may be approximate with :
+
+ yr = cosh(xi)/sinh(xi)
+ = sign(xi) (1 + exp(-2 |xi|))/(1 - exp(-2|xi|))
+ = sign(xi) (1 + 2 u + 2 u^2 + 2 u^3 + ...)
+
+ with u = exp(-2 |xi|)). Now when :
+
+ 2 exp(-2|xi|) < epsm (2)
+ <=> |xi| > 0.5 * log(2/epsm) (= 18.71... in ieee 754 double)
+
+ sign(xi) is a good approximation for yr.
+
+ Constraint (1) is stronger than (2) and we take finaly
+
+ LIM = 1 + log(2/sqrt(epsm))
+
+ (log(2/sqrt(epsm)) being very near asinh(1/sqrt(epsm))
+
+AUTHOR
+ Bruno Pincon <Bruno.Pincon@iecn.u-nancy.fr>
+*/
+
+#include <math.h>
+#include "lapack.h"
#include "tan.h"
+#include "sqrt.h"
+#include "cos.h"
+#include "sinh.h"
+#include "sin.h"
+#include "log.h"
+#include "abs.h"
+
+#define localSign(x) x >= 0 ? 1.0 : -1.0
doubleComplex ztans(doubleComplex z) {
- /* FIXME: Dummy... */
- return z;
+ double Temp = 0;
+ double Lim = 1 + dlogs(2.0 / dsqrts( getRelativeMachinePrecision()));
+ double RealIn = zreals(z);
+ double ImagIn = zimags(z);
+ double RealOut = 0;
+ double ImagOut = 0;
+
+ Temp = pow(dcoss(RealIn), 2) + pow(dsinhs(ImagIn), 2);
+ RealOut = 0.5 * dsins(2 * RealIn) / Temp;
+ if(dabss(ImagIn) < Lim)
+ {
+ ImagOut = 0.5 * dsinhs(2 * ImagIn) / Temp;
+ }
+ else
+ {
+ ImagOut = localSign(ImagIn);
+ }
+
+ return DoubleComplex(RealOut, ImagOut);
}