diff options
author | jofret | 2008-05-22 09:29:06 +0000 |
---|---|---|
committer | jofret | 2008-05-22 09:29:06 +0000 |
commit | 6d2a9845241e1c1b9774165847f2836b9bc81aee (patch) | |
tree | 67dd7aab503b5ca79d1e7bcd64a8b938da8da687 | |
parent | 2f6a3cf7733f3680dcaea87c8200da19ce843c70 (diff) | |
download | scilab2c-6d2a9845241e1c1b9774165847f2836b9bc81aee.tar.gz scilab2c-6d2a9845241e1c1b9774165847f2836b9bc81aee.tar.bz2 scilab2c-6d2a9845241e1c1b9774165847f2836b9bc81aee.zip |
* Update Algorithm according to Scilab behaviour
* Need some further tests
-rw-r--r-- | src/elementaryFunctions/log/Makefile.am | 5 | ||||
-rw-r--r-- | src/elementaryFunctions/log/Makefile.in | 11 | ||||
-rw-r--r-- | src/elementaryFunctions/log/cloga.c | 20 | ||||
-rw-r--r-- | src/elementaryFunctions/log/clogs.c | 50 | ||||
-rw-r--r-- | src/elementaryFunctions/log/dlogs.c | 20 | ||||
-rw-r--r-- | src/elementaryFunctions/log/sloga.c | 20 | ||||
-rw-r--r-- | src/elementaryFunctions/log/testDoubleLog.c | 22 | ||||
-rw-r--r-- | src/elementaryFunctions/log/testFloatLog.c | 2 | ||||
-rw-r--r-- | src/elementaryFunctions/log/zloga.c | 20 | ||||
-rw-r--r-- | src/elementaryFunctions/log/zlogs.c | 50 |
10 files changed, 171 insertions, 49 deletions
diff --git a/src/elementaryFunctions/log/Makefile.am b/src/elementaryFunctions/log/Makefile.am index bf352aca..34eb6a8f 100644 --- a/src/elementaryFunctions/log/Makefile.am +++ b/src/elementaryFunctions/log/Makefile.am @@ -11,6 +11,7 @@ ## libLog_la_CFLAGS = -I $(top_builddir)/type \ + -I $(top_builddir)/auxiliaryFunctions/includes \ -I $(top_builddir)/elementaryFunctions/includes instdir = $(top_builddir)/lib @@ -39,7 +40,11 @@ check_INCLUDES = -I $(top_builddir)/elementaryFunctions/includes \ check_LDADD = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/type/libFloatComplex.la \ + $(top_builddir)/lib/lapack/libscilapack.la \ $(top_builddir)/elementaryFunctions/log/libLog.la \ + $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \ + $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \ + $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la \ @LIBMATH@ check_PROGRAMS = testFloatLog testDoubleLog diff --git a/src/elementaryFunctions/log/Makefile.in b/src/elementaryFunctions/log/Makefile.in index af7b8ea4..16f27eea 100644 --- a/src/elementaryFunctions/log/Makefile.in +++ b/src/elementaryFunctions/log/Makefile.in @@ -66,7 +66,11 @@ am_testDoubleLog_OBJECTS = testDoubleLog-testDoubleLog.$(OBJEXT) testDoubleLog_OBJECTS = $(am_testDoubleLog_OBJECTS) am__DEPENDENCIES_1 = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/type/libFloatComplex.la \ - $(top_builddir)/elementaryFunctions/log/libLog.la + $(top_builddir)/lib/lapack/libscilapack.la \ + $(top_builddir)/elementaryFunctions/log/libLog.la \ + $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \ + $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \ + $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la testDoubleLog_DEPENDENCIES = $(am__DEPENDENCIES_1) testDoubleLog_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(testDoubleLog_CFLAGS) \ @@ -207,6 +211,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ libLog_la_CFLAGS = -I $(top_builddir)/type \ + -I $(top_builddir)/auxiliaryFunctions/includes \ -I $(top_builddir)/elementaryFunctions/includes instdir = $(top_builddir)/lib @@ -231,7 +236,11 @@ check_INCLUDES = -I $(top_builddir)/elementaryFunctions/includes \ check_LDADD = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/type/libFloatComplex.la \ + $(top_builddir)/lib/lapack/libscilapack.la \ $(top_builddir)/elementaryFunctions/log/libLog.la \ + $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \ + $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \ + $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la \ @LIBMATH@ testFloatLog_SOURCES = testFloatLog.c diff --git a/src/elementaryFunctions/log/cloga.c b/src/elementaryFunctions/log/cloga.c index 533c0dfd..6edf1dd0 100644 --- a/src/elementaryFunctions/log/cloga.c +++ b/src/elementaryFunctions/log/cloga.c @@ -1,14 +1,14 @@ /* -** -*- C -*- -** -** cloga.c -** Made by Bruno JOFRET <bruno.jofret@inria.fr> -** -** Started on Fri Sep 7 10:32:52 2007 bruno -** Last update Mon Oct 22 09:52:01 2007 bruno -** -** 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 + * + */ #include "log.h" diff --git a/src/elementaryFunctions/log/clogs.c b/src/elementaryFunctions/log/clogs.c index 44cf32a7..d402d1d1 100644 --- a/src/elementaryFunctions/log/clogs.c +++ b/src/elementaryFunctions/log/clogs.c @@ -10,9 +10,55 @@ * */ +#include <math.h> #include "log.h" +#include "lapack.h" +#include "log1p.h" +#include "pythag.h" floatComplex clogs(floatComplex in) { - /* FIXME : Implementation */ - return in; + static float sR2 = 1.41421356237309504f; + + float _RealIn = creals(in); + float _ImgIn = cimags(in); + + float _RealOut = 0; + float _ImgOut = 0; + + float RMax = (float) getOverflowThreshold(); + float LInf = sqrtf((float) getUnderflowThreshold()); + float LSup = sqrtf(0.5f * RMax); + + float AbsReal = fabsf(_RealIn); + float AbsImg = fabsf(_ImgIn); + + _ImgOut = atan2f(_ImgIn, _RealIn); + + if(_ImgIn > _RealIn) + {/* switch Real part and Imaginary part */ + float Temp = AbsReal; + AbsReal = AbsImg; + AbsImg = Temp; + } + + if((0.5 <= AbsReal) && (AbsReal <= sR2)) + _RealOut = 0.5f * slog1ps((AbsReal - 1.0f) * (AbsReal + 1.0f) + AbsImg * AbsImg); + else if(LInf < AbsImg && AbsReal < LSup) + _RealOut = 0.5f * slogs(AbsReal * AbsReal + AbsImg * AbsImg); + else if(AbsReal > RMax) + _RealOut = AbsReal; + else + { + float Temp = spythags(AbsReal, AbsImg); + if(Temp <= RMax) + { + _RealOut = slogs(Temp); + } + else /* handle rare spurious overflow with : */ + { + float Temp2 = AbsImg/AbsReal; + _RealOut = slogs(AbsReal) + 0.5f * slog1ps(Temp2 * Temp2); + } + } + return FloatComplex(_RealOut, _ImgOut); } diff --git a/src/elementaryFunctions/log/dlogs.c b/src/elementaryFunctions/log/dlogs.c index de62ba31..c75bef21 100644 --- a/src/elementaryFunctions/log/dlogs.c +++ b/src/elementaryFunctions/log/dlogs.c @@ -1,14 +1,14 @@ /* -** -*- C -*- -** -** dlogs.c -** Made by Bruno JOFRET <bruno.jofret@inria.fr> -** -** Started on Fri Apr 20 14:26:10 2007 jofret -** Last update Fri Apr 20 14:46:45 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 + * + */ #include <math.h> #include "log.h" diff --git a/src/elementaryFunctions/log/sloga.c b/src/elementaryFunctions/log/sloga.c index e6da9104..e6fab861 100644 --- a/src/elementaryFunctions/log/sloga.c +++ b/src/elementaryFunctions/log/sloga.c @@ -1,14 +1,14 @@ /* -** -*- C -*- -** -** sloga.c -** Made by Bruno JOFRET <bruno.jofret@inria.fr> -** -** Started on Fri Sep 7 10:29:01 2007 bruno -** Last update Mon Oct 22 09:51:33 2007 bruno -** -** 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 + * + */ #include "log.h" diff --git a/src/elementaryFunctions/log/testDoubleLog.c b/src/elementaryFunctions/log/testDoubleLog.c index 471d3544..92c803e8 100644 --- a/src/elementaryFunctions/log/testDoubleLog.c +++ b/src/elementaryFunctions/log/testDoubleLog.c @@ -13,17 +13,33 @@ #include "testLog.h" void dlogsTest(void) { - /* FIXME : Implement some test here ... */ + double value = 0; + double maxValue = 1; + double increment = 1e-3; printf(">> Double scalar\n"); - printf("dlogs(0) = %e\n", dlogs(0.0)); + while (value <= maxValue) + { + printf("dlogs(%e) = %e\n", value, dlogs(value)); + value += increment; + } +} + +void zlogsTest(void) { + doubleComplex result; + + printf(">> Complex Double scalar\n"); + result = zlogs(DoubleComplex(-0.1, 0)); + printf("dlogs(-0.1) = %e + %e I \n", zreals(result), zimags(result)); + result = zlogs(DoubleComplex(0, 0)); + printf("dlogs(-0.1) = %e + %e I \n", zreals(result), zimags(result)); } int testLog(void) { printf("\n>>>> Double Logarithm Tests\n"); dlogsTest(); + zlogsTest(); /* FIXME : Implement some test here ... */ /* - zlogsTest(); dlogaTest(); zlogaTest(); */ diff --git a/src/elementaryFunctions/log/testFloatLog.c b/src/elementaryFunctions/log/testFloatLog.c index d47398f9..95a0473b 100644 --- a/src/elementaryFunctions/log/testFloatLog.c +++ b/src/elementaryFunctions/log/testFloatLog.c @@ -15,7 +15,7 @@ void slogsTest(void) { /* FIXME : Implement some test here ... */ printf(">> Float scalar\n"); - printf("slogs(0) = %f\n", slogs(0.0f)); + printf("slogs(0.1) = %f\n", slogs(0.1f)); } int testLog(void) { diff --git a/src/elementaryFunctions/log/zloga.c b/src/elementaryFunctions/log/zloga.c index 8ea92bcd..d4f083d7 100644 --- a/src/elementaryFunctions/log/zloga.c +++ b/src/elementaryFunctions/log/zloga.c @@ -1,14 +1,14 @@ /* -** -*- C -*- -** -** zloga.c -** Made by Bruno JOFRET <bruno.jofret@inria.fr> -** -** Started on Fri Sep 7 10:38:10 2007 bruno -** Last update Mon Oct 22 09:51:22 2007 bruno -** -** 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 + * + */ #include "log.h" diff --git a/src/elementaryFunctions/log/zlogs.c b/src/elementaryFunctions/log/zlogs.c index 4b6dab26..dd0792a9 100644 --- a/src/elementaryFunctions/log/zlogs.c +++ b/src/elementaryFunctions/log/zlogs.c @@ -10,9 +10,55 @@ * */ +#include <math.h> #include "log.h" +#include "lapack.h" +#include "log1p.h" +#include "pythag.h" doubleComplex zlogs(doubleComplex in) { - /* FIXME : Implementation */ - return in; + static double sR2 = 1.41421356237309504; + + double _RealIn = zreals(in); + double _ImgIn = zimags(in); + + double _RealOut = 0; + double _ImgOut = 0; + + double RMax = getOverflowThreshold(); + double LInf = sqrt(getUnderflowThreshold()); + double LSup = sqrt(0.5 * RMax); + + double AbsReal = fabs(_RealIn); + double AbsImg = fabs(_ImgIn); + + _ImgOut = atan2(_ImgIn, _RealIn); + + if(_ImgIn > _RealIn) + {/* switch Real part and Imaginary part */ + double Temp = AbsReal; + AbsReal = AbsImg; + AbsImg = Temp; + } + + if((0.5 <= AbsReal) && (AbsReal <= sR2)) + _RealOut = 0.5 * dlog1ps((AbsReal - 1) * (AbsReal + 1) + AbsImg * AbsImg); + else if(LInf < AbsImg && AbsReal < LSup) + _RealOut = 0.5 * dlogs(AbsReal * AbsReal + AbsImg * AbsImg); + else if(AbsReal > RMax) + _RealOut = AbsReal; + else + { + double Temp = dpythags(AbsReal, AbsImg); + if(Temp <= RMax) + { + _RealOut = dlogs(Temp); + } + else /* handle rare spurious overflow with : */ + { + double Temp2 = AbsImg/AbsReal; + _RealOut = dlogs(AbsReal) + 0.5 * dlog1ps(Temp2 * Temp2); + } + } + return DoubleComplex(_RealOut, _ImgOut); } |