changelog shortlog tags changeset files revisions annotate raw

src/mappers.cc

changeset 10289: 4b124317dc38
parent:44e889c67abe
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (36 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1/*
2
3Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
5
6This file is part of Octave.
7
8Octave is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 3 of the License, or (at your
11option) any later version.
12
13Octave is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with Octave; see the file COPYING. If not, see
20<http://www.gnu.org/licenses/>.
21
22*/
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <cctype>
29#include <cfloat>
30
31#include "lo-ieee.h"
32#include "lo-specfun.h"
33#include "lo-mappers.h"
34
35#include "defun.h"
36#include "error.h"
37#include "variables.h"
38
39DEFUN (abs, args, ,
40 "-*- texinfo -*-\n\
41@deftypefn {Mapping Function} {} abs (@var{z})\n\
42Compute the magnitude of @var{z}, defined as\n\
43@tex\n\
44$|z| = \\sqrt{x^2 + y^2}$.\n\
45@end tex\n\
46@ifnottex\n\
47|@var{z}| = @code{sqrt (x^2 + y^2)}.\n\
48@end ifnottex\n\
49\n\
50For example,\n\
51\n\
52@example\n\
53@group\n\
54abs (3 + 4i)\n\
55 @result{} 5\n\
56@end group\n\
57@end example\n\
58@end deftypefn")
59{
60 octave_value retval;
61 if (args.length () == 1)
62 retval = args(0).abs ();
63 else
64 print_usage ();
65
66 return retval;
67}
68
69/*
70
71%!assert(abs (1), 1);
72%!assert(abs (-3.5), 3.5);
73%!assert(abs (3+4i), 5);
74%!assert(abs (3-4i), 5);
75%!assert(abs ([1.1, 3i; 3+4i, -3-4i]), [1.1, 3; 5, 5]);
76
77%!assert(abs (single(1)), single(1));
78%!assert(abs (single(-3.5)), single(3.5));
79%!assert(abs (single(3+4i)), single(5));
80%!assert(abs (single(3-4i)), single(5));
81%!assert(abs (single([1.1, 3i; 3+4i, -3-4i])), single([1.1, 3; 5, 5]));
82
83%!error abs ();
84%!error abs (1, 2);
85
86 */
87
88DEFUN (acos, args, ,
89 "-*- texinfo -*-\n\
90@deftypefn {Mapping Function} {} acos (@var{x})\n\
91Compute the inverse cosine in radians for each element of @var{x}.\n\
92@seealso{cos, acosd}\n\
93@end deftypefn")
94{
95 octave_value retval;
96 if (args.length () == 1)
97 retval = args(0).acos ();
98 else
99 print_usage ();
100
101 return retval;
102}
103
104/*
105
106%!test
107%! rt2 = sqrt (2);
108%! rt3 = sqrt (3);
109%! v = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
110%! x = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
111%! assert(acos (x), v, sqrt(eps));
112
113%!test
114%! rt2 = sqrt (2);
115%! rt3 = sqrt (3);
116%! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
117%! x = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
118%! assert(acos (x), v, sqrt(eps('single')));
119
120%!error acos ();
121%!error acos (1, 2);
122
123*/
124
125DEFUN (acosh, args, ,
126 "-*- texinfo -*-\n\
127@deftypefn {Mapping Function} {} acosh (@var{x})\n\
128Compute the inverse hyperbolic cosine for each element of @var{x}.\n\
129@seealso{cosh}\n\
130@end deftypefn")
131{
132 octave_value retval;
133 if (args.length () == 1)
134 retval = args(0).acosh ();
135 else
136 print_usage ();
137
138 return retval;
139}
140
141/*
142
143%!test
144%! v = [0, pi/2*i, pi*i, pi/2*i];
145%! x = [1, 0, -1, 0];
146%! assert(acosh (x), v, sqrt(eps));
147
148%!test
149%! v = single([0, pi/2*i, pi*i, pi/2*i]);
150%! x = single([1, 0, -1, 0]);
151%! assert(acosh (x), v, sqrt (eps('single')));
152
153%!error acosh ();
154%!error acosh (1, 2);
155
156*/
157
158DEFUN (angle, args, ,
159 "-*- texinfo -*-\n\
160@deftypefn {Mapping Function} {} angle (@var{z})\n\
161See arg.\n\
162@end deftypefn")
163{
164 octave_value retval;
165 if (args.length () == 1)
166 retval = args(0).arg ();
167 else
168 print_usage ();
169
170 return retval;
171}
172
173DEFUN (arg, args, ,
174 "-*- texinfo -*-\n\
175@deftypefn {Mapping Function} {} arg (@var{z})\n\
176@deftypefnx {Mapping Function} {} angle (@var{z})\n\
177Compute the argument of @var{z}, defined as,\n\
178@tex\n\
179$\\theta = atan2 (y, x),$\n\
180@end tex\n\
181@ifnottex\n\
182@var{theta} = @code{atan2 (@var{y}, @var{x})},\n\
183@end ifnottex\n\
184in radians.\n\
185\n\
186For example,\n\
187\n\
188@example\n\
189@group\n\
190arg (3 + 4i)\n\
191 @result{} 0.92730\n\
192@end group\n\
193@end example\n\
194@end deftypefn")
195{
196 octave_value retval;
197 if (args.length () == 1)
198 retval = args(0).arg ();
199 else
200 print_usage ();
201
202 return retval;
203}
204
205/*
206
207%!assert(arg (1), 0);
208%!assert(arg (i), pi/2);
209%!assert(arg (-1), pi);
210%!assert(arg (-i), -pi/2);
211%!assert(arg ([1, i; -1, -i]), [0, pi/2; pi, -pi/2]);
212
213%!assert(arg (single(1)), single(0));
214%!assert(arg (single(i)), single(pi/2));
215%!assert(arg (single(-1)), single(pi));
216%!assert(arg (single(-i)), single(-pi/2));
217%!assert(arg (single([1, i; -1, -i])), single([0, pi/2; pi, -pi/2]), 2e1*eps('single'));
218
219%!error arg ();
220%!error arg (1, 2);
221
222*/
223
224DEFUN (asin, args, ,
225 "-*- texinfo -*-\n\
226@deftypefn {Mapping Function} {} asin (@var{x})\n\
227Compute the inverse sine in radians for each element of @var{x}.\n\
228@seealso{sin, asind}\n\
229@end deftypefn")
230{
231 octave_value retval;
232 if (args.length () == 1)
233 retval = args(0).asin ();
234 else
235 print_usage ();
236
237 return retval;
238}
239
240/*
241%!test
242%! rt2 = sqrt (2);
243%! rt3 = sqrt (3);
244%! v = [0, pi/6, pi/4, pi/3, pi/2, pi/3, pi/4, pi/6, 0];
245%! x = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
246%! assert(all (abs (asin (x) - v) < sqrt (eps)));
247%!error asin ();
248%!error asin (1, 2);
249*/
250
251DEFUN (asinh, args, ,
252 "-*- texinfo -*-\n\
253@deftypefn {Mapping Function} {} asinh (@var{x})\n\
254Compute the inverse hyperbolic sine for each element of @var{x}.\n\
255@seealso{sinh}\n\
256@end deftypefn")
257{
258 octave_value retval;
259 if (args.length () == 1)
260 retval = args(0).asinh ();
261 else
262 print_usage ();
263
264 return retval;
265}
266
267/*
268
269%!test
270%! v = [0, pi/2*i, 0, -pi/2*i];
271%! x = [0, i, 0, -i];
272%! assert(asinh (x), v, sqrt (eps));
273
274%!test
275%! v = single([0, pi/2*i, 0, -pi/2*i]);
276%! x = single([0, i, 0, -i]);
277%! assert(asinh (x), v, sqrt (eps('single')));
278
279%!error asinh ();
280%!error asinh (1, 2);
281
282*/
283
284DEFUN (atan, args, ,
285 "-*- texinfo -*-\n\
286@deftypefn {Mapping Function} {} atan (@var{x})\n\
287Compute the inverse tangent in radians for each element of @var{x}.\n\
288@seealso{tan, atand}\n\
289@end deftypefn")
290{
291 octave_value retval;
292 if (args.length () == 1)
293 retval = args(0).atan ();
294 else
295 print_usage ();
296
297 return retval;
298}
299
300/*
301
302%!test
303%! rt2 = sqrt (2);
304%! rt3 = sqrt (3);
305%! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
306%! x = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
307%! assert(atan (x), v, sqrt (eps));
308
309%!test
310%! rt2 = sqrt (2);
311%! rt3 = sqrt (3);
312%! v = single([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
313%! x = single([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
314%! assert(atan (x), v, sqrt (eps('single')));
315
316%!error atan ();
317%!error atan (1, 2);
318
319 */
320
321DEFUN (atanh, args, ,
322 "-*- texinfo -*-\n\
323@deftypefn {Mapping Function} {} atanh (@var{x})\n\
324Compute the inverse hyperbolic tangent for each element of @var{x}.\n\
325@seealso{tanh}\n\
326@end deftypefn")
327{
328 octave_value retval;
329 if (args.length () == 1)
330 retval = args(0).atanh ();
331 else
332 print_usage ();
333
334 return retval;
335}
336
337/*
338
339%!test
340%! v = [0, 0];
341%! x = [0, 0];
342%! assert(atanh (x), v, sqrt (eps));
343
344%!test
345%! v = single([0, 0]);
346%! x = single([0, 0]);
347%! assert(atanh (x), v, sqrt (eps('single')));
348
349%!error atanh ();
350%!error atanh (1, 2);
351
352*/
353
354DEFUN (ceil, args, ,
355 "-*- texinfo -*-\n\
356@deftypefn {Mapping Function} {} ceil (@var{x})\n\
357Return the smallest integer not less than @var{x}. This is equivalent to\n\
358rounding towards positive infinity. If @var{x} is\n\
359complex, return @code{ceil (real (@var{x})) + ceil (imag (@var{x})) * I}.\n\
360@example\n\
361@group\n\
362ceil ([-2.7, 2.7])\n\
363 @result{} -2 3\n\
364@end group\n\
365@end example\n\
366@seealso{floor, round, fix}\n\
367@end deftypefn")
368{
369 octave_value retval;
370 if (args.length () == 1)
371 retval = args(0).ceil ();
372 else
373 print_usage ();
374
375 return retval;
376}
377
378/*
379
380%% double precision
381%!assert(ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1]);
382
383%% compelx double precison
384%!assert(ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i]);
385
386%% single precision
387%!assert(ceil (single([2, 1.1, -1.1, -1])), single([2, 2, -1, -1]));
388
389%% compelx single preci
390%!assert(ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single([2+2i, 2+2i, -1-i, -1-i]));
391
392%!error ceil ();
393%!error ceil (1, 2);
394
395*/
396
397DEFUN (conj, args, ,
398 "-*- texinfo -*-\n\
399@deftypefn {Mapping Function} {} conj (@var{z})\n\
400Return the complex conjugate of @var{z}, defined as\n\
401@tex\n\
402$\\bar{z} = x - iy$.\n\
403@end tex\n\
404@ifnottex\n\
405@code{conj (@var{z})} = @var{x} - @var{i}@var{y}.\n\
406@end ifnottex\n\
407@seealso{real, imag}\n\
408@end deftypefn")
409{
410 octave_value retval;
411 if (args.length () == 1)
412 retval = args(0).conj ();
413 else
414 print_usage ();
415
416 return retval;
417}
418
419/*
420
421%!assert(conj (1), 1);
422%!assert(conj (i), -i)
423%!assert(conj (1+i), 1-i)
424%!assert(conj (1-i), 1+i)
425%!assert(conj ([-1, -i; -1+i, -1-i]), [-1, i; -1-i, -1+i]);
426
427%!assert(conj (single(1)), single(1));
428%!assert(conj (single(i)), single(-i))
429%!assert(conj (single(1+i)), single(1-i))
430%!assert(conj (single(1-i)), single(1+i))
431%!assert(conj (single([-1, -i; -1+i, -1-i])), single([-1, i; -1-i, -1+i]));
432
433%!error conj ();
434%!error conj (1, 2);
435
436*/
437
438DEFUN (cos, args, ,
439 "-*- texinfo -*-\n\
440@deftypefn {Mapping Function} {} cos (@var{x})\n\
441Compute the cosine for each element of @var{x} in radians.\n\
442@seealso{acos, cosd, cosh}\n\
443@end deftypefn")
444{
445 octave_value retval;
446 if (args.length () == 1)
447 retval = args(0).cos ();
448 else
449 print_usage ();
450
451 return retval;
452}
453
454/*
455
456%!test
457%! rt2 = sqrt (2);
458%! rt3 = sqrt (3);
459%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
460%! v = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
461%! assert(cos (x), v, sqrt (eps));
462
463%!test
464%! rt2 = sqrt (2);
465%! rt3 = sqrt (3);
466%! x = single([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
467%! v = single([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
468%! assert(cos (x), v, sqrt (eps('single')));
469
470%!error cos ();
471%!error cos (1, 2);
472
473 */
474
475DEFUN (cosh, args, ,
476 "-*- texinfo -*-\n\
477@deftypefn {Mapping Function} {} cosh (@var{x})\n\
478Compute the hyperbolic cosine for each element of @var{x}.\n\
479@seealso{acosh, sinh, tanh}\n\
480@end deftypefn")
481{
482 octave_value retval;
483 if (args.length () == 1)
484 retval = args(0).cosh ();
485 else
486 print_usage ();
487
488 return retval;
489}
490
491/*
492
493%!test
494%! x = [0, pi/2*i, pi*i, 3*pi/2*i];
495%! v = [1, 0, -1, 0];
496%! assert(cosh (x), v, sqrt (eps));
497
498%!test
499%! x = single([0, pi/2*i, pi*i, 3*pi/2*i]);
500%! v = single([1, 0, -1, 0]);
501%! assert(cosh (x), v, sqrt (eps ('single')));
502
503%!error cosh ();
504%!error cosh (1, 2);
505
506*/
507
508DEFUN (erf, args, ,
509 "-*- texinfo -*-\n\
510@deftypefn {Mapping Function} {} erf (@var{z})\n\
511Computes the error function,\n\
512@tex\n\
513$$\n\
514 {\\rm erf} (z) = {2 \\over \\sqrt{\\pi}}\\int_0^z e^{-t^2} dt\n\
515$$\n\
516@end tex\n\
517@ifnottex\n\
518\n\
519@example\n\
520@group\n\
521 z\n\
522 /\n\
523erf (z) = (2/sqrt (pi)) | e^(-t^2) dt\n\
524 /\n\
525 t=0\n\
526@end group\n\
527@end example\n\
528@end ifnottex\n\
529@seealso{erfc, erfinv}\n\
530@end deftypefn")
531{
532 octave_value retval;
533 if (args.length () == 1)
534 retval = args(0).erf ();
535 else
536 print_usage ();
537
538 return retval;
539}
540
541/*
542
543%!test
544%! a = -1i*sqrt(-1/(6.4187*6.4187));
545%! assert (erf(a), erf(real(a)));
546
547%!test
548%! x=[0,.5,1];
549%! v=[0, .520499877813047, .842700792949715];
550%! assert(all(abs(erf(x)-v)<1.e-10) && all(abs(erf(-x)+v)<1.e-10) && all(abs(erfc(x)+v-1)<1.e-10) && all(abs(erfinv(v)-x)<1.e-10));
551
552%!test
553%! a = -1i*sqrt(single (-1/(6.4187*6.4187)));
554%! assert (erf(a), erf(real(a)));
555
556%!test
557%! x=single ([0,.5,1]);
558%! v=single ([0, .520499877813047, .842700792949715]);
559%! assert(all(abs(erf(x)-v)<1.e-6) && all(abs(erf(-x)+v)<1.e-6) && all(abs(erfc(x)+v-1)<1.e-6) && all(abs(erfinv(v)-x)<1.e-6));
560
561%% test/octave.test/arith/erf-2.m
562%!error erf();
563
564%% test/octave.test/arith/erf-3.m
565%!error erf(1,2);
566
567
568
569*/
570
571DEFUN (erfinv, args, ,
572 "-*- texinfo -*-\n\
573@deftypefn {Mapping Function} {} erfinv (@var{x})\n\
574Computes the inverse error function, i.e. @var{y} such that\n\
575@example\n\
576 erf(@var{y}) == @var{x}\n\
577@end example\n\
578@seealso{erfc, erf}\n\
579@end deftypefn")
580{
581 octave_value retval;
582 if (args.length () == 1)
583 retval = args(0).erfinv ();
584 else
585 print_usage ();
586
587 return retval;
588}
589
590/*
591%% middle region
592%!assert (erf (erfinv ([-0.9 -0.3 0 0.4 0.8])), [-0.9 -0.3 0 0.4 0.8], eps)
593%!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)
594%% tail region
595%!assert (erf (erfinv ([-0.999 -0.99 0.9999 0.99999])), [-0.999 -0.99 0.9999 0.99999], eps)
596%!assert (erf (erfinv (single ([-0.999 -0.99 0.9999 0.99999]))), single ([-0.999 -0.99 0.9999 0.99999]), 1e-8)
597%% backward - loss of accuracy
598%!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)
599%!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)
600%% exceptional
601%!assert (erfinv ([-1, 1, 1.1, -2.1]), [-Inf, Inf, NaN, NaN])
602%!error erfinv (1+2i)
603*/
604
605DEFUN (erfc, args, ,
606 "-*- texinfo -*-\n\
607@deftypefn {Mapping Function} {} erfc (@var{z})\n\
608Computes the complementary error function,\n\
609@tex\n\
610$1 - {\\rm erf} (z)$.\n\
611@end tex\n\
612@ifnottex\n\
613@code{1 - erf (@var{z})}.\n\
614@end ifnottex\n\
615@seealso{erf, erfinv}\n\
616@end deftypefn")
617{
618 octave_value retval;
619 if (args.length () == 1)
620 retval = args(0).erfc ();
621 else
622 print_usage ();
623
624 return retval;
625}
626
627/*
628
629%!test
630%! a = -1i*sqrt(-1/(6.4187*6.4187));
631%! assert (erfc(a), erfc(real(a)));
632
633*/
634
635DEFUN (exp, args, ,
636 "-*- texinfo -*-\n\
637@deftypefn {Mapping Function} {} exp (@var{x})\n\
638Compute\n\
639@tex\n\
640$e^{x}$\n\
641@end tex\n\
642@ifnottex\n\
643@code{e^x}\n\
644@end ifnottex\n\
645for each element of @var{x}. To compute the matrix\n\
646exponential, see @ref{Linear Algebra}.\n\
647@seealso{log}\n\
648@end deftypefn")
649{
650 octave_value retval;
651 if (args.length () == 1)
652 retval = args(0).exp ();
653 else
654 print_usage ();
655
656 return retval;
657}
658
659/*
660
661%!assert(exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps));
662%!assert(exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps));
663%!assert(exp (single([0, 1, -1, -1000])), single([1, e, 1/e, 0]), sqrt (eps('single')));
664%!assert(exp (single(1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps('single')));
665
666%!error exp ();
667%!error exp (1, 2);
668
669%!assert(exp (Inf) == Inf && exp (-Inf) == 0 && isnan (exp (NaN)));
670%!assert(exp (Inf ('single')) == Inf('single') && exp (-Inf('single')) == 0 && isnan (exp (NaN('single'))));
671
672*/
673
674DEFUN (expm1, args, ,
675 "-*- texinfo -*-\n\
676@deftypefn {Mapping Function} {} expm1 (@var{x})\n\
677Compute\n\
678@tex\n\
679$ e^{x} - 1 $\n\
680@end tex\n\
681@ifnottex\n\
682@code{exp (@var{x}) - 1}\n\
683@end ifnottex\n\
684accurately in the neighborhood of zero.\n\
685@seealso{exp}\n\
686@end deftypefn")
687{
688 octave_value retval;
689 if (args.length () == 1)
690 retval = args(0).expm1 ();
691 else
692 print_usage ();
693
694 return retval;
695}
696
697DEFUN (finite, args, ,
698 "-*- texinfo -*-\n\
699@deftypefn {Mapping Function} {} finite (@var{x})\n\
700Return 1 for elements of @var{x} that are finite values and zero\n\
701otherwise. For example,\n\
702\n\
703@example\n\
704@group\n\
705finite ([13, Inf, NA, NaN])\n\
706 @result{} [ 1, 0, 0, 0 ]\n\
707@end group\n\
708@end example\n\
709@end deftypefn")
710{
711 octave_value retval;
712 if (args.length () == 1)
713 retval = args(0).finite ();
714 else
715 print_usage ();
716
717 return retval;
718}
719
720/*
721
722%!assert(!(finite (Inf)));
723%!assert(!(finite (NaN)));
724%!assert(finite (rand(1,10)));
725
726%!assert(!(finite (single(Inf))));
727%!assert(!(finite (single(NaN))));
728%!assert(finite (single(rand(1,10))));
729
730 */
731
732DEFUN (fix, args, ,
733 "-*- texinfo -*-\n\
734@deftypefn {Mapping Function} {} fix (@var{x})\n\
735Truncate fractional portion of @var{x} and return the integer portion. This\n\
736is equivalent to rounding towards zero. If @var{x} is complex, return\n\
737@code{fix (real (@var{x})) + fix (imag (@var{x})) * I}.\n\
738@example\n\
739@group\n\
740fix ([-2.7, 2.7])\n\
741 @result{} -2 2\n\
742@end group\n\
743@end example\n\
744@seealso{ceil, floor, round}\n\
745@end deftypefn")
746{
747 octave_value retval;
748 if (args.length () == 1)
749 retval = args(0).fix ();
750 else
751 print_usage ();
752
753 return retval;
754}
755
756/*
757
758%!assert(fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1]);
759%!assert(fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i]);
760%!assert(fix (single([1.1, 1, -1.1, -1])), single([1, 1, -1, -1]));
761%!assert(fix (single([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])), single([1+i, 1+i, -1-i, -1-i]));
762
763%!error fix ();
764%!error fix (1, 2);
765
766*/
767
768DEFUN (floor, args, ,
769 "-*- texinfo -*-\n\
770@deftypefn {Mapping Function} {} floor (@var{x})\n\
771Return the largest integer not greater than @var{x}. This is equivalent to\n\
772rounding towards negative infinity. If @var{x} is\n\
773complex, return @code{floor (real (@var{x})) + floor (imag (@var{x})) * I}.\n\
774@example\n\
775@group\n\
776floor ([-2.7, 2.7])\n\
777 @result{} -3 2\n\
778@end group\n\
779@end example\n\
780@seealso{ceil, round, fix}\n\
781@end deftypefn")
782{
783 octave_value retval;
784 if (args.length () == 1)
785 retval = args(0).floor ();
786 else
787 print_usage ();
788
789 return retval;
790}
791
792/*
793
794%!assert(floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1]);
795%!assert(floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i]);
796%!assert(floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]));
797%!assert(floor (single([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single([2+2i, 1+i, -2-2i, -1-i]));
798
799%!error floor ();
800%!error floor (1, 2);
801
802*/
803
804DEFUN (gamma, args, ,
805 "-*- texinfo -*-\n\
806@deftypefn {Mapping Function} {} gamma (@var{z})\n\
807Computes the Gamma function,\n\
808@tex\n\
809$$\n\
810 \\Gamma (z) = \\int_0^\\infty t^{z-1} e^{-t} dt.\n\
811$$\n\
812@end tex\n\
813@ifnottex\n\
814\n\
815@example\n\
816@group\n\
817 infinity\n\
818 /\n\
819gamma (z) = | t^(z-1) exp (-t) dt.\n\
820 /\n\
821 t=0\n\
822@end group\n\
823@end example\n\
824@end ifnottex\n\
825@seealso{gammainc, lgamma}\n\
826@end deftypefn")
827{
828 octave_value retval;
829 if (args.length () == 1)
830 retval = args(0).gamma ();
831 else
832 print_usage ();
833
834 return retval;
835}
836
837/*
838
839%!test
840%! a = -1i*sqrt(-1/(6.4187*6.4187));
841%! assert (gamma(a), gamma(real(a)));
842
843%!test
844%! x = [.5, 1, 1.5, 2, 3, 4, 5];
845%! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
846%! assert(gamma(x), v, sqrt(eps))
847
848%!test
849%! a = single(-1i*sqrt(-1/(6.4187*6.4187)));
850%! assert (gamma(a), gamma(real(a)));
851
852%!test
853%! x = single([.5, 1, 1.5, 2, 3, 4, 5]);
854%! v = single([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
855%! assert(gamma(x), v, sqrt(eps('single')))
856
857%!error gamma();
858%!error gamma(1,2);
859
860*/
861
862DEFUN (imag, args, ,
863 "-*- texinfo -*-\n\
864@deftypefn {Mapping Function} {} imag (@var{z})\n\
865Return the imaginary part of @var{z} as a real number.\n\
866@seealso{real, conj}\n\
867@end deftypefn")
868{
869 octave_value retval;
870 if (args.length () == 1)
871 retval = args(0).imag ();
872 else
873 print_usage ();
874
875 return retval;
876}
877
878/*
879
880%!assert(imag (1), 0);
881%!assert(imag (i), 1);
882%!assert(imag (1+i), 1);
883%!assert(imag ([i, 1; 1, i]), full (eye (2)));
884
885%!assert(imag (single(1)), single(0));
886%!assert(imag (single(i)), single(1));
887%!assert(imag (single(1+i)), single(1));
888%!assert(imag (single([i, 1; 1, i])), full (eye (2,'single')));
889
890%!error imag ();
891%!error imag (1, 2);
892
893 */
894
895DEFUNX ("isalnum", Fisalnum, args, ,
896 "-*- texinfo -*-\n\
897@deftypefn {Mapping Function} {} isalnum (@var{s})\n\
898Return 1 for characters that are letters or digits (@code{isalpha\n\
899(@var{s})} or @code{isdigit (@var{s})} is true).\n\
900@end deftypefn")
901{
902 octave_value retval;
903 if (args.length () == 1)
904 retval = args(0).xisalnum ();
905 else
906 print_usage ();
907
908 return retval;
909}
910
911DEFUNX ("isalpha", Fisalpha, args, ,
912 "-*- texinfo -*-\n\
913@deftypefn {Mapping Function} {} isalpha (@var{s})\n\
914@deftypefnx {Mapping Function} {} isletter (@var{s})\n\
915Return true for characters that are letters (@code{isupper (@var{s})}\n\
916or @code{islower (@var{s})} is true).\n\
917@end deftypefn")
918{
919 octave_value retval;
920 if (args.length () == 1)
921 retval = args(0).xisalpha ();
922 else
923 print_usage ();
924
925 return retval;
926}
927
928DEFUNX ("isascii", Fisascii, args, ,
929 "-*- texinfo -*-\n\
930@deftypefn {Mapping Function} {} isascii (@var{s})\n\
931Return 1 for characters that are ASCII (in the range 0 to 127 decimal).\n\
932@end deftypefn")
933{
934 octave_value retval;
935 if (args.length () == 1)
936 retval = args(0).xisascii ();
937 else
938 print_usage ();
939
940 return retval;
941}
942
943DEFUNX ("iscntrl", Fiscntrl, args, ,
944 "-*- texinfo -*-\n\
945@deftypefn {Mapping Function} {} iscntrl (@var{s})\n\
946Return 1 for control characters.\n\
947@end deftypefn")
948{
949 octave_value retval;
950 if (args.length () == 1)
951 retval = args(0).xiscntrl ();
952 else
953 print_usage ();
954
955 return retval;
956}
957
958DEFUNX ("isdigit", Fisdigit, args, ,
959 "-*- texinfo -*-\n\
960@deftypefn {Mapping Function} {} isdigit (@var{s})\n\
961Return 1 for characters that are decimal digits.\n\
962@end deftypefn")
963{
964 octave_value retval;
965 if (args.length () == 1)
966 retval = args(0).xisdigit ();
967 else
968 print_usage ();
969
970 return retval;
971}
972
973DEFUN (isinf, args, ,
974 "-*- texinfo -*-\n\
975@deftypefn {Mapping Function} {} isinf (@var{x})\n\
976Return 1 for elements of @var{x} that are infinite and zero\n\
977otherwise. For example,\n\
978\n\
979@example\n\
980@group\n\
981isinf ([13, Inf, NA, NaN])\n\
982 @result{} [ 0, 1, 0, 0 ]\n\
983@end group\n\
984@end example\n\
985@end deftypefn")
986{
987 octave_value retval;
988 if (args.length () == 1)
989 retval = args(0).isinf ();
990 else
991 print_usage ();
992
993 return retval;
994}
995
996/*
997
998%!assert(isinf (Inf));
999%!assert(!isinf (NaN));
1000%!assert(!(isinf (NA)));
1001%!assert(isinf (rand(1,10)), false(1,10));
1002%!assert(isinf([NaN -Inf -1 0 1 Inf NA]), [false, true, false, false, false, true, false]);
1003
1004%!assert(isinf (single(Inf)));
1005%!assert(!(isinf (single(NaN))));
1006%!assert(!(isinf (single(NA))));
1007%!assert(isinf (single(rand(1,10))), false(1,10));
1008%!assert(isinf(single([NaN -Inf -1 0 1 Inf NA])), [false, true, false, false, false, true, false]);
1009
1010 */
1011
1012DEFUNX ("isgraph", Fisgraph, args, ,
1013 "-*- texinfo -*-\n\
1014@deftypefn {Mapping Function} {} isgraph (@var{s})\n\
1015Return 1 for printable characters (but not the space character).\n\
1016@end deftypefn")
1017{
1018 octave_value retval;
1019 if (args.length () == 1)
1020 retval = args(0).xisgraph ();
1021 else
1022 print_usage ();
1023
1024 return retval;
1025}
1026
1027DEFUNX ("islower", Fislower, args, ,
1028 "-*- texinfo -*-\n\
1029@deftypefn {Mapping Function} {} islower (@var{s})\n\
1030Return 1 for characters that are lower case letters.\n\
1031@end deftypefn")
1032{
1033 octave_value retval;
1034 if (args.length () == 1)
1035 retval = args(0).xislower ();
1036 else
1037 print_usage ();
1038
1039 return retval;
1040}
1041
1042DEFUN (isna, args, ,
1043 "-*- texinfo -*-\n\
1044@deftypefn {Mapping Function} {} isna (@var{x})\n\
1045Return 1 for elements of @var{x} that are NA (missing) values and zero\n\
1046otherwise. For example,\n\
1047\n\
1048@example\n\
1049@group\n\
1050isna ([13, Inf, NA, NaN])\n\
1051 @result{} [ 0, 0, 1, 0 ]\n\
1052@end group\n\
1053@end example\n\
1054@seealso{isnan}\n\
1055@end deftypefn")
1056{
1057 octave_value retval;
1058 if (args.length () == 1)
1059 retval = args(0).isna ();
1060 else
1061 print_usage ();
1062
1063 return retval;
1064}
1065
1066/*
1067
1068%!assert(!(isna (Inf)));
1069%!assert(!isna (NaN));
1070%!assert(isna (NA));
1071%!assert(isna (rand(1,10)), false(1,10));
1072%!assert(isna([NaN -Inf -1 0 1 Inf NA]), [false, false, false, false, false, false, true]);
1073
1074%!assert(!(isna (single(Inf))));
1075%!assert(!isna (single(NaN)));
1076%!assert(isna (single(NA)));
1077%!assert(isna (single(rand(1,10))), false(1,10));
1078%!assert(isna(single([NaN -Inf -1 0 1 Inf NA])), [false, false, false, false, false, false, true]);
1079
1080 */
1081
1082DEFUN (isnan, args, ,
1083 "-*- texinfo -*-\n\
1084@deftypefn {Mapping Function} {} isnan (@var{x})\n\
1085Return 1 for elements of @var{x} that are NaN values and zero\n\
1086otherwise. NA values are also considered NaN values. For example,\n\
1087\n\
1088@example\n\
1089@group\n\
1090isnan ([13, Inf, NA, NaN])\n\
1091 @result{} [ 0, 0, 1, 1 ]\n\
1092@end group\n\
1093@end example\n\
1094@seealso{isna}\n\
1095@end deftypefn")
1096{
1097 octave_value retval;
1098 if (args.length () == 1)
1099 retval = args(0).isnan ();
1100 else
1101 print_usage ();
1102
1103 return retval;
1104}
1105
1106/*
1107
1108%!assert(!(isnan (Inf)));
1109%!assert(isnan (NaN));
1110%!assert(isnan (NA));
1111%!assert(isnan (rand(1,10)), false(1,10));
1112%!assert(isnan([NaN -Inf -1 0 1 Inf NA]), [true, false, false, false, false, false, true]);
1113
1114%!assert(!(isnan (single(Inf))));
1115%!assert(isnan (single(NaN)));
1116%!assert(isnan (single(NA)));
1117%!assert(isnan (single(rand(1,10))), false(1,10));
1118%!assert(isnan(single([NaN -Inf -1 0 1 Inf NA])), [true, false, false, false, false, false, true]);
1119
1120 */
1121
1122DEFUNX ("isprint", Fisprint, args, ,
1123 "-*- texinfo -*-\n\
1124@deftypefn {Mapping Function} {} isprint (@var{s})\n\
1125Return 1 for printable characters (including the space character).\n\
1126@end deftypefn")
1127{
1128 octave_value retval;
1129 if (args.length () == 1)
1130 retval = args(0).xisprint ();
1131 else
1132 print_usage ();
1133
1134 return retval;
1135}
1136
1137DEFUNX ("ispunct", Fispunct, args, ,
1138 "-*- texinfo -*-\n\
1139@deftypefn {Mapping Function} {} ispunct (@var{s})\n\
1140Return 1 for punctuation characters.\n\
1141@end deftypefn")
1142{
1143 octave_value retval;
1144 if (args.length () == 1)
1145 retval = args(0).xispunct ();
1146 else
1147 print_usage ();
1148
1149 return retval;
1150}
1151
1152DEFUNX ("isspace", Fisspace, args, ,
1153 "-*- texinfo -*-\n\
1154@deftypefn {Mapping Function} {} isspace (@var{s})\n\
1155Return 1 for whitespace characters (space, formfeed, newline,\n\
1156carriage return, tab, and vertical tab).\n\
1157@end deftypefn")
1158{
1159 octave_value retval;
1160 if (args.length () == 1)
1161 retval = args(0).xisspace ();
1162 else
1163 print_usage ();
1164
1165 return retval;
1166}
1167
1168DEFUNX ("isupper", Fisupper, args, ,
1169 "-*- texinfo -*-\n\
1170@deftypefn {Mapping Function} {} isupper (@var{s})\n\
1171Return 1 for upper case letters.\n\
1172@end deftypefn")
1173{
1174 octave_value retval;
1175 if (args.length () == 1)
1176 retval = args(0).xisupper ();
1177 else
1178 print_usage ();
1179
1180 return retval;
1181}
1182
1183DEFUNX ("isxdigit", Fisxdigit, args, ,
1184 "-*- texinfo -*-\n\
1185@deftypefn {Mapping Function} {} isxdigit (@var{s})\n\
1186Return 1 for characters that are hexadecimal digits.\n\
1187@end deftypefn")
1188{
1189 octave_value retval;
1190 if (args.length () == 1)
1191 retval = args(0).xisxdigit ();
1192 else
1193 print_usage ();
1194
1195 return retval;
1196}
1197
1198DEFUN (lgamma, args, ,
1199 "-*- texinfo -*-\n\
1200@deftypefn {Mapping Function} {} lgamma (@var{x})\n\
1201@deftypefnx {Mapping Function} {} gammaln (@var{x})\n\
1202Return the natural logarithm of the gamma function of @var{x}.\n\
1203@seealso{gamma, gammainc}\n\
1204@end deftypefn")
1205{
1206 octave_value retval;
1207 if (args.length () == 1)
1208 retval = args(0).lgamma ();
1209 else
1210 print_usage ();
1211
1212 return retval;
1213}
1214
1215/*
1216
1217%!test
1218%! a = -1i*sqrt(-1/(6.4187*6.4187));
1219%! assert (lgamma(a), lgamma(real(a)));
1220
1221%!test
1222%! x = [.5, 1, 1.5, 2, 3, 4, 5];
1223%! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1224%! assert(lgamma(x), log(v), sqrt(eps))
1225
1226%!test
1227%! a = single(-1i*sqrt(-1/(6.4187*6.4187)));
1228%! assert (lgamma(a), lgamma(real(a)));
1229
1230%!test
1231%! x = single([.5, 1, 1.5, 2, 3, 4, 5]);
1232%! v = single([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1233%! assert(lgamma(x), log(v), sqrt(eps ('single')))
1234
1235%!error lgamma();
1236%!error lgamma(1,2);
1237
1238*/
1239
1240DEFUN (log, args, ,
1241 "-*- texinfo -*-\n\
1242@deftypefn {Mapping Function} {} log (@var{x})\n\
1243Compute the natural logarithm,\n\
1244@tex\n\
1245$\\ln{(x)},$\n\
1246@end tex\n\
1247@ifnottex\n\
1248@code{ln (@var{x})},\n\
1249@end ifnottex\n\
1250for each element of @var{x}. To compute the\n\
1251matrix logarithm, see @ref{Linear Algebra}.\n\
1252@seealso{exp, log1p, log2, log10, logspace}\n\
1253@end deftypefn")
1254{
1255 octave_value retval;
1256 if (args.length () == 1)
1257 retval = args(0).log ();
1258 else
1259 print_usage ();
1260
1261 return retval;
1262}
1263
1264/*
1265
1266%!assert(log ([1, e, e^2]), [0, 1, 2], sqrt (eps));
1267%!assert(log ([-0.5, -1.5, -2.5]), log([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps));
1268
1269%!assert(log (single([1, e, e^2])), single([0, 1, 2]), sqrt (eps('single')));
1270%!assert(log (single([-0.5, -1.5, -2.5])), single(log([0.5, 1.5, 2.5]) + pi*1i), 4*eps('single'));
1271
1272%!error log ();
1273%!error log (1, 2);
1274
1275 */
1276
1277DEFUN (log10, args, ,
1278 "-*- texinfo -*-\n\
1279@deftypefn {Mapping Function} {} log10 (@var{x})\n\
1280Compute the base-10 logarithm of each element of @var{x}.\n\
1281@seealso{log, log2, logspace, exp}\n\
1282@end deftypefn")
1283{
1284 octave_value retval;
1285 if (args.length () == 1)
1286 retval = args(0).log10 ();
1287 else
1288 print_usage ();
1289
1290 return retval;
1291}
1292
1293/*
1294
1295%!assert(log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps));
1296%!assert(log10 (single([0.01, 0.1, 1, 10, 100])), single([-2, -1, 0, 1, 2]), sqrt (eps ('single')));
1297
1298%!error log10 ();
1299%!error log10 (1, 2);
1300
1301*/
1302
1303DEFUN (log1p, args, ,
1304 "-*- texinfo -*-\n\
1305@deftypefn {Mapping Function} {} log1p (@var{x})\n\
1306Compute\n\
1307@tex\n\
1308$\\ln{(1 + x)}$\n\
1309@end tex\n\
1310@ifnottex\n\
1311@code{log (1 + @var{x})}\n\
1312@end ifnottex\n\
1313accurately in the neighborhood of zero.\n\
1314@seealso{log, exp, expm1}\n\
1315@end deftypefn")
1316{
1317 octave_value retval;
1318 if (args.length () == 1)
1319 retval = args(0).log1p ();
1320 else
1321 print_usage ();
1322
1323 return retval;
1324}
1325
1326DEFUN (real, args, ,
1327 "-*- texinfo -*-\n\
1328@deftypefn {Mapping Function} {} real (@var{z})\n\
1329Return the real part of @var{z}.\n\
1330@seealso{imag, conj}\n\
1331@end deftypefn")
1332{
1333 octave_value retval;
1334 if (args.length () == 1)
1335 retval = args(0).real ();
1336 else
1337 print_usage ();
1338
1339 return retval;
1340}
1341
1342/*
1343
1344%!assert(real (1), 1);
1345%!assert(real (i), 0);
1346%!assert(real (1+i), 1);
1347%!assert(real ([1, i; i, 1]), full (eye (2)));
1348
1349%!assert(real (single(1)), single(1));
1350%!assert(real (single(i)), single(0));
1351%!assert(real (single(1+i)), single(1));
1352%!assert(real (single([1, i; i, 1])), full (eye (2,'single')));
1353
1354%!error real ();
1355%!error real (1, 2);
1356
1357*/
1358
1359DEFUN (round, args, ,
1360 "-*- texinfo -*-\n\
1361@deftypefn {Mapping Function} {} round (@var{x})\n\
1362Return the integer nearest to @var{x}. If @var{x} is complex, return\n\
1363@code{round (real (@var{x})) + round (imag (@var{x})) * I}.\n\
1364@example\n\
1365@group\n\
1366round ([-2.7, 2.7])\n\
1367 @result{} -3 3\n\
1368@end group\n\
1369@end example\n\
1370@seealso{ceil, floor, fix}\n\
1371@end deftypefn")
1372{
1373 octave_value retval;
1374 if (args.length () == 1)
1375 retval = args(0).round ();
1376 else
1377 print_usage ();
1378
1379 return retval;
1380}
1381
1382/*
1383
1384%!assert(round (1), 1);
1385%!assert(round (1.1), 1);
1386%!assert(round (5.5), 6);
1387%!assert(round (i), i);
1388%!assert(round (2.5+3.5i), 3+4i);
1389%!assert(round (-2.6), -3);
1390%!assert(round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7]);
1391
1392%!assert(round (single(1)), single(1));
1393%!assert(round (single(1.1)), single(1));
1394%!assert(round (single(5.5)), single(6));
1395%!assert(round (single(i)), single(i));
1396%!assert(round (single(2.5+3.5i)), single(3+4i));
1397%!assert(round (single(-2.6)), single(-3));
1398%!assert(round (single([1.1, -2.4; -3.7, 7.1])), single([1, -2; -4, 7]));
1399
1400%!error round ();
1401%!error round (1, 2);
1402
1403*/
1404
1405DEFUN (roundb, args, ,
1406 "-*- texinfo -*-\n\
1407@deftypefn {Mapping Function} {} roundb (@var{x})\n\
1408Return the integer nearest to @var{x}. If there are two nearest\n\
1409integers, return the even one (banker's rounding). If @var{x} is complex,\n\
1410return @code{roundb (real (@var{x})) + roundb (imag (@var{x})) * I}.\n\
1411@seealso{round}\n\
1412@end deftypefn")
1413{
1414 octave_value retval;
1415 if (args.length () == 1)
1416 retval = args(0).roundb ();
1417 else
1418 print_usage ();
1419
1420 return retval;
1421}
1422
1423DEFUN (sign, args, ,
1424 "-*- texinfo -*-\n\
1425@deftypefn {Mapping Function} {} sign (@var{x})\n\
1426Compute the @dfn{signum} function, which is defined as\n\
1427@tex\n\
1428$$\n\
1429{\\rm sign} (@var{x}) = \\cases{1,&$x>0$;\\cr 0,&$x=0$;\\cr -1,&$x<0$.\\cr}\n\
1430$$\n\
1431@end tex\n\
1432@ifnottex\n\
1433\n\
1434@example\n\
1435@group\n\
1436 -1, x < 0;\n\
1437sign (x) = 0, x = 0;\n\
1438 1, x > 0.\n\
1439@end group\n\
1440@end example\n\
1441@end ifnottex\n\
1442\n\
1443For complex arguments, @code{sign} returns @code{x ./ abs (@var{x})}.\n\
1444@end deftypefn")
1445{
1446 octave_value retval;
1447 if (args.length () == 1)
1448 retval = args(0).signum ();
1449 else
1450 print_usage ();
1451
1452 return retval;
1453}
1454
1455/*
1456
1457%!assert(sign (-2) , -1);
1458%!assert(sign (3), 1);
1459%!assert(sign (0), 0);
1460%!assert(sign ([1, -pi; e, 0]), [1, -1; 1, 0]);
1461
1462%!assert(sign (single(-2)) , single(-1));
1463%!assert(sign (single(3)), single(1));
1464%!assert(sign (single(0)), single(0));
1465%!assert(sign (single([1, -pi; e, 0])), single([1, -1; 1, 0]));
1466
1467%!error sign ();
1468%!error sign (1, 2);
1469
1470*/
1471
1472DEFUN (sin, args, ,
1473 "-*- texinfo -*-\n\
1474@deftypefn {Mapping Function} {} sin (@var{x})\n\
1475Compute the sine for each element of @var{x} in radians.\n\
1476@seealso{asin, sind, sinh}\n\
1477@end deftypefn")
1478{
1479 octave_value retval;
1480 if (args.length () == 1)
1481 retval = args(0).sin ();
1482 else
1483 print_usage ();
1484
1485 return retval;
1486}
1487
1488/*
1489
1490%!test
1491%! rt2 = sqrt (2);
1492%! rt3 = sqrt (3);
1493%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
1494%! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
1495%! assert(sin (x), v, sqrt (eps));
1496
1497%!test
1498%! rt2 = sqrt (2);
1499%! rt3 = sqrt (3);
1500%! x = single([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
1501%! v = single([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
1502%! assert(sin (x), v, sqrt (eps('single')));
1503
1504%!error sin ();
1505%!error sin (1, 2);
1506
1507*/
1508
1509DEFUN (sinh, args, ,
1510 "-*- texinfo -*-\n\
1511@deftypefn {Mapping Function} {} sinh (@var{x})\n\
1512Compute the hyperbolic sine for each element of @var{x}.\n\
1513@seealso{asinh, cosh, tanh}\n\
1514@end deftypefn")
1515{
1516 octave_value retval;
1517 if (args.length () == 1)
1518 retval = args(0).sinh ();
1519 else
1520 print_usage ();
1521
1522 return retval;
1523}
1524
1525/*
1526
1527%!test
1528%! x = [0, pi/2*i, pi*i, 3*pi/2*i];
1529%! v = [0, i, 0, -i];
1530%! assert(sinh (x), v, sqrt (eps));
1531
1532%!test
1533%! x = single([0, pi/2*i, pi*i, 3*pi/2*i]);
1534%! v = single([0, i, 0, -i]);
1535%! assert(sinh (x), v, sqrt (eps('single')));
1536
1537%!error sinh ();
1538%!error sinh (1, 2);
1539
1540 */
1541
1542DEFUN (sqrt, args, ,
1543 "-*- texinfo -*-\n\
1544@deftypefn {Mapping Function} {} sqrt (@var{x})\n\
1545Compute the square root of each element of @var{x}. If @var{x} is negative,\n\
1546a complex result is returned. To compute the matrix square root, see\n\
1547@ref{Linear Algebra}.\n\
1548@seealso{realsqrt}\n\
1549@end deftypefn")
1550{
1551 octave_value retval;
1552 if (args.length () == 1)
1553 retval = args(0).sqrt ();
1554 else
1555 print_usage ();
1556
1557 return retval;
1558}
1559
1560/*
1561
1562%!assert(sqrt (4), 2)
1563%!assert(sqrt (-1), i)
1564%!assert(sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps));
1565%!assert(sqrt([4, -4; i, 1-i]), [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt(eps));
1566
1567%!assert(sqrt (single(4)), single(2))
1568%!assert(sqrt (single(-1)), single(i))
1569%!assert(sqrt (single(1+i)), single(exp (0.5 * log (1+i))), sqrt (eps('single')));
1570%!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')));
1571
1572%!error sqrt ();
1573%!error sqrt (1, 2);
1574
1575*/
1576
1577DEFUN (tan, args, ,
1578 "-*- texinfo -*-\n\
1579@deftypefn {Mapping Function} {} tan (@var{z})\n\
1580Compute the tangent for each element of @var{x} in radians.\n\
1581@seealso{atan, tand, tanh}\n\
1582@end deftypefn")
1583{
1584 octave_value retval;
1585 if (args.length () == 1)
1586 retval = args(0).tan ();
1587 else
1588 print_usage ();
1589
1590 return retval;
1591}
1592
1593/*
1594
1595%!test
1596%! rt2 = sqrt (2);
1597%! rt3 = sqrt (3);
1598%! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
1599%! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
1600%! assert(tan (x), v, sqrt (eps));
1601
1602%!test
1603%! rt2 = sqrt (2);
1604%! rt3 = sqrt (3);
1605%! x = single([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
1606%! v = single([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
1607%! assert(tan (x), v, sqrt (eps('single')));
1608
1609%!error tan ();
1610%!error tan (1, 2);
1611
1612*/
1613
1614DEFUN (tanh, args, ,
1615 "-*- texinfo -*-\n\
1616@deftypefn {Mapping Function} {} tanh (@var{x})\n\
1617Compute hyperbolic tangent for each element of @var{x}.\n\
1618@seealso{atanh, sinh, cosh}\n\
1619@end deftypefn")
1620{
1621 octave_value retval;
1622 if (args.length () == 1)
1623 retval = args(0).tanh ();
1624 else
1625 print_usage ();
1626
1627 return retval;
1628}
1629
1630/*
1631
1632%!test
1633%! x = [0, pi*i];
1634%! v = [0, 0];
1635%! assert(tanh (x), v, sqrt (eps));
1636
1637%!test
1638%! x = single([0, pi*i]);
1639%! v = single([0, 0]);
1640%! assert(tanh (x), v, sqrt (eps('single')));
1641
1642%!error tanh ();
1643%!error tanh (1, 2);
1644
1645*/
1646
1647DEFUNX ("toascii", Ftoascii, args, ,
1648 "-*- texinfo -*-\n\
1649@deftypefn {Mapping Function} {} toascii (@var{s})\n\
1650Return ASCII representation of @var{s} in a matrix. For example,\n\
1651\n\
1652@example\n\
1653@group\n\
1654toascii (\"ASCII\")\n\
1655 @result{} [ 65, 83, 67, 73, 73 ]\n\
1656@end group\n\
1657\n\
1658@end example\n\
1659@seealso{char}\n\
1660@end deftypefn")
1661{
1662 octave_value retval;
1663 if (args.length () == 1)
1664 retval = args(0).xtoascii ();
1665 else
1666 print_usage ();
1667
1668 return retval;
1669}
1670
1671DEFUNX ("tolower", Ftolower, args, ,
1672 "-*- texinfo -*-\n\
1673@deftypefn {Mapping Function} {} tolower (@var{s})\n\
1674@deftypefnx {Mapping Function} {} lower (@var{s})\n\
1675Return a copy of the string or cell string @var{s}, with each upper-case\n\
1676character replaced by the corresponding lower-case one; non-alphabetic\n\
1677characters are left unchanged. For example,\n\
1678\n\
1679@example\n\
1680@group\n\
1681tolower (\"MiXeD cAsE 123\")\n\
1682 @result{} \"mixed case 123\"\n\
1683@end group\n\
1684@end example\n\
1685@seealso{toupper}\n\
1686@end deftypefn")
1687{
1688 octave_value retval;
1689 if (args.length () == 1)
1690 retval = args(0).xtolower ();
1691 else
1692 print_usage ();
1693
1694 return retval;
1695}
1696
1697DEFALIAS (lower, tolower);
1698
1699/*
1700
1701%!error <Invalid call to tolower.*> tolower();
1702%!error <Invalid call to tolower.*> lower();
1703%!assert(tolower("OCTAVE"), "octave");
1704%!assert(tolower("123OCTave!_&"), "123octave!_&");
1705%!assert(tolower({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}});
1706%!assert(tolower(["ABC"; "DEF"]), ["abc"; "def"]);
1707%!assert(tolower({["ABC"; "DEF"]}), {["abc";"def"]});
1708%!assert(tolower(68), "d");
1709%!assert(tolower({[68, 68; 68, 68]}), {["dd";"dd"]});
1710%!test
1711%! a(3,3,3,3) = "D";
1712%! assert(tolower(a)(3,3,3,3), "d");
1713
1714*/
1715
1716
1717DEFUNX ("toupper", Ftoupper, args, ,
1718 "-*- texinfo -*-\n\
1719@deftypefn {Built-in Function} {} toupper (@var{s})\n\
1720@deftypefnx {Built-in Function} {} upper (@var{s})\n\
1721Return a copy of the string or cell string @var{s}, with each lower-case\n\
1722character replaced by the corresponding upper-case one; non-alphabetic\n\
1723characters are left unchanged. For example,\n\
1724\n\
1725@example\n\
1726@group\n\
1727toupper (\"MiXeD cAsE 123\")\n\
1728 @result{} \"MIXED CASE 123\"\n\
1729@end group\n\
1730@end example\n\
1731@seealso{tolower}\n\
1732@end deftypefn")
1733{
1734 octave_value retval;
1735 if (args.length () == 1)
1736 retval = args(0).xtoupper ();
1737 else
1738 print_usage ();
1739
1740 return retval;
1741}
1742
1743DEFALIAS (upper, toupper);
1744
1745/*
1746
1747%!error <Invalid call to toupper.*> toupper();
1748%!error <Invalid call to toupper.*> upper();
1749%!assert(toupper("octave"), "OCTAVE");
1750%!assert(toupper("123OCTave!_&"), "123OCTAVE!_&");
1751%!assert(toupper({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI", {"JKL"}}});
1752%!assert(toupper(["abc"; "def"]), ["ABC"; "DEF"]);
1753%!assert(toupper({["abc"; "def"]}), {["ABC";"DEF"]});
1754%!assert(toupper(100), "D");
1755%!assert(toupper({[100, 100; 100, 100]}), {["DD";"DD"]});
1756%!test
1757%! a(3,3,3,3) = "d";
1758%! assert(toupper(a)(3,3,3,3), "D");
1759
1760*/
1761
1762DEFALIAS (gammaln, lgamma);
1763
1764DEFALIAS (isfinite, finite);