mappers.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1993-2012 John W. Eaton
00004 Copyright (C) 2009-2010 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include <cctype>
00029 #include <cfloat>
00030 
00031 #include "lo-ieee.h"
00032 #include "lo-specfun.h"
00033 #include "lo-mappers.h"
00034 
00035 #include "defun.h"
00036 #include "error.h"
00037 #include "variables.h"
00038 
00039 DEFUN (abs, args, ,
00040     "-*- texinfo -*-\n\
00041 @deftypefn {Mapping Function} {} abs (@var{z})\n\
00042 Compute the magnitude of @var{z}, defined as\n\
00043 @tex\n\
00044 $|z| = \\sqrt{x^2 + y^2}$.\n\
00045 @end tex\n\
00046 @ifnottex\n\
00047 |@var{z}| = @code{sqrt (x^2 + y^2)}.\n\
00048 @end ifnottex\n\
00049 \n\
00050 For example:\n\
00051 \n\
00052 @example\n\
00053 @group\n\
00054 abs (3 + 4i)\n\
00055      @result{} 5\n\
00056 @end group\n\
00057 @end example\n\
00058 @end deftypefn")
00059 {
00060   octave_value retval;
00061   if (args.length () == 1)
00062     retval = args(0).abs ();
00063   else
00064     print_usage ();
00065 
00066   return retval;
00067 }
00068 
00069 /*
00070 %!assert (abs (1), 1)
00071 %!assert (abs (-3.5), 3.5)
00072 %!assert (abs (3+4i), 5)
00073 %!assert (abs (3-4i), 5)
00074 %!assert (abs ([1.1, 3i; 3+4i, -3-4i]), [1.1, 3; 5, 5])
00075 
00076 %!assert (abs (single (1)), single (1))
00077 %!assert (abs (single (-3.5)), single (3.5))
00078 %!assert (abs (single (3+4i)), single (5))
00079 %!assert (abs (single (3-4i)), single (5))
00080 %!assert (abs (single ([1.1, 3i; 3+4i, -3-4i])), single ([1.1, 3; 5, 5]))
00081 
00082 %!error abs ()
00083 %!error abs (1, 2)
00084 */
00085 
00086 DEFUN (acos, args, ,
00087     "-*- texinfo -*-\n\
00088 @deftypefn {Mapping Function} {} acos (@var{x})\n\
00089 Compute the inverse cosine in radians for each element of @var{x}.\n\
00090 @seealso{cos, acosd}\n\
00091 @end deftypefn")
00092 {
00093   octave_value retval;
00094   if (args.length () == 1)
00095     retval = args(0).acos ();
00096   else
00097     print_usage ();
00098 
00099   return retval;
00100 }
00101 
00102 /*
00103 %!shared rt2, rt3
00104 %! rt2 = sqrt (2);
00105 %! rt3 = sqrt (3);
00106 
00107 %!test
00108 %! x = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
00109 %! v = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
00110 %! assert (acos (x), v, sqrt (eps));
00111 
00112 %!test
00113 %! x = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
00114 %! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
00115 %! assert (acos (x), v, sqrt (eps ('single')));
00116 
00117 %!error acos ()
00118 %!error acos (1, 2)
00119 */
00120 
00121 DEFUN (acosh, args, ,
00122     "-*- texinfo -*-\n\
00123 @deftypefn {Mapping Function} {} acosh (@var{x})\n\
00124 Compute the inverse hyperbolic cosine for each element of @var{x}.\n\
00125 @seealso{cosh}\n\
00126 @end deftypefn")
00127 {
00128   octave_value retval;
00129   if (args.length () == 1)
00130     retval = args(0).acosh ();
00131   else
00132     print_usage ();
00133 
00134   return retval;
00135 }
00136 
00137 /*
00138 %!test
00139 %! x = [1, 0, -1, 0];
00140 %! v = [0, pi/2*i, pi*i, pi/2*i];
00141 %! assert (acosh (x), v, sqrt (eps));
00142 
00143 %!test
00144 %! x = single ([1, 0, -1, 0]);
00145 %! v = single ([0, pi/2*i, pi*i, pi/2*i]);
00146 %! assert (acosh (x), v, sqrt (eps ('single')));
00147 
00148 %!error acosh ()
00149 %!error acosh (1, 2)
00150 */
00151 
00152 DEFUN (angle, args, ,
00153     "-*- texinfo -*-\n\
00154 @deftypefn {Mapping Function} {} angle (@var{z})\n\
00155 See arg.\n\
00156 @end deftypefn")
00157 {
00158   octave_value retval;
00159   if (args.length () == 1)
00160     retval = args(0).arg ();
00161   else
00162     print_usage ();
00163 
00164   return retval;
00165 }
00166 
00167 DEFUN (arg, args, ,
00168     "-*- texinfo -*-\n\
00169 @deftypefn  {Mapping Function} {} arg (@var{z})\n\
00170 @deftypefnx {Mapping Function} {} angle (@var{z})\n\
00171 Compute the argument of @var{z}, defined as,\n\
00172 @tex\n\
00173 $\\theta = atan2 (y, x),$\n\
00174 @end tex\n\
00175 @ifnottex\n\
00176 @var{theta} = @code{atan2 (@var{y}, @var{x})},\n\
00177 @end ifnottex\n\
00178 in radians.\n\
00179 \n\
00180 For example:\n\
00181 \n\
00182 @example\n\
00183 @group\n\
00184 arg (3 + 4i)\n\
00185      @result{} 0.92730\n\
00186 @end group\n\
00187 @end example\n\
00188 @end deftypefn")
00189 {
00190   octave_value retval;
00191   if (args.length () == 1)
00192     retval = args(0).arg ();
00193   else
00194     print_usage ();
00195 
00196   return retval;
00197 }
00198 
00199 /*
00200 %!assert (arg (1), 0)
00201 %!assert (arg (i), pi/2)
00202 %!assert (arg (-1), pi)
00203 %!assert (arg (-i), -pi/2)
00204 %!assert (arg ([1, i; -1, -i]), [0, pi/2; pi, -pi/2])
00205 
00206 %!assert (arg (single (1)), single (0))
00207 %!assert (arg (single (i)), single (pi/2))
00208 %!test
00209 %! if (ismac ())
00210 %!   ## Avoid failing for a MacOS feature
00211 %!   assert (arg (single (-1)), single (pi), 2*eps (single (1)));
00212 %! else
00213 %!   assert (arg (single (-1)), single (pi));
00214 %! endif
00215 %!assert (arg (single (-i)), single (-pi/2))
00216 %!assert (arg (single ([1, i; -1, -i])), single ([0, pi/2; pi, -pi/2]), 2e1*eps ('single'))
00217 
00218 %!error arg ()
00219 %!error arg (1, 2)
00220 */
00221 
00222 DEFUN (asin, args, ,
00223     "-*- texinfo -*-\n\
00224 @deftypefn {Mapping Function} {} asin (@var{x})\n\
00225 Compute the inverse sine in radians for each element of @var{x}.\n\
00226 @seealso{sin, asind}\n\
00227 @end deftypefn")
00228 {
00229   octave_value retval;
00230   if (args.length () == 1)
00231     retval = args(0).asin ();
00232   else
00233     print_usage ();
00234 
00235   return retval;
00236 }
00237 
00238 /*
00239 %!test
00240 %! rt2 = sqrt (2);
00241 %! rt3 = sqrt (3);
00242 %! x = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
00243 %! v = [0, pi/6, pi/4, pi/3, pi/2, pi/3, pi/4, pi/6, 0];
00244 %! assert (all (abs (asin (x) - v) < sqrt (eps)));
00245 
00246 %!error asin ()
00247 %!error asin (1, 2)
00248 */
00249 
00250 DEFUN (asinh, args, ,
00251     "-*- texinfo -*-\n\
00252 @deftypefn {Mapping Function} {} asinh (@var{x})\n\
00253 Compute the inverse hyperbolic sine for each element of @var{x}.\n\
00254 @seealso{sinh}\n\
00255 @end deftypefn")
00256 {
00257   octave_value retval;
00258   if (args.length () == 1)
00259     retval = args(0).asinh ();
00260   else
00261     print_usage ();
00262 
00263   return retval;
00264 }
00265 
00266 /*
00267 %!test
00268 %! v = [0, pi/2*i, 0, -pi/2*i];
00269 %! x = [0, i, 0, -i];
00270 %! assert (asinh (x), v,  sqrt (eps));
00271 
00272 %!test
00273 %! v = single ([0, pi/2*i, 0, -pi/2*i]);
00274 %! x = single ([0, i, 0, -i]);
00275 %! assert (asinh (x), v,  sqrt (eps ('single')));
00276 
00277 %!error asinh ()
00278 %!error asinh (1, 2)
00279 */
00280 
00281 DEFUN (atan, args, ,
00282     "-*- texinfo -*-\n\
00283 @deftypefn {Mapping Function} {} atan (@var{x})\n\
00284 Compute the inverse tangent in radians for each element of @var{x}.\n\
00285 @seealso{tan, atand}\n\
00286 @end deftypefn")
00287 {
00288   octave_value retval;
00289   if (args.length () == 1)
00290     retval = args(0).atan ();
00291   else
00292     print_usage ();
00293 
00294   return retval;
00295 }
00296 
00297 /*
00298 %!shared rt2, rt3
00299 %! rt2 = sqrt (2);
00300 %! rt3 = sqrt (3);
00301 
00302 %!test
00303 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
00304 %! x = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
00305 %! assert (atan (x), v, sqrt (eps));
00306 
00307 %!test
00308 %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
00309 %! x = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
00310 %! assert (atan (x), v, sqrt (eps ('single')));
00311 
00312 %!error atan ()
00313 %!error atan (1, 2)
00314 */
00315 
00316 DEFUN (atanh, args, ,
00317     "-*- texinfo -*-\n\
00318 @deftypefn {Mapping Function} {} atanh (@var{x})\n\
00319 Compute the inverse hyperbolic tangent for each element of @var{x}.\n\
00320 @seealso{tanh}\n\
00321 @end deftypefn")
00322 {
00323   octave_value retval;
00324   if (args.length () == 1)
00325     retval = args(0).atanh ();
00326   else
00327     print_usage ();
00328 
00329   return retval;
00330 }
00331 
00332 /*
00333 %!test
00334 %! v = [0, 0];
00335 %! x = [0, 0];
00336 %! assert (atanh (x), v, sqrt (eps));
00337 
00338 %!test
00339 %! v = single ([0, 0]);
00340 %! x = single ([0, 0]);
00341 %! assert (atanh (x), v, sqrt (eps ('single')));
00342 
00343 %!error atanh ()
00344 %!error atanh (1, 2)
00345 */
00346 
00347 DEFUN (cbrt, args, ,
00348     "-*- texinfo -*-\n\
00349 @deftypefn {Mapping Function} {} cbrt (@var{x})\n\
00350 Compute the real cube root of each element of @var{x}.\n\
00351 Unlike @code{@var{x}^(1/3)}, the result will be negative if @var{x} is\n\
00352 negative.\n\
00353 @seealso{nthroot}\n\
00354 @end deftypefn")
00355 {
00356   octave_value retval;
00357   if (args.length () == 1)
00358     retval = args(0).cbrt ();
00359   else
00360     print_usage ();
00361 
00362   return retval;
00363 }
00364 
00365 /*
00366 %!assert (cbrt (64), 4)
00367 %!assert (cbrt (-125), -5)
00368 %!assert (cbrt (0), 0)
00369 %!assert (cbrt (Inf), Inf)
00370 %!assert (cbrt (-Inf), -Inf)
00371 %!assert (cbrt (NaN), NaN)
00372 %!assert (cbrt (2^300), 2^100)
00373 %!assert (cbrt (125*2^300), 5*2^100)
00374 
00375 %!error cbrt ()
00376 %!error cbrt (1, 2)
00377 */
00378 
00379 DEFUN (ceil, args, ,
00380     "-*- texinfo -*-\n\
00381 @deftypefn {Mapping Function} {} ceil (@var{x})\n\
00382 Return the smallest integer not less than @var{x}.  This is equivalent to\n\
00383 rounding towards positive infinity.  If @var{x} is\n\
00384 complex, return @code{ceil (real (@var{x})) + ceil (imag (@var{x})) * I}.\n\
00385 \n\
00386 @example\n\
00387 @group\n\
00388 ceil ([-2.7, 2.7])\n\
00389    @result{}  -2   3\n\
00390 @end group\n\
00391 @end example\n\
00392 @seealso{floor, round, fix}\n\
00393 @end deftypefn")
00394 {
00395   octave_value retval;
00396   if (args.length () == 1)
00397     retval = args(0).ceil ();
00398   else
00399     print_usage ();
00400 
00401   return retval;
00402 }
00403 
00404 /*
00405 %% double precision
00406 %!assert (ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1])
00407 
00408 %% complex double precison
00409 %!assert (ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i])
00410 
00411 %% single precision
00412 %!assert (ceil (single ([2, 1.1, -1.1, -1])), single ([2, 2, -1, -1]))
00413 
00414 %% complex single precision
00415 %!assert (ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 2+2i, -1-i, -1-i]))
00416 
00417 %!error ceil ()
00418 %!error ceil (1, 2)
00419 */
00420 
00421 DEFUN (conj, args, ,
00422     "-*- texinfo -*-\n\
00423 @deftypefn {Mapping Function} {} conj (@var{z})\n\
00424 Return the complex conjugate of @var{z}, defined as\n\
00425 @tex\n\
00426 $\\bar{z} = x - iy$.\n\
00427 @end tex\n\
00428 @ifnottex\n\
00429 @code{conj (@var{z})} = @var{x} - @var{i}@var{y}.\n\
00430 @end ifnottex\n\
00431 @seealso{real, imag}\n\
00432 @end deftypefn")
00433 {
00434   octave_value retval;
00435   if (args.length () == 1)
00436     retval = args(0).conj ();
00437   else
00438     print_usage ();
00439 
00440   return retval;
00441 }
00442 
00443 /*
00444 %!assert (conj (1), 1)
00445 %!assert (conj (i), -i)
00446 %!assert (conj (1+i), 1-i)
00447 %!assert (conj (1-i), 1+i)
00448 %!assert (conj ([-1, -i; -1+i, -1-i]), [-1, i; -1-i, -1+i])
00449 
00450 %!assert (conj (single (1)), single (1))
00451 %!assert (conj (single (i)), single (-i))
00452 %!assert (conj (single (1+i)), single (1-i))
00453 %!assert (conj (single (1-i)), single (1+i))
00454 %!assert (conj (single ([-1, -i; -1+i, -1-i])), single ([-1, i; -1-i, -1+i]))
00455 
00456 %!error conj ()
00457 %!error conj (1, 2)
00458 */
00459 
00460 DEFUN (cos, args, ,
00461     "-*- texinfo -*-\n\
00462 @deftypefn {Mapping Function} {} cos (@var{x})\n\
00463 Compute the cosine for each element of @var{x} in radians.\n\
00464 @seealso{acos, cosd, cosh}\n\
00465 @end deftypefn")
00466 {
00467   octave_value retval;
00468   if (args.length () == 1)
00469     retval = args(0).cos ();
00470   else
00471     print_usage ();
00472 
00473   return retval;
00474 }
00475 
00476 /*
00477 %!shared rt2, rt3
00478 %! rt2 = sqrt (2);
00479 %! rt3 = sqrt (3);
00480 
00481 %!test
00482 %! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
00483 %! v = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
00484 %! assert (cos (x), v, sqrt (eps));
00485 
00486 %!test
00487 %! rt2 = sqrt (2);
00488 %! rt3 = sqrt (3);
00489 %! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
00490 %! v = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
00491 %! assert (cos (x), v, sqrt (eps ('single')));
00492 
00493 %!error cos ()
00494 %!error cos (1, 2)
00495 */
00496 
00497 DEFUN (cosh, args, ,
00498     "-*- texinfo -*-\n\
00499 @deftypefn {Mapping Function} {} cosh (@var{x})\n\
00500 Compute the hyperbolic cosine for each element of @var{x}.\n\
00501 @seealso{acosh, sinh, tanh}\n\
00502 @end deftypefn")
00503 {
00504   octave_value retval;
00505   if (args.length () == 1)
00506     retval = args(0).cosh ();
00507   else
00508     print_usage ();
00509 
00510   return retval;
00511 }
00512 
00513 /*
00514 %!test
00515 %! x = [0, pi/2*i, pi*i, 3*pi/2*i];
00516 %! v = [1, 0, -1, 0];
00517 %! assert (cosh (x), v, sqrt (eps));
00518 
00519 %!test
00520 %! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
00521 %! v = single ([1, 0, -1, 0]);
00522 %! assert (cosh (x), v, sqrt (eps ('single')));
00523 
00524 %!error cosh ()
00525 %!error cosh (1, 2)
00526 */
00527 
00528 DEFUN (erf, args, ,
00529     "-*- texinfo -*-\n\
00530 @deftypefn {Mapping Function} {} erf (@var{z})\n\
00531 Compute the error function,\n\
00532 @tex\n\
00533 $$\n\
00534  {\\rm erf} (z) = {2 \\over \\sqrt{\\pi}}\\int_0^z e^{-t^2} dt\n\
00535 $$\n\
00536 @end tex\n\
00537 @ifnottex\n\
00538 \n\
00539 @example\n\
00540 @group\n\
00541 @c spacing appears odd here, but is correct after Makeinfo\n\
00542                           z\n\
00543                          /\n\
00544 erf (z) = (2/sqrt (pi)) | e^(-t^2) dt\n\
00545                          /\n\
00546                       t=0\n\
00547 @end group\n\
00548 @end example\n\
00549 \n\
00550 @end ifnottex\n\
00551 @seealso{erfc, erfcx, erfinv}\n\
00552 @end deftypefn")
00553 {
00554   octave_value retval;
00555   if (args.length () == 1)
00556     retval = args(0).erf ();
00557   else
00558     print_usage ();
00559 
00560   return retval;
00561 }
00562 
00563 /*
00564 %!test
00565 %! a = -1i*sqrt (-1/(6.4187*6.4187));
00566 %! assert (erf (a), erf (real (a)));
00567 
00568 %!test
00569 %! x = [0,.5,1];
00570 %! v = [0, .520499877813047, .842700792949715];
00571 %! assert (all (abs (erf (x)-v) < 1.e-10));
00572 %! assert (all (abs (erf (-x)+v) < 1.e-10));
00573 %! assert (all (abs (erfc (x)+v-1) < 1.e-10));
00574 %! assert (all (abs (erfinv (v)-x) < 1.e-10));
00575 
00576 %!test
00577 %! a = -1i*sqrt (single (-1/(6.4187*6.4187)));
00578 %! assert (erf (a), erf (real (a)));
00579 
00580 %!test
00581 %! x = single ([0,.5,1]);
00582 %! v = single ([0, .520499877813047, .842700792949715]);
00583 %! assert (all (abs (erf (x)-v) < 1.e-6));
00584 %! assert (all (abs (erf (-x)+v) < 1.e-6));
00585 %! assert (all (abs (erfc (x)+v-1) < 1.e-6));
00586 %! assert (all (abs (erfinv (v)-x) < 1.e-6));
00587 
00588 %!error erf ()
00589 %!error erf (1, 2)
00590 */
00591 
00592 DEFUN (erfinv, args, ,
00593     "-*- texinfo -*-\n\
00594 @deftypefn {Mapping Function} {} erfinv (@var{x})\n\
00595 Compute the inverse error function, i.e., @var{y} such that\n\
00596 \n\
00597 @example\n\
00598   erf (@var{y}) == @var{x}\n\
00599 @end example\n\
00600 @seealso{erf, erfc, erfcx}\n\
00601 @end deftypefn")
00602 {
00603   octave_value retval;
00604   if (args.length () == 1)
00605     retval = args(0).erfinv ();
00606   else
00607     print_usage ();
00608 
00609   return retval;
00610 }
00611 
00612 /*
00613 %% middle region
00614 %!assert (erf (erfinv ([-0.9 -0.3 0 0.4 0.8])), [-0.9 -0.3 0 0.4 0.8], eps)
00615 %!assert (erf (erfinv (single ([-0.9 -0.3 0 0.4 0.8]))), single ([-0.9 -0.3 0 0.4 0.8]), 1e-8)
00616 %% tail region
00617 %!assert (erf (erfinv ([-0.999 -0.99 0.9999 0.99999])), [-0.999 -0.99 0.9999 0.99999], eps)
00618 %!assert (erf (erfinv (single ([-0.999 -0.99 0.9999 0.99999]))), single ([-0.999 -0.99 0.9999 0.99999]), 1e-8)
00619 %% backward - loss of accuracy
00620 %!assert (erfinv (erf ([-3 -1 -0.4 0.7 1.3 2.8])), [-3 -1 -0.4 0.7 1.3 2.8], -1e-12)
00621 %!assert (erfinv (erf (single ([-3 -1 -0.4 0.7 1.3 2.8]))), single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4)
00622 %% exceptional
00623 %!assert (erfinv ([-1, 1, 1.1, -2.1]), [-Inf, Inf, NaN, NaN])
00624 %!error erfinv (1+2i)
00625 
00626 %!error erfinv ()
00627 %!error erfinv (1, 2)
00628 */
00629 
00630 DEFUN (erfc, args, ,
00631     "-*- texinfo -*-\n\
00632 @deftypefn {Mapping Function} {} erfc (@var{z})\n\
00633 Compute the complementary error function,\n\
00634 @tex\n\
00635 $1 - {\\rm erf} (z)$.\n\
00636 @end tex\n\
00637 @ifnottex\n\
00638 @w{@code{1 - erf (@var{z})}}.\n\
00639 @end ifnottex\n\
00640 @seealso{erfcx, erf, erfinv}\n\
00641 @end deftypefn")
00642 {
00643   octave_value retval;
00644   if (args.length () == 1)
00645     retval = args(0).erfc ();
00646   else
00647     print_usage ();
00648 
00649   return retval;
00650 }
00651 
00652 /*
00653 %!test
00654 %! a = -1i*sqrt (-1/(6.4187*6.4187));
00655 %! assert (erfc (a), erfc (real (a)));
00656 
00657 %!error erfc ()
00658 %!error erfc (1, 2)
00659 */
00660 
00661 DEFUN (erfcx, args, ,
00662     "-*- texinfo -*-\n\
00663 @deftypefn {Mapping Function} {} erfcx (@var{z})\n\
00664 Compute the scaled complementary error function,\n\
00665 @tex\n\
00666 $$\n\
00667  e^{z^2} {\\rm erfc} (z) \\equiv e^{z^2} (1 - {\\rm erf} (z))\n\
00668 $$\n\
00669 @end tex\n\
00670 @ifnottex\n\
00671 \n\
00672 @example\n\
00673 exp (z^2) * erfc (x)\n\
00674 @end example\n\
00675 \n\
00676 @end ifnottex\n\
00677 @seealso{erfc, erf, erfinv}\n\
00678 @end deftypefn")
00679 {
00680   octave_value retval;
00681   if (args.length () == 1)
00682     retval = args(0).erfcx ();
00683   else
00684     print_usage ();
00685 
00686   return retval;
00687 }
00688 
00689 /*
00690 %% FIXME: Need a test for erfcx
00691 
00692 %!error erfcx ()
00693 %!error erfcx (1, 2)
00694 */
00695 
00696 DEFUN (exp, args, ,
00697     "-*- texinfo -*-\n\
00698 @deftypefn {Mapping Function} {} exp (@var{x})\n\
00699 Compute\n\
00700 @tex\n\
00701 $e^{x}$\n\
00702 @end tex\n\
00703 @ifnottex\n\
00704 @code{e^x}\n\
00705 @end ifnottex\n\
00706 for each element of @var{x}.  To compute the matrix\n\
00707 exponential, see @ref{Linear Algebra}.\n\
00708 @seealso{log}\n\
00709 @end deftypefn")
00710 {
00711   octave_value retval;
00712   if (args.length () == 1)
00713     retval = args(0).exp ();
00714   else
00715     print_usage ();
00716 
00717   return retval;
00718 }
00719 
00720 /*
00721 %!assert (exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps))
00722 %!assert (exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps))
00723 %!assert (exp (single ([0, 1, -1, -1000])), single ([1, e, 1/e, 0]), sqrt (eps ('single')))
00724 %!assert (exp (single (1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps ('single')))
00725 
00726 %!assert (exp ([Inf, -Inf, NaN]), [Inf 0 NaN])
00727 %!assert (exp (single ([Inf, -Inf, NaN])), single ([Inf 0 NaN]))
00728 
00729 %!error exp ()
00730 %!error exp (1, 2)
00731 */
00732 
00733 DEFUN (expm1, args, ,
00734     "-*- texinfo -*-\n\
00735 @deftypefn {Mapping Function} {} expm1 (@var{x})\n\
00736 Compute\n\
00737 @tex\n\
00738 $ e^{x} - 1 $\n\
00739 @end tex\n\
00740 @ifnottex\n\
00741 @code{exp (@var{x}) - 1}\n\
00742 @end ifnottex\n\
00743 accurately in the neighborhood of zero.\n\
00744 @seealso{exp}\n\
00745 @end deftypefn")
00746 {
00747   octave_value retval;
00748   if (args.length () == 1)
00749     retval = args(0).expm1 ();
00750   else
00751     print_usage ();
00752 
00753   return retval;
00754 }
00755 
00756 /*
00757 %!assert (expm1 (2*eps), 2*eps, 1e-29)
00758 
00759 %!assert (expm1 ([Inf, -Inf, NaN]), [Inf -1 NaN])
00760 %!assert (expm1 (single ([Inf, -Inf, NaN])), single ([Inf -1 NaN]))
00761 
00762 %!error expm1 ()
00763 %!error expm1 (1, 2)
00764 */
00765 
00766 DEFUN (isfinite, args, ,
00767     "-*- texinfo -*-\n\
00768 @deftypefn  {Mapping Function} {} isfinite (@var{x})\n\
00769 @deftypefnx {Mapping Function} {} finite (@var{x})\n\
00770 Return a logical array which is true where the elements of @var{x} are\n\
00771 finite values and false where they are not.\n\
00772 For example:\n\
00773 \n\
00774 @example\n\
00775 @group\n\
00776 finite ([13, Inf, NA, NaN])\n\
00777      @result{} [ 1, 0, 0, 0 ]\n\
00778 @end group\n\
00779 @end example\n\
00780 @seealso{isinf, isnan, isna}\n\
00781 @end deftypefn")
00782 {
00783   octave_value retval;
00784   if (args.length () == 1)
00785     retval = args(0).finite ();
00786   else
00787     print_usage ();
00788 
00789   return retval;
00790 }
00791 
00792 /*
00793 %!assert (!finite (Inf))
00794 %!assert (!finite (NaN))
00795 %!assert (finite (rand (1,10)))
00796 
00797 %!assert (!finite (single (Inf)))
00798 %!assert (!finite (single (NaN)))
00799 %!assert (finite (single (rand (1,10))))
00800 
00801 %!error finite ()
00802 %!error finite (1, 2)
00803 */
00804 
00805 DEFUN (fix, args, ,
00806     "-*- texinfo -*-\n\
00807 @deftypefn {Mapping Function} {} fix (@var{x})\n\
00808 Truncate fractional portion of @var{x} and return the integer portion.  This\n\
00809 is equivalent to rounding towards zero.  If @var{x} is complex, return\n\
00810 @code{fix (real (@var{x})) + fix (imag (@var{x})) * I}.\n\
00811 \n\
00812 @example\n\
00813 @group\n\
00814 fix ([-2.7, 2.7])\n\
00815    @result{} -2   2\n\
00816 @end group\n\
00817 @end example\n\
00818 @seealso{ceil, floor, round}\n\
00819 @end deftypefn")
00820 {
00821   octave_value retval;
00822   if (args.length () == 1)
00823     retval = args(0).fix ();
00824   else
00825     print_usage ();
00826 
00827   return retval;
00828 }
00829 
00830 /*
00831 %!assert (fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1])
00832 %!assert (fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i])
00833 %!assert (fix (single ([1.1, 1, -1.1, -1])), single ([1, 1, -1, -1]))
00834 %!assert (fix (single ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])), single ([1+i, 1+i, -1-i, -1-i]))
00835 
00836 %!error fix ()
00837 %!error fix (1, 2)
00838 */
00839 
00840 DEFUN (floor, args, ,
00841     "-*- texinfo -*-\n\
00842 @deftypefn {Mapping Function} {} floor (@var{x})\n\
00843 Return the largest integer not greater than @var{x}.  This is equivalent to\n\
00844 rounding towards negative infinity.  If @var{x} is\n\
00845 complex, return @code{floor (real (@var{x})) + floor (imag (@var{x})) * I}.\n\
00846 \n\
00847 @example\n\
00848 @group\n\
00849 floor ([-2.7, 2.7])\n\
00850      @result{} -3   2\n\
00851 @end group\n\
00852 @end example\n\
00853 @seealso{ceil, round, fix}\n\
00854 @end deftypefn")
00855 {
00856   octave_value retval;
00857   if (args.length () == 1)
00858     retval = args(0).floor ();
00859   else
00860     print_usage ();
00861 
00862   return retval;
00863 }
00864 
00865 /*
00866 %!assert (floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1])
00867 %!assert (floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i])
00868 %!assert (floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]))
00869 %!assert (floor (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 1+i, -2-2i, -1-i]))
00870 
00871 %!error floor ()
00872 %!error floor (1, 2)
00873 */
00874 
00875 DEFUN (gamma, args, ,
00876     "-*- texinfo -*-\n\
00877 @deftypefn {Mapping Function} {} gamma (@var{z})\n\
00878 Compute the Gamma function,\n\
00879 @tex\n\
00880 $$\n\
00881  \\Gamma (z) = \\int_0^\\infty t^{z-1} e^{-t} dt.\n\
00882 $$\n\
00883 @end tex\n\
00884 @ifnottex\n\
00885 \n\
00886 @example\n\
00887 @group\n\
00888 @c spacing appears odd here, but is correct after Makeinfo\n\
00889               infinity\n\
00890              /\n\
00891 gamma (z) = | t^(z-1) exp (-t) dt.\n\
00892              /\n\
00893           t=0\n\
00894 @end group\n\
00895 @end example\n\
00896 \n\
00897 @end ifnottex\n\
00898 @seealso{gammainc, lgamma}\n\
00899 @end deftypefn")
00900 {
00901   octave_value retval;
00902   if (args.length () == 1)
00903     retval = args(0).gamma ();
00904   else
00905     print_usage ();
00906 
00907   return retval;
00908 }
00909 
00910 /*
00911 %!test
00912 %! a = -1i*sqrt (-1/(6.4187*6.4187));
00913 %! assert (gamma (a), gamma (real (a)));
00914 
00915 %!test
00916 %! x = [.5, 1, 1.5, 2, 3, 4, 5];
00917 %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
00918 %! assert (gamma (x), v, sqrt (eps));
00919 
00920 %!test
00921 %! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
00922 %! assert (gamma (a), gamma (real (a)));
00923 
00924 %!test
00925 %! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
00926 %! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
00927 %! assert (gamma (x), v, sqrt (eps ('single')));
00928 
00929 %!test
00930 %! x = [-1, 0, 1, Inf];
00931 %! v = [Inf, Inf, 1, Inf];
00932 %! assert (gamma (x), v);
00933 %! assert (gamma (single (x)), single (v));
00934 
00935 %!error gamma ()
00936 %!error gamma (1, 2)
00937 */
00938 
00939 DEFUN (imag, args, ,
00940     "-*- texinfo -*-\n\
00941 @deftypefn {Mapping Function} {} imag (@var{z})\n\
00942 Return the imaginary part of @var{z} as a real number.\n\
00943 @seealso{real, conj}\n\
00944 @end deftypefn")
00945 {
00946   octave_value retval;
00947   if (args.length () == 1)
00948     retval = args(0).imag ();
00949   else
00950     print_usage ();
00951 
00952   return retval;
00953 }
00954 
00955 /*
00956 %!assert (imag (1), 0)
00957 %!assert (imag (i), 1)
00958 %!assert (imag (1+i), 1)
00959 %!assert (imag ([i, 1; 1, i]), full (eye (2)))
00960 
00961 %!assert (imag (single (1)), single (0))
00962 %!assert (imag (single (i)), single (1))
00963 %!assert (imag (single (1+i)), single (1))
00964 %!assert (imag (single ([i, 1; 1, i])), full (eye (2,'single')))
00965 
00966 %!error imag ()
00967 %!error imag (1, 2)
00968 */
00969 
00970 DEFUNX ("isalnum", Fisalnum, args, ,
00971     "-*- texinfo -*-\n\
00972 @deftypefn {Mapping Function} {} isalnum (@var{s})\n\
00973 Return a logical array which is true where the elements of @var{s} are\n\
00974 letters or digits and false where they are not.  This is equivalent to\n\
00975 (@code{isalpha (@var{s}) | isdigit (@var{s})}).\n\
00976 @seealso{isalpha, isdigit, ispunct, isspace, iscntrl}\n\
00977 @end deftypefn")
00978 {
00979   octave_value retval;
00980   if (args.length () == 1)
00981     retval = args(0).xisalnum ();
00982   else
00983     print_usage ();
00984 
00985   return retval;
00986 }
00987 
00988 /*
00989 %!test
00990 %! charset = char (0:127);
00991 %! result = false (1, 128);
00992 %! result(toascii ("A":"Z") + 1) = true;
00993 %! result(toascii ("0":"9") + 1) = true;
00994 %! result(toascii ("a":"z") + 1) = true;
00995 %! assert (all (isalnum (charset) == result));
00996 
00997 %!error isalnum ()
00998 %!error isalnum (1, 2)
00999 */
01000 
01001 DEFUNX ("isalpha", Fisalpha, args, ,
01002     "-*- texinfo -*-\n\
01003 @deftypefn {Mapping Function} {} isalpha (@var{s})\n\
01004 Return a logical array which is true where the elements of @var{s} are\n\
01005 letters and false where they are not.  This is equivalent to\n\
01006 (@code{islower (@var{s}) | isupper (@var{s})}).\n\
01007 @seealso{isdigit, ispunct, isspace, iscntrl, isalnum, islower, isupper}\n\
01008 @end deftypefn")
01009 {
01010   octave_value retval;
01011   if (args.length () == 1)
01012     retval = args(0).xisalpha ();
01013   else
01014     print_usage ();
01015 
01016   return retval;
01017 }
01018 
01019 /*
01020 %!test
01021 %! charset = char (0:127);
01022 %! result = false (1, 128);
01023 %! result(toascii ("A":"Z") + 1) = true;
01024 %! result(toascii ("a":"z") + 1) = true;
01025 %! assert (all (isalpha (charset) == result));
01026 
01027 %!error isalpha ()
01028 %!error isalpha (1, 2)
01029 */
01030 
01031 DEFUNX ("isascii", Fisascii, args, ,
01032     "-*- texinfo -*-\n\
01033 @deftypefn {Mapping Function} {} isascii (@var{s})\n\
01034 Return a logical array which is true where the elements of @var{s} are\n\
01035 ASCII characters (in the range 0 to 127 decimal) and false where they are\n\
01036 not.\n\
01037 @end deftypefn")
01038 {
01039   octave_value retval;
01040   if (args.length () == 1)
01041     retval = args(0).xisascii ();
01042   else
01043     print_usage ();
01044 
01045   return retval;
01046 }
01047 
01048 /*
01049 %!test
01050 %! charset = char (0:127);
01051 %! result = true (1, 128);
01052 %! assert (all (isascii (charset) == result));
01053 
01054 %!error isascii ()
01055 %!error isascii (1, 2)
01056 */
01057 
01058 DEFUNX ("iscntrl", Fiscntrl, args, ,
01059     "-*- texinfo -*-\n\
01060 @deftypefn {Mapping Function} {} iscntrl (@var{s})\n\
01061 Return a logical array which is true where the elements of @var{s} are\n\
01062 control characters and false where they are not.\n\
01063 @seealso{ispunct, isspace, isalpha, isdigit}\n\
01064 @end deftypefn")
01065 {
01066   octave_value retval;
01067   if (args.length () == 1)
01068     retval = args(0).xiscntrl ();
01069   else
01070     print_usage ();
01071 
01072   return retval;
01073 }
01074 
01075 /*
01076 %!test
01077 %! charset = char (0:127);
01078 %! result = false (1, 128);
01079 %! result(1:32) = true;
01080 %! result(128) = true;
01081 %! assert (all (iscntrl (charset) == result));
01082 
01083 %!error iscntrl ()
01084 %!error iscntrl (1, 2)
01085 */
01086 
01087 DEFUNX ("isdigit", Fisdigit, args, ,
01088     "-*- texinfo -*-\n\
01089 @deftypefn {Mapping Function} {} isdigit (@var{s})\n\
01090 Return a logical array which is true where the elements of @var{s} are\n\
01091 decimal digits (0-9) and false where they are not.\n\
01092 @seealso{isxdigit, isalpha, isletter, ispunct, isspace, iscntrl}\n\
01093 @end deftypefn")
01094 {
01095   octave_value retval;
01096   if (args.length () == 1)
01097     retval = args(0).xisdigit ();
01098   else
01099     print_usage ();
01100 
01101   return retval;
01102 }
01103 
01104 /*
01105 %!test
01106 %! charset = char (0:127);
01107 %! result = false (1, 128);
01108 %! result(toascii ("0":"9") + 1) = true;
01109 %! assert (all (isdigit (charset) == result));
01110 
01111 %!error isdigit ()
01112 %!error isdigit (1, 2)
01113 */
01114 
01115 DEFUN (isinf, args, ,
01116     "-*- texinfo -*-\n\
01117 @deftypefn {Mapping Function} {} isinf (@var{x})\n\
01118 Return a logical array which is true where the elements of @var{x} are\n\
01119 are infinite and false where they are not.\n\
01120 For example:\n\
01121 \n\
01122 @example\n\
01123 @group\n\
01124 isinf ([13, Inf, NA, NaN])\n\
01125      @result{} [ 0, 1, 0, 0 ]\n\
01126 @end group\n\
01127 @end example\n\
01128 @seealso{isfinite, isnan, isna}\n\
01129 @end deftypefn")
01130 {
01131   octave_value retval;
01132   if (args.length () == 1)
01133     retval = args(0).isinf ();
01134   else
01135     print_usage ();
01136 
01137   return retval;
01138 }
01139 
01140 /*
01141 %!assert (isinf (Inf))
01142 %!assert (!isinf (NaN))
01143 %!assert (!isinf (NA))
01144 %!assert (isinf (rand(1,10)), false (1,10))
01145 %!assert (isinf ([NaN -Inf -1 0 1 Inf NA]), [false, true, false, false, false, true, false])
01146 
01147 %!assert (isinf (single (Inf)))
01148 %!assert (!isinf (single (NaN)))
01149 %!assert (!isinf (single (NA)))
01150 %!assert (isinf (single (rand(1,10))), false (1,10))
01151 %!assert (isinf (single ([NaN -Inf -1 0 1 Inf NA])), [false, true, false, false, false, true, false])
01152 
01153 %!error isinf ()
01154 %!error isinf (1, 2)
01155 */
01156 
01157 DEFUNX ("isgraph", Fisgraph, args, ,
01158     "-*- texinfo -*-\n\
01159 @deftypefn {Mapping Function} {} isgraph (@var{s})\n\
01160 Return a logical array which is true where the elements of @var{s} are\n\
01161 printable characters (but not the space character) and false where they are\n\
01162 not.\n\
01163 @seealso{isprint}\n\
01164 @end deftypefn")
01165 {
01166   octave_value retval;
01167   if (args.length () == 1)
01168     retval = args(0).xisgraph ();
01169   else
01170     print_usage ();
01171 
01172   return retval;
01173 }
01174 
01175 /*
01176 %!test
01177 %! charset = char (0:127);
01178 %! result = false (1, 128);
01179 %! result(34:127) = true;
01180 %! assert (all (isgraph (charset) == result));
01181 
01182 %!error isgraph ()
01183 %!error isgraph (1, 2)
01184 */
01185 
01186 DEFUNX ("islower", Fislower, args, ,
01187     "-*- texinfo -*-\n\
01188 @deftypefn {Mapping Function} {} islower (@var{s})\n\
01189 Return a logical array which is true where the elements of @var{s} are\n\
01190 lowercase letters and false where they are not.\n\
01191 @seealso{isupper, isalpha, isletter, isalnum}\n\
01192 @end deftypefn")
01193 {
01194   octave_value retval;
01195   if (args.length () == 1)
01196     retval = args(0).xislower ();
01197   else
01198     print_usage ();
01199 
01200   return retval;
01201 }
01202 
01203 /*
01204 %!test
01205 %! charset = char (0:127);
01206 %! result = false (1, 128);
01207 %! result(toascii ("a":"z") + 1) = true;
01208 %! assert (all (islower (charset) == result));
01209 
01210 %!error islower ()
01211 %!error islower (1, 2)
01212 */
01213 
01214 DEFUN (isna, args, ,
01215     "-*- texinfo -*-\n\
01216 @deftypefn {Mapping Function} {} isna (@var{x})\n\
01217 Return a logical array which is true where the elements of @var{x} are\n\
01218 NA (missing) values and false where they are not.\n\
01219 For example:\n\
01220 \n\
01221 @example\n\
01222 @group\n\
01223 isna ([13, Inf, NA, NaN])\n\
01224      @result{} [ 0, 0, 1, 0 ]\n\
01225 @end group\n\
01226 @end example\n\
01227 @seealso{isnan, isinf, isfinite}\n\
01228 @end deftypefn")
01229 {
01230   octave_value retval;
01231   if (args.length () == 1)
01232     retval = args(0).isna ();
01233   else
01234     print_usage ();
01235 
01236   return retval;
01237 }
01238 
01239 /*
01240 %!assert (!isna (Inf))
01241 %!assert (!isna (NaN))
01242 %!assert (isna (NA))
01243 %!assert (isna (rand(1,10)), false (1,10))
01244 %!assert (isna ([NaN -Inf -1 0 1 Inf NA]), [false, false, false, false, false, false, true])
01245 
01246 %!assert (!isna (single (Inf)))
01247 %!assert (!isna (single (NaN)))
01248 %!assert (isna (single (NA)))
01249 %!assert (isna (single (rand(1,10))), false (1,10))
01250 %!assert (isna (single ([NaN -Inf -1 0 1 Inf NA])), [false, false, false, false, false, false, true])
01251 
01252 %!error isna ()
01253 %!error isna (1, 2)
01254 */
01255 
01256 DEFUN (isnan, args, ,
01257     "-*- texinfo -*-\n\
01258 @deftypefn {Mapping Function} {} isnan (@var{x})\n\
01259 Return a logical array which is true where the elements of @var{x} are\n\
01260 NaN values and false where they are not.\n\
01261 NA values are also considered NaN values.  For example:\n\
01262 \n\
01263 @example\n\
01264 @group\n\
01265 isnan ([13, Inf, NA, NaN])\n\
01266      @result{} [ 0, 0, 1, 1 ]\n\
01267 @end group\n\
01268 @end example\n\
01269 @seealso{isna, isinf, isfinite}\n\
01270 @end deftypefn")
01271 {
01272   octave_value retval;
01273   if (args.length () == 1)
01274     retval = args(0).isnan ();
01275   else
01276     print_usage ();
01277 
01278   return retval;
01279 }
01280 
01281 /*
01282 %!assert (!isnan (Inf))
01283 %!assert (isnan (NaN))
01284 %!assert (isnan (NA))
01285 %!assert (isnan (rand(1,10)), false (1,10))
01286 %!assert (isnan ([NaN -Inf -1 0 1 Inf NA]), [true, false, false, false, false, false, true])
01287 
01288 %!assert (!isnan (single (Inf)))
01289 %!assert (isnan (single (NaN)))
01290 %!assert (isnan (single (NA)))
01291 %!assert (isnan (single (rand(1,10))), false (1,10))
01292 %!assert (isnan (single ([NaN -Inf -1 0 1 Inf NA])), [true, false, false, false, false, false, true])
01293 
01294 %!error isnan ()
01295 %!error isnan (1, 2)
01296 */
01297 
01298 DEFUNX ("isprint", Fisprint, args, ,
01299     "-*- texinfo -*-\n\
01300 @deftypefn {Mapping Function} {} isprint (@var{s})\n\
01301 Return a logical array which is true where the elements of @var{s} are\n\
01302 printable characters (including the space character) and false where they\n\
01303 are not.\n\
01304 @seealso{isgraph}\n\
01305 @end deftypefn")
01306 {
01307   octave_value retval;
01308   if (args.length () == 1)
01309     retval = args(0).xisprint ();
01310   else
01311     print_usage ();
01312 
01313   return retval;
01314 }
01315 
01316 /*
01317 %!test
01318 %! charset = char (0:127);
01319 %! result = false (1, 128);
01320 %! result(33:127) = true;
01321 %! assert (all (isprint (charset) == result));
01322 
01323 %!error isprint ()
01324 %!error isprint (1, 2)
01325 */
01326 
01327 DEFUNX ("ispunct", Fispunct, args, ,
01328     "-*- texinfo -*-\n\
01329 @deftypefn {Mapping Function} {} ispunct (@var{s})\n\
01330 Return a logical array which is true where the elements of @var{s} are\n\
01331 punctuation characters and false where they are not.\n\
01332 @seealso{isalpha, isdigit, isspace, iscntrl}\n\
01333 @end deftypefn")
01334 {
01335   octave_value retval;
01336   if (args.length () == 1)
01337     retval = args(0).xispunct ();
01338   else
01339     print_usage ();
01340 
01341   return retval;
01342 }
01343 
01344 /*
01345 %!test
01346 %! charset = char (0:127);
01347 %! result = false (1, 128);
01348 %! result(34:48) = true;
01349 %! result(59:65) = true;
01350 %! result(92:97) = true;
01351 %! result(124:127) = true;
01352 %! assert (all (ispunct (charset) == result));
01353 
01354 %!error ispunct ()
01355 %!error ispunct (1, 2)
01356 */
01357 
01358 DEFUNX ("isspace", Fisspace, args, ,
01359     "-*- texinfo -*-\n\
01360 @deftypefn {Mapping Function} {} isspace (@var{s})\n\
01361 Return a logical array which is true where the elements of @var{s} are\n\
01362 whitespace characters (space, formfeed, newline, carriage return, tab, and\n\
01363 vertical tab) and false where they are not.\n\
01364 @seealso{iscntrl, ispunct, isalpha, isdigit}\n\
01365 @end deftypefn")
01366 {
01367   octave_value retval;
01368   if (args.length () == 1)
01369     retval = args(0).xisspace ();
01370   else
01371     print_usage ();
01372 
01373   return retval;
01374 }
01375 
01376 /*
01377 %!test
01378 %! charset = char (0:127);
01379 %! result = false (1, 128);
01380 %! result(toascii (" \f\n\r\t\v") + 1) = true;
01381 %! assert (all (isspace (charset) == result));
01382 
01383 %!error isspace ()
01384 %!error isspace (1, 2)
01385 */
01386 
01387 DEFUNX ("isupper", Fisupper, args, ,
01388     "-*- texinfo -*-\n\
01389 @deftypefn {Mapping Function} {} isupper (@var{s})\n\
01390 Return a logical array which is true where the elements of @var{s} are\n\
01391 uppercase letters and false where they are not.\n\
01392 @seealso{islower, isalpha, isletter, isalnum}\n\
01393 @end deftypefn")
01394 {
01395   octave_value retval;
01396   if (args.length () == 1)
01397     retval = args(0).xisupper ();
01398   else
01399     print_usage ();
01400 
01401   return retval;
01402 }
01403 
01404 /*
01405 %!test
01406 %! charset = char (0:127);
01407 %! result = false (1, 128);
01408 %! result(toascii ("A":"Z") + 1) = true;
01409 %! assert (all (isupper (charset) == result));
01410 
01411 %!error isupper ()
01412 %!error isupper (1, 2)
01413 */
01414 
01415 DEFUNX ("isxdigit", Fisxdigit, args, ,
01416     "-*- texinfo -*-\n\
01417 @deftypefn {Mapping Function} {} isxdigit (@var{s})\n\
01418 Return a logical array which is true where the elements of @var{s} are\n\
01419 hexadecimal digits (0-9 and @nospell{a-fA-F}).\n\
01420 @seealso{isdigit}\n\
01421 @end deftypefn")
01422 {
01423   octave_value retval;
01424   if (args.length () == 1)
01425     retval = args(0).xisxdigit ();
01426   else
01427     print_usage ();
01428 
01429   return retval;
01430 }
01431 
01432 /*
01433 %!test
01434 %! charset = char (0:127);
01435 %! result = false (1, 128);
01436 %! result(toascii ("A":"F") + 1) = true;
01437 %! result(toascii ("0":"9") + 1) = true;
01438 %! result(toascii ("a":"f") + 1) = true;
01439 %! assert (all (isxdigit (charset) == result));
01440 
01441 %!error isxdigit ()
01442 %!error isxdigit (1, 2)
01443 */
01444 
01445 DEFUN (lgamma, args, ,
01446     "-*- texinfo -*-\n\
01447 @deftypefn  {Mapping Function} {} lgamma (@var{x})\n\
01448 @deftypefnx {Mapping Function} {} gammaln (@var{x})\n\
01449 Return the natural logarithm of the gamma function of @var{x}.\n\
01450 @seealso{gamma, gammainc}\n\
01451 @end deftypefn")
01452 {
01453   octave_value retval;
01454   if (args.length () == 1)
01455     retval = args(0).lgamma ();
01456   else
01457     print_usage ();
01458 
01459   return retval;
01460 }
01461 
01462 /*
01463 %!test
01464 %! a = -1i*sqrt (-1/(6.4187*6.4187));
01465 %! assert (lgamma(a), lgamma(real(a)));
01466 
01467 %!test
01468 %! x = [.5, 1, 1.5, 2, 3, 4, 5];
01469 %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
01470 %! assert (lgamma(x), log(v), sqrt (eps))
01471 
01472 %!test
01473 %! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
01474 %! assert (lgamma(a), lgamma(real(a)));
01475 
01476 %!test
01477 %! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
01478 %! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
01479 %! assert (lgamma(x), log(v), sqrt (eps ('single')))
01480 
01481 %!test
01482 %! x = [-1, 0, 1, Inf];
01483 %! v = [Inf, Inf, 0, Inf];
01484 %! assert (lgamma(x), v);
01485 %! assert (lgamma(single (x)), single (v));
01486 
01487 %!error lgamma()
01488 %!error lgamma(1,2)
01489 */
01490 
01491 DEFUN (log, args, ,
01492     "-*- texinfo -*-\n\
01493 @deftypefn {Mapping Function} {} log (@var{x})\n\
01494 Compute the natural logarithm,\n\
01495 @tex\n\
01496 $\\ln{(x)},$\n\
01497 @end tex\n\
01498 @ifnottex\n\
01499 @code{ln (@var{x})},\n\
01500 @end ifnottex\n\
01501 for each element of @var{x}.  To compute the\n\
01502 matrix logarithm, see @ref{Linear Algebra}.\n\
01503 @seealso{exp, log1p, log2, log10, logspace}\n\
01504 @end deftypefn")
01505 {
01506   octave_value retval;
01507   if (args.length () == 1)
01508     retval = args(0).log ();
01509   else
01510     print_usage ();
01511 
01512   return retval;
01513 }
01514 
01515 /*
01516 %!assert (log ([1, e, e^2]), [0, 1, 2], sqrt (eps))
01517 %!assert (log ([-0.5, -1.5, -2.5]), log([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps))
01518 
01519 %!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ('single')))
01520 %!assert (log (single ([-0.5, -1.5, -2.5])), single (log([0.5, 1.5, 2.5]) + pi*1i), 4*eps ('single'))
01521 
01522 %!error log ()
01523 %!error log (1, 2)
01524 */
01525 
01526 DEFUN (log10, args, ,
01527     "-*- texinfo -*-\n\
01528 @deftypefn {Mapping Function} {} log10 (@var{x})\n\
01529 Compute the base-10 logarithm of each element of @var{x}.\n\
01530 @seealso{log, log2, logspace, exp}\n\
01531 @end deftypefn")
01532 {
01533   octave_value retval;
01534   if (args.length () == 1)
01535     retval = args(0).log10 ();
01536   else
01537     print_usage ();
01538 
01539   return retval;
01540 }
01541 
01542 /*
01543 %!assert (log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps))
01544 %!assert (log10 (single ([0.01, 0.1, 1, 10, 100])), single ([-2, -1, 0, 1, 2]), sqrt (eps ('single')))
01545 
01546 %!error log10 ()
01547 %!error log10 (1, 2)
01548 */
01549 
01550 DEFUN (log1p, args, ,
01551     "-*- texinfo -*-\n\
01552 @deftypefn {Mapping Function} {} log1p (@var{x})\n\
01553 Compute\n\
01554 @tex\n\
01555 $\\ln{(1 + x)}$\n\
01556 @end tex\n\
01557 @ifnottex\n\
01558 @code{log (1 + @var{x})}\n\
01559 @end ifnottex\n\
01560 accurately in the neighborhood of zero.\n\
01561 @seealso{log, exp, expm1}\n\
01562 @end deftypefn")
01563 {
01564   octave_value retval;
01565   if (args.length () == 1)
01566     retval = args(0).log1p ();
01567   else
01568     print_usage ();
01569 
01570   return retval;
01571 }
01572 
01573 /*
01574 %!assert (log1p ([0, 2*eps, -2*eps]), [0, 2*eps, -2*eps], 1e-29)
01575 %!assert (log1p (single ([0, 2*eps, -2*eps])), single([0, 2*eps, -2*eps]), 1e-29)
01576 
01577 %!error log1p ()
01578 %!error log1p (1, 2)
01579 */
01580 
01581 DEFUN (real, args, ,
01582     "-*- texinfo -*-\n\
01583 @deftypefn {Mapping Function} {} real (@var{z})\n\
01584 Return the real part of @var{z}.\n\
01585 @seealso{imag, conj}\n\
01586 @end deftypefn")
01587 {
01588   octave_value retval;
01589   if (args.length () == 1)
01590     retval = args(0).real ();
01591   else
01592     print_usage ();
01593 
01594   return retval;
01595 }
01596 
01597 /*
01598 %!assert (real (1), 1)
01599 %!assert (real (i), 0)
01600 %!assert (real (1+i), 1)
01601 %!assert (real ([1, i; i, 1]), full (eye (2)))
01602 
01603 %!assert (real (single (1)), single (1))
01604 %!assert (real (single (i)), single (0))
01605 %!assert (real (single (1+i)), single (1))
01606 %!assert (real (single ([1, i; i, 1])), full (eye (2,'single')))
01607 
01608 %!error real ()
01609 %!error real (1, 2)
01610 */
01611 
01612 DEFUN (round, args, ,
01613     "-*- texinfo -*-\n\
01614 @deftypefn {Mapping Function} {} round (@var{x})\n\
01615 Return the integer nearest to @var{x}.  If @var{x} is complex, return\n\
01616 @code{round (real (@var{x})) + round (imag (@var{x})) * I}.  If there\n\
01617 are two nearest integers, return the one further away from zero.\n\
01618 \n\
01619 @example\n\
01620 @group\n\
01621 round ([-2.7, 2.7])\n\
01622      @result{} -3   3\n\
01623 @end group\n\
01624 @end example\n\
01625 @seealso{ceil, floor, fix, roundb}\n\
01626 @end deftypefn")
01627 {
01628   octave_value retval;
01629   if (args.length () == 1)
01630     retval = args(0).round ();
01631   else
01632     print_usage ();
01633 
01634   return retval;
01635 }
01636 
01637 /*
01638 %!assert (round (1), 1)
01639 %!assert (round (1.1), 1)
01640 %!assert (round (5.5), 6)
01641 %!assert (round (i), i)
01642 %!assert (round (2.5+3.5i), 3+4i)
01643 %!assert (round (-2.6), -3)
01644 %!assert (round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
01645 
01646 %!assert (round (single (1)), single (1))
01647 %!assert (round (single (1.1)), single (1))
01648 %!assert (round (single (5.5)), single (6))
01649 %!assert (round (single (i)), single (i))
01650 %!assert (round (single (2.5+3.5i)), single (3+4i))
01651 %!assert (round (single (-2.6)), single (-3))
01652 %!assert (round (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
01653 
01654 %!error round ()
01655 %!error round (1, 2)
01656 */
01657 
01658 DEFUN (roundb, args, ,
01659     "-*- texinfo -*-\n\
01660 @deftypefn {Mapping Function} {} roundb (@var{x})\n\
01661 Return the integer nearest to @var{x}.  If there are two nearest\n\
01662 integers, return the even one (banker's rounding).  If @var{x} is complex,\n\
01663 return @code{roundb (real (@var{x})) + roundb (imag (@var{x})) * I}.\n\
01664 @seealso{round}\n\
01665 @end deftypefn")
01666 {
01667   octave_value retval;
01668   if (args.length () == 1)
01669     retval = args(0).roundb ();
01670   else
01671     print_usage ();
01672 
01673   return retval;
01674 }
01675 
01676 /*
01677 %!assert (roundb (1), 1)
01678 %!assert (roundb (1.1), 1)
01679 %!assert (roundb (1.5), 2)
01680 %!assert (roundb (4.5), 4)
01681 %!assert (roundb (i), i)
01682 %!assert (roundb (2.5+3.5i), 2+4i)
01683 %!assert (roundb (-2.6), -3)
01684 %!assert (roundb ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
01685 
01686 %!assert (roundb (single (1)), single (1))
01687 %!assert (roundb (single (1.1)), single (1))
01688 %!assert (roundb (single (1.5)), single (2))
01689 %!assert (roundb (single (4.5)), single (4))
01690 %!assert (roundb (single (i)), single (i))
01691 %!assert (roundb (single (2.5+3.5i)), single (2+4i))
01692 %!assert (roundb (single (-2.6)), single (-3))
01693 %!assert (roundb (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
01694 
01695 %!error roundb ()
01696 %!error roundb (1, 2)
01697 */
01698 
01699 DEFUN (sign, args, ,
01700     "-*- texinfo -*-\n\
01701 @deftypefn {Mapping Function} {} sign (@var{x})\n\
01702 Compute the @dfn{signum} function, which is defined as\n\
01703 @tex\n\
01704 $$\n\
01705 {\\rm sign} (@var{x}) = \\cases{1,&$x>0$;\\cr 0,&$x=0$;\\cr -1,&$x<0$.\\cr}\n\
01706 $$\n\
01707 @end tex\n\
01708 @ifnottex\n\
01709 \n\
01710 @example\n\
01711 @group\n\
01712            -1, x < 0;\n\
01713 sign (x) =  0, x = 0;\n\
01714             1, x > 0.\n\
01715 @end group\n\
01716 @end example\n\
01717 \n\
01718 @end ifnottex\n\
01719 \n\
01720 For complex arguments, @code{sign} returns @code{x ./ abs (@var{x})}.\n\
01721 @end deftypefn")
01722 {
01723   octave_value retval;
01724   if (args.length () == 1)
01725     retval = args(0).signum ();
01726   else
01727     print_usage ();
01728 
01729   return retval;
01730 }
01731 
01732 /*
01733 %!assert (sign (-2) , -1)
01734 %!assert (sign (0), 0)
01735 %!assert (sign (3), 1)
01736 %!assert (sign ([1, -pi; e, 0]), [1, -1; 1, 0])
01737 
01738 %!assert (sign (single (-2)) , single (-1))
01739 %!assert (sign (single (0)), single (0))
01740 %!assert (sign (single (3)), single (1))
01741 %!assert (sign (single ([1, -pi; e, 0])), single ([1, -1; 1, 0]))
01742 
01743 %!error sign ()
01744 %!error sign (1, 2)
01745 */
01746 
01747 DEFUN (sin, args, ,
01748     "-*- texinfo -*-\n\
01749 @deftypefn {Mapping Function} {} sin (@var{x})\n\
01750 Compute the sine for each element of @var{x} in radians.\n\
01751 @seealso{asin, sind, sinh}\n\
01752 @end deftypefn")
01753 {
01754   octave_value retval;
01755   if (args.length () == 1)
01756     retval = args(0).sin ();
01757   else
01758     print_usage ();
01759 
01760   return retval;
01761 }
01762 
01763 /*
01764 %!shared rt2, rt3
01765 %! rt2 = sqrt (2);
01766 %! rt3 = sqrt (3);
01767 
01768 %!test
01769 %! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
01770 %! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
01771 %! assert (sin (x), v, sqrt (eps));
01772 
01773 %!test
01774 %! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
01775 %! v = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
01776 %! assert (sin (x), v, sqrt (eps ('single')));
01777 
01778 %!error sin ()
01779 %!error sin (1, 2)
01780 */
01781 
01782 DEFUN (sinh, args, ,
01783     "-*- texinfo -*-\n\
01784 @deftypefn {Mapping Function} {} sinh (@var{x})\n\
01785 Compute the hyperbolic sine for each element of @var{x}.\n\
01786 @seealso{asinh, cosh, tanh}\n\
01787 @end deftypefn")
01788 {
01789   octave_value retval;
01790   if (args.length () == 1)
01791     retval = args(0).sinh ();
01792   else
01793     print_usage ();
01794 
01795   return retval;
01796 }
01797 
01798 /*
01799 %!test
01800 %! x = [0, pi/2*i, pi*i, 3*pi/2*i];
01801 %! v = [0, i, 0, -i];
01802 %! assert (sinh (x), v, sqrt (eps));
01803 
01804 %!test
01805 %! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
01806 %! v = single ([0, i, 0, -i]);
01807 %! assert (sinh (x), v, sqrt (eps ('single')));
01808 
01809 %!error sinh ()
01810 %!error sinh (1, 2)
01811 */
01812 
01813 DEFUN (sqrt, args, ,
01814     "-*- texinfo -*-\n\
01815 @deftypefn {Mapping Function} {} sqrt (@var{x})\n\
01816 Compute the square root of each element of @var{x}.  If @var{x} is negative,\n\
01817 a complex result is returned.  To compute the matrix square root, see\n\
01818 @ref{Linear Algebra}.\n\
01819 @seealso{realsqrt, nthroot}\n\
01820 @end deftypefn")
01821 {
01822   octave_value retval;
01823   if (args.length () == 1)
01824     retval = args(0).sqrt ();
01825   else
01826     print_usage ();
01827 
01828   return retval;
01829 }
01830 
01831 /*
01832 %!assert (sqrt (4), 2)
01833 %!assert (sqrt (-1), i)
01834 %!assert (sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps))
01835 %!assert (sqrt ([4, -4; i, 1-i]), [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt (eps))
01836 
01837 %!assert (sqrt (single (4)), single (2))
01838 %!assert (sqrt (single (-1)), single (i))
01839 %!assert (sqrt (single (1+i)), single (exp (0.5 * log (1+i))), sqrt (eps ('single')))
01840 %!assert (sqrt (single ([4, -4; i, 1-i])), single ([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]), sqrt (eps ('single')))
01841 
01842 %!error sqrt ()
01843 %!error sqrt (1, 2)
01844 */
01845 
01846 DEFUN (tan, args, ,
01847     "-*- texinfo -*-\n\
01848 @deftypefn {Mapping Function} {} tan (@var{z})\n\
01849 Compute the tangent for each element of @var{x} in radians.\n\
01850 @seealso{atan, tand, tanh}\n\
01851 @end deftypefn")
01852 {
01853   octave_value retval;
01854   if (args.length () == 1)
01855     retval = args(0).tan ();
01856   else
01857     print_usage ();
01858 
01859   return retval;
01860 }
01861 
01862 /*
01863 %!shared rt2, rt3
01864 %! rt2 = sqrt (2);
01865 %! rt3 = sqrt (3);
01866 
01867 %!test
01868 %! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
01869 %! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
01870 %! assert (tan (x), v,  sqrt (eps));
01871 
01872 %!test
01873 %! x = single ([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
01874 %! v = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
01875 %! assert (tan (x), v,  sqrt (eps ('single')));
01876 
01877 %!error tan ()
01878 %!error tan (1, 2)
01879 */
01880 
01881 DEFUN (tanh, args, ,
01882     "-*- texinfo -*-\n\
01883 @deftypefn {Mapping Function} {} tanh (@var{x})\n\
01884 Compute hyperbolic tangent for each element of @var{x}.\n\
01885 @seealso{atanh, sinh, cosh}\n\
01886 @end deftypefn")
01887 {
01888   octave_value retval;
01889   if (args.length () == 1)
01890     retval = args(0).tanh ();
01891   else
01892     print_usage ();
01893 
01894   return retval;
01895 }
01896 
01897 /*
01898 %!test
01899 %! x = [0, pi*i];
01900 %! v = [0, 0];
01901 %! assert (tanh (x), v, sqrt (eps));
01902 
01903 %!test
01904 %! x = single ([0, pi*i]);
01905 %! v = single ([0, 0]);
01906 %! assert (tanh (x), v, sqrt (eps ('single')));
01907 
01908 %!error tanh ()
01909 %!error tanh (1, 2)
01910 */
01911 
01912 DEFUNX ("toascii", Ftoascii, args, ,
01913     "-*- texinfo -*-\n\
01914 @deftypefn {Mapping Function} {} toascii (@var{s})\n\
01915 Return ASCII representation of @var{s} in a matrix.  For example:\n\
01916 \n\
01917 @example\n\
01918 @group\n\
01919 toascii (\"ASCII\")\n\
01920      @result{} [ 65, 83, 67, 73, 73 ]\n\
01921 @end group\n\
01922 \n\
01923 @end example\n\
01924 @seealso{char}\n\
01925 @end deftypefn")
01926 {
01927   octave_value retval;
01928   if (args.length () == 1)
01929     retval = args(0).xtoascii ();
01930   else
01931     print_usage ();
01932 
01933   return retval;
01934 }
01935 
01936 /*
01937 %!assert (toascii (char (0:127)), 0:127)
01938 %!assert (toascii (" ":"@"), 32:64)
01939 %!assert (toascii ("A":"Z"), 65:90)
01940 %!assert (toascii ("[":"`"), 91:96)
01941 %!assert (toascii ("a":"z"), 97:122)
01942 %!assert (toascii ("{":"~"), 123:126)
01943 
01944 %!error toascii ()
01945 %!error toascii (1, 2)
01946 */
01947 
01948 DEFUNX ("tolower", Ftolower, args, ,
01949     "-*- texinfo -*-\n\
01950 @deftypefn  {Mapping Function} {} tolower (@var{s})\n\
01951 @deftypefnx {Mapping Function} {} lower (@var{s})\n\
01952 Return a copy of the string or cell string @var{s}, with each uppercase\n\
01953 character replaced by the corresponding lowercase one; non-alphabetic\n\
01954 characters are left unchanged.  For example:\n\
01955 \n\
01956 @example\n\
01957 @group\n\
01958 tolower (\"MiXeD cAsE 123\")\n\
01959      @result{} \"mixed case 123\"\n\
01960 @end group\n\
01961 @end example\n\
01962 @seealso{toupper}\n\
01963 @end deftypefn")
01964 {
01965   octave_value retval;
01966   if (args.length () == 1)
01967     retval = args(0).xtolower ();
01968   else
01969     print_usage ();
01970 
01971   return retval;
01972 }
01973 
01974 DEFALIAS (lower, tolower);
01975 
01976 /*
01977 %!assert (tolower("OCTAVE"), "octave")
01978 %!assert (tolower("123OCTave!_&"), "123octave!_&")
01979 %!assert (tolower({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}})
01980 %!assert (tolower(["ABC"; "DEF"]), ["abc"; "def"])
01981 %!assert (tolower({["ABC"; "DEF"]}), {["abc";"def"]})
01982 %!assert (tolower(68), "d")
01983 %!assert (tolower({[68, 68; 68, 68]}), {["dd";"dd"]})
01984 %!test
01985 %!  a(3,3,3,3) = "D";
01986 %!  assert(tolower(a)(3,3,3,3), "d");
01987 
01988 %!test
01989 %! charset = char (0:127);
01990 %! result = charset;
01991 %! result(toascii ("A":"Z") + 1) = result(toascii ("a":"z") + 1);
01992 %! assert (all (tolower (charset) == result));
01993 
01994 %!error <Invalid call to tolower> tolower()
01995 %!error <Invalid call to tolower> lower()
01996 %!error tolower (1, 2)
01997 */
01998 
01999 DEFUNX ("toupper", Ftoupper, args, ,
02000     "-*- texinfo -*-\n\
02001 @deftypefn  {Mapping Function} {} toupper (@var{s})\n\
02002 @deftypefnx {Mapping Function} {} upper (@var{s})\n\
02003 Return a copy of the string or cell string @var{s}, with each lowercase\n\
02004 character replaced by the corresponding uppercase one; non-alphabetic\n\
02005 characters are left unchanged.  For example:\n\
02006 \n\
02007 @example\n\
02008 @group\n\
02009 toupper (\"MiXeD cAsE 123\")\n\
02010      @result{} \"MIXED CASE 123\"\n\
02011 @end group\n\
02012 @end example\n\
02013 @seealso{tolower}\n\
02014 @end deftypefn")
02015 {
02016   octave_value retval;
02017   if (args.length () == 1)
02018     retval = args(0).xtoupper ();
02019   else
02020     print_usage ();
02021 
02022   return retval;
02023 }
02024 
02025 DEFALIAS (upper, toupper);
02026 
02027 /*
02028 %!assert (toupper ("octave"), "OCTAVE")
02029 %!assert (toupper ("123OCTave!_&"), "123OCTAVE!_&")
02030 %!assert (toupper ({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI", {"JKL"}}})
02031 %!assert (toupper (["abc"; "def"]), ["ABC"; "DEF"])
02032 %!assert (toupper ({["abc"; "def"]}), {["ABC";"DEF"]})
02033 %!assert (toupper (100), "D")
02034 %!assert (toupper ({[100, 100; 100, 100]}), {["DD";"DD"]})
02035 %!test
02036 %!  a(3,3,3,3) = "d";
02037 %!  assert(toupper (a)(3,3,3,3), "D");
02038 %!test
02039 %! charset = char (0:127);
02040 %! result = charset;
02041 %! result(toascii  ("a":"z") + 1) = result(toascii  ("A":"Z") + 1);
02042 %! assert (all (toupper (charset) == result));
02043 
02044 %!error <Invalid call to toupper> toupper()
02045 %!error <Invalid call to toupper> upper()
02046 %!error toupper (1, 2)
02047 */
02048 
02049 DEFALIAS (gammaln, lgamma);
02050 
02051 DEFALIAS (finite, isfinite);
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines