changeset 624:1a7dea6fa26b

[project @ 1994-08-17 16:19:40 by jwe]
author jwe
date Wed, 17 Aug 1994 16:19:45 +0000
parents 7caf80625d0e
children 9cdb3844008b
files src/mappers.cc src/octave.cc
diffstat 2 files changed, 79 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/mappers.cc	Wed Aug 17 02:04:04 1994 +0000
+++ b/src/mappers.cc	Wed Aug 17 16:19:45 1994 +0000
@@ -104,6 +104,26 @@
 }
 
 double
+xerf (double x)
+{
+#if defined (HAVE_ERF)
+  return erf (x);
+#else
+  error ("erf(x) not available on this system");
+#endif
+}
+
+double
+xerfc (double x)
+{
+#if defined (HAVE_ERFC)
+  return erfc (x);
+#else
+  error ("erfc(x) not available on this system");
+#endif
+}
+
+double
 xisnan (double x)
 {
 #if defined (HAVE_ISNAN)
@@ -126,6 +146,17 @@
 }
 
 double
+xgamma (double x)
+{
+#if defined (HAVE_LGAMMA)
+  double y = lgamma (x);
+  return signgam * exp (y);
+#else
+  error ("gamma(x) not available on this system");
+#endif
+}
+
+double
 xisinf (double x)
 {
 #if defined (HAVE_ISINF)
@@ -137,6 +168,16 @@
 #endif
 }
 
+double
+xlgamma (double x)
+{
+#if defined (HAVE_LGAMMA)
+  return lgamma (x);
+#else
+  error ("lgamma (x) not available on this system");
+#endif
+}
+
 /*
  * Complex -> double mappers.
  */
@@ -317,6 +358,12 @@
   DEFUN_MAPPER ("cosh", Scosh, 0, 0.0, 0.0, cosh, 0, cosh,
     "cosh (X): compute cosh (X) for each element of X");
 
+  DEFUN_MAPPER ("erf", Serf, 0, 0.0, 0.0, xerf, 0, 0,
+    "erf (X): compute erf (X) for each element of X");
+
+  DEFUN_MAPPER ("erfc", Serfc, 0, 0.0, 0.0, xerfc, 0, 0,
+    "erfc (X): compute erfc (X) for each element of X");
+
   DEFUN_MAPPER ("exp", Sexp, 0, 0.0, 0.0, exp, 0, exp,
     "exp (X): compute exp (X) for each element of X");
 
@@ -329,16 +376,20 @@
   DEFUN_MAPPER ("floor", Sfloor, 0, 0.0, 0.0, floor, 0, floor,
     "floor (X): round elements of X toward -Inf");
 
+  DEFUN_MAPPER ("gamma", Sgamma, 0, 0.0, 0.0, xgamma, 0, 0,
+    "gamma (X): compute gamma (X) for each element of X");
+
   DEFUN_MAPPER ("isinf", Sisinf, 0, 0.0, 0.0, xisinf, xisinf, 0,
     "isinf (X): return 1 for elements of X infinite");
 
   DEFUN_MAPPER ("imag", Simag, 0, 0.0, 0.0, imag, imag, 0,
     "imag (X): return imaginary part for each elements of X");
 
-#ifdef HAVE_ISNAN
   DEFUN_MAPPER ("isnan", Sisnan, 0, 0.0, 0.0, xisnan, xisnan, 0,
     "isnan (X): return 1 where elements of X are NaNs");
-#endif
+
+  DEFUN_MAPPER ("lgamma", Slgamma, 0, 0.0, 0.0, xlgamma, 0, 0,
+    "lgamma (X): compute log gamma (X) for each element of X");
 
   DEFUN_MAPPER ("log", Slog, 1, 0.0, DBL_MAX, log, 0, log,
     "log (X): compute log (X) for each element of X");
--- a/src/octave.cc	Wed Aug 17 02:04:04 1994 +0000
+++ b/src/octave.cc	Wed Aug 17 16:19:45 1994 +0000
@@ -778,32 +778,42 @@
 
   int nargin = args.length ();
 
-  if (nargin == 2 && args(1).is_string ())
+  if (nargin < 2 || nargin > 3)
     {
-      iprocstream cmd (args(1).string_value ());
+      print_usage ("shell_cmd");
+      return retval;
+    }
+
+  tree_constant tc_command = args(1);
+
+  if (tc_command.is_string ())
+    {
+      iprocstream cmd (tc_command.string_value ());
+
+      ostrstream output_buf;
+
       char ch;
-      ostrstream output_buf;
       while (cmd.get (ch))
 	output_buf.put (ch);
+
       output_buf << ends;
+
       int status = cmd.close ();
-      switch (nargout)
+
+      if (nargout > 0 || nargin > 2)
 	{
-	case 1:
-	  maybe_page_output (output_buf);
-	  retval.resize (1);
-	  retval(0) = tree_constant ((double) status);
-	  break;
-	case 2:
-	  retval.resize (2);
-	  retval(0) = tree_constant ((double) status);
-	  retval(1) = tree_constant (output_buf.str ());
-	  break;
-	  break;
+	  char *msg = output_buf.str ();
+
+	  retval(1) = (double) status;
+	  retval(0) = msg;
+
+	  delete [] msg;
 	}
+      else
+	maybe_page_output (output_buf);
     }
   else
-    print_usage ("shell_cmd");
+    error ("shell_cmd: expecting string as first argument");
 
   return retval;
 }