log10(x) with x in R will computed with lib c instead of log(x) / log(10) macro 93/15593/4
Antoine ELIAS [Wed, 26 Nov 2014 10:33:59 +0000 (11:33 +0100)]
Change-Id: Idfcee91d14b4151b9e38207711255a02199202e5

scilab/modules/elementary_functions/Makefile.am
scilab/modules/elementary_functions/Makefile.in
scilab/modules/elementary_functions/includes/gw_elementary_functions.h
scilab/modules/elementary_functions/macros/%s_log10.sci [moved from scilab/modules/elementary_functions/macros/log10.sci with 96% similarity]
scilab/modules/elementary_functions/sci_gateway/c/gw_elementary_functions.c
scilab/modules/elementary_functions/sci_gateway/c/sci_log10.c [new file with mode: 0644]
scilab/modules/elementary_functions/sci_gateway/elementary_functions_gateway.xml
scilab/modules/elementary_functions/src/c/core_Import.def
scilab/modules/elementary_functions/src/c/elementary_functions.vcxproj
scilab/modules/elementary_functions/src/c/elementary_functions.vcxproj.filters

index 5ae0594..34689eb 100644 (file)
@@ -266,6 +266,7 @@ sci_gateway/c/sci_tril.c \
 sci_gateway/c/sci_ceil.c \
 sci_gateway/c/sci_imag.c \
 sci_gateway/c/sci_log.c \
+sci_gateway/c/sci_log10.c \
 sci_gateway/c/sci_log1p.c \
 sci_gateway/c/sci_eye.c \
 sci_gateway/c/sci_clean.c \
index 16f8707..ec903c5 100644 (file)
@@ -425,6 +425,7 @@ am__objects_8 =  \
        sci_gateway/c/libscielementary_functions_la-sci_ceil.lo \
        sci_gateway/c/libscielementary_functions_la-sci_imag.lo \
        sci_gateway/c/libscielementary_functions_la-sci_log.lo \
+       sci_gateway/c/libscielementary_functions_la-sci_log10.lo \
        sci_gateway/c/libscielementary_functions_la-sci_log1p.lo \
        sci_gateway/c/libscielementary_functions_la-sci_eye.lo \
        sci_gateway/c/libscielementary_functions_la-sci_clean.lo \
@@ -1124,6 +1125,7 @@ sci_gateway/c/sci_tril.c \
 sci_gateway/c/sci_ceil.c \
 sci_gateway/c/sci_imag.c \
 sci_gateway/c/sci_log.c \
+sci_gateway/c/sci_log10.c \
 sci_gateway/c/sci_log1p.c \
 sci_gateway/c/sci_eye.c \
 sci_gateway/c/sci_clean.c \
@@ -1983,6 +1985,9 @@ sci_gateway/c/libscielementary_functions_la-sci_imag.lo:  \
 sci_gateway/c/libscielementary_functions_la-sci_log.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/c/libscielementary_functions_la-sci_log10.lo:  \
+       sci_gateway/c/$(am__dirstamp) \
+       sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libscielementary_functions_la-sci_log1p.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
@@ -2310,6 +2315,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_isreal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log10.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_maxi.Plo@am__quote@
@@ -2604,6 +2610,13 @@ sci_gateway/c/libscielementary_functions_la-sci_log.lo: sci_gateway/c/sci_log.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscielementary_functions_la-sci_log.lo `test -f 'sci_gateway/c/sci_log.c' || echo '$(srcdir)/'`sci_gateway/c/sci_log.c
 
+sci_gateway/c/libscielementary_functions_la-sci_log10.lo: sci_gateway/c/sci_log10.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscielementary_functions_la-sci_log10.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log10.Tpo -c -o sci_gateway/c/libscielementary_functions_la-sci_log10.lo `test -f 'sci_gateway/c/sci_log10.c' || echo '$(srcdir)/'`sci_gateway/c/sci_log10.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log10.Tpo sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log10.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='sci_gateway/c/sci_log10.c' object='sci_gateway/c/libscielementary_functions_la-sci_log10.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscielementary_functions_la-sci_log10.lo `test -f 'sci_gateway/c/sci_log10.c' || echo '$(srcdir)/'`sci_gateway/c/sci_log10.c
+
 sci_gateway/c/libscielementary_functions_la-sci_log1p.lo: sci_gateway/c/sci_log1p.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscielementary_functions_la-sci_log1p.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Tpo -c -o sci_gateway/c/libscielementary_functions_la-sci_log1p.lo `test -f 'sci_gateway/c/sci_log1p.c' || echo '$(srcdir)/'`sci_gateway/c/sci_log1p.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Tpo sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo
index 438d811..c2f5c14 100644 (file)
@@ -70,6 +70,7 @@ int sci_rat(char *fname, unsigned long fname_len);
 int sci_base2dec(char *fname, unsigned long fname_len);
 int sci_dec2base(char *fname, unsigned long fname_len);
 int C2F(sci_find)(char *fname, unsigned long fname_len);
+int sci_log10(char *fname, unsigned long fname_len);
 #endif /*  __GW_ELEMENTARIES_FUNCTIONS__ */
 /*--------------------------------------------------------------------------*/
 
@@ -8,7 +8,7 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function y = log10(x)
+function y = %s_log10(x)
     [lhs, rhs] = argn(0);
     if rhs == 0 then
         error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"log10", 1));
index a2d81bd..d864463 100644 (file)
@@ -73,7 +73,8 @@ static gw_generic_table Tab[] =
     {sci_rat, "rat"},
     {sci_base2dec, "base2dec"},
     {sci_dec2base, "dec2base"},
-    {C2F(sci_find), "find"}
+    {C2F(sci_find), "find"},
+    {sci_log10, "log10"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_elementary_functions(void)
diff --git a/scilab/modules/elementary_functions/sci_gateway/c/sci_log10.c b/scilab/modules/elementary_functions/sci_gateway/c/sci_log10.c
new file mode 100644 (file)
index 0000000..5cf933c
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007 - INRIA - Jean-Baptiste SILVY
+ * Copyright (C) 2007 - INRIA - Allan CORNET
+ * Copyright (C) 2007 - INRIA - Cong WU
+ *
+ * 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.1-en.txt
+ *
+ */
+
+/*------------------------------------------------------------------------*/
+#include <string.h>
+#include "gw_elementary_functions.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "localization.h"
+#include "msgs.h"
+#include "setieee.h"
+
+/*--------------------------------------------------------------------------*/
+int sci_log10(char *fname, unsigned long fname_len)
+{
+    SciErr sciErr;
+    int i = 0;
+    int complex = 0;
+    int check_ieee = 0;
+
+    int* piAddr = NULL;
+    int iType = 0;
+    int iRows = 0;
+    int iCols = 0;
+    double* pIn = NULL;
+    double* pOutR = NULL;
+    double* pOutI = NULL;
+    double imag = M_PI / log(10.0);
+
+    int iRhs = nbInputArgument(pvApiCtx);
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 1, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
+        return 0;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddr, &iType);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    if (iType != sci_matrix || isVarComplex(pvApiCtx, piAddr))
+    {
+        //manage complex log10 via %s_log macro
+        OverLoad(1);
+        return 0;
+    }
+
+    sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pIn);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    //check values
+    for (i = 0 ; i < iRows * iCols ; ++i)
+    {
+        double d = pIn[i];
+        if (d < 0)
+        {
+            complex = 1;
+        }
+
+        if (d == 0)
+        {
+            check_ieee = 1;
+        }
+    }
+
+    if (check_ieee)
+    {
+        if (getieee() == 0)
+        {
+            SciError(32);
+            return 0;
+        }
+
+        if (getieee() == 1)
+        {
+            Msgs(64, 0);
+        }
+    }
+
+    if (complex)
+    {
+        sciErr = allocComplexMatrixOfDouble(pvApiCtx, iRhs + 1, iRows, iCols, &pOutR, &pOutI);
+        if (sciErr.iErr)
+        {
+            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            return 0;
+        }
+
+        memset(pOutI, 0x00, iRows * iCols * sizeof(double));
+    }
+    else
+    {
+        sciErr = allocMatrixOfDouble(pvApiCtx, iRhs + 1, iRows, iCols, &pOutR);
+        if (sciErr.iErr)
+        {
+            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            return 0;
+        }
+    }
+
+
+    for (i = 0 ; i < iRows * iCols ; ++i)
+    {
+        if (pIn[i] < 0)
+        {
+            pOutR[i] = log10(-pIn[i]);
+            pOutI[i] = imag;
+        }
+        else
+        {
+            pOutR[i] = log10(pIn[i]);
+        }
+    }
+
+    AssignOutputVariable(pvApiCtx, 1) = iRhs + 1;
+    ReturnArguments(pvApiCtx);
+    return 0;
+}
\ No newline at end of file
index 302516f..134bb97 100644 (file)
@@ -87,4 +87,5 @@
     <PRIMITIVE gatewayId="6" primitiveId="53" primitiveName="base2dec" />
     <PRIMITIVE gatewayId="6" primitiveId="54" primitiveName="dec2base" />
     <PRIMITIVE gatewayId="6" primitiveId="55" primitiveName="find" />
+    <PRIMITIVE gatewayId="6" primitiveId="56" primitiveName="log10" />
 </GATEWAY>
index 29707b0..411945e 100644 (file)
@@ -197,6 +197,7 @@ lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MA
     <ClCompile Include="..\..\sci_gateway\c\sci_base2dec.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_dec2base.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_find.c" />
+    <ClCompile Include="..\..\sci_gateway\c\sci_log10.c" />
     <ClCompile Include="cmp.c" />
     <ClCompile Include="convertbase.c" />
     <ClCompile Include="DllmainElementary_functions.c" />
index 94d554b..fd95155 100644 (file)
     <ClCompile Include="..\..\sci_gateway\c\sci_find.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\c\sci_log10.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_elementary_functions.h">