GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
mappers.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <cctype>
31
32#include "lo-ieee.h"
33#include "lo-specfun.h"
34#include "lo-mappers.h"
35
36#include "defun.h"
37#include "error.h"
38#include "variables.h"
39
40OCTAVE_NAMESPACE_BEGIN
41
42DEFUN (abs, args, ,
43 doc: /* -*- texinfo -*-
44@deftypefn {} {} abs (@var{z})
45Compute the magnitude of @var{z}.
46
47The magnitude is defined as
48@tex
49$|z| = \sqrt{x^2 + y^2}$.
50@end tex
51@ifnottex
52|@var{z}| = @code{sqrt (x^2 + y^2)}.
53@end ifnottex
54
55For example:
56
57@example
58@group
59abs (3 + 4i)
60 @result{} 5
61@end group
62@end example
63@seealso{arg}
64@end deftypefn */)
65{
66 if (args.length () != 1)
67 print_usage ();
68
69 return ovl (args(0).abs ());
70}
71
72/*
73%!assert (abs (1), 1)
74%!assert (abs (-3.5), 3.5)
75%!assert (abs (3+4i), 5)
76%!assert (abs (3-4i), 5)
77%!assert (abs ([1.1, 3i; 3+4i, -3-4i]), [1.1, 3; 5, 5])
78
79%!assert (abs (single (1)), single (1))
80%!assert (abs (single (-3.5)), single (3.5))
81%!assert (abs (single (3+4i)), single (5))
82%!assert (abs (single (3-4i)), single (5))
83%!assert (abs (single ([1.1, 3i; 3+4i, -3-4i])), single ([1.1, 3; 5, 5]))
84
85%!error abs ()
86%!error abs (1, 2)
87*/
88
89DEFUN (acos, args, ,
90 doc: /* -*- texinfo -*-
91@deftypefn {} {} acos (@var{x})
92Compute the inverse cosine in radians for each element of @var{x}.
93@seealso{cos, acosd}
94@end deftypefn */)
95{
96 if (args.length () != 1)
97 print_usage ();
98
99 return ovl (args(0).acos ());
100}
101
102/*
103%!shared rt2, rt3
104%! rt2 = sqrt (2);
105%! rt3 = sqrt (3);
106
107%!test
108%! x = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
109%! v = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
110%! assert (acos (x), v, sqrt (eps));
111
112%!test
113%! x = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
114%! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
115%! assert (acos (x), v, sqrt (eps ("single")));
116
117## Test values on either side of branch cut
118%!test
119%! rval = 0;
120%! ival = 1.31695789692481671;
121%! obs = acos ([2, 2-i*eps, 2+i*eps]);
122%! exp = [rval + ival*i, rval + ival*i, rval - ival*i];
123%! assert (obs, exp, 3*eps);
124%! rval = pi;
125%! obs = acos ([-2, -2-i*eps, -2+i*eps]);
126%! exp = [rval - ival*i, rval + ival*i, rval - ival*i];
127%! assert (obs, exp, 5*eps);
128%! assert (acos ([2 0]), [ival*i, pi/2], 3*eps);
129%! assert (acos ([2 0i]), [ival*i, pi/2], 3*eps);
130
131## Test large magnitude arguments (bug #45507)
132## Test fails with older versions of libm, solution is to upgrade.
133%!testif ; ! ismac () && ! ispc () <*45507>
134%! x = [1, -1, i, -i] .* 1e150;
135%! v = [0, pi, pi/2, pi/2];
136%! assert (real (acos (x)), v);
137
138%!testif ; ismac () || ispc () <52627>
139%! ## Same test code as above, but intended only for test statistics on Mac and
140%! ## Windows. Their trig/hyperbolic functions have huge tolerances.
141%! x = [1, -1, i, -i] .* 1e150;
142%! v = [0, pi, pi/2, pi/2];
143%! assert (real (acos (x)), v);
144
145%!error acos ()
146%!error acos (1, 2)
147*/
148
149DEFUN (acosh, args, ,
150 doc: /* -*- texinfo -*-
151@deftypefn {} {} acosh (@var{x})
152Compute the inverse hyperbolic cosine for each element of @var{x}.
153@seealso{cosh}
154@end deftypefn */)
155{
156 if (args.length () != 1)
157 print_usage ();
158
159 return ovl (args(0).acosh ());
160}
161
162/*
163%!testif ; ! ismac ()
164%! x = [1, 0, -1, 0];
165%! v = [0, pi/2*i, pi*i, pi/2*i];
166%! assert (acosh (x), v, sqrt (eps));
167
168%!testif ; ismac () <52627>
169%! ## Same test code as above, but intended only for test statistics on Mac.
170%! ## Mac trig/hyperbolic functions have huge tolerances.
171%! x = [1, 0, -1, 0];
172%! v = [0, pi/2*i, pi*i, pi/2*i];
173%! assert (acosh (x), v, sqrt (eps));
174
175## FIXME: std::acosh on Windows platforms, returns a result that differs
176## by 1 in the last significant digit. This is ~30*eps which is quite large.
177## The decision now (9/15/2016) is to mark the test with a bug number so
178## it is understood why it is failing, and wait for MinGw to improve their
179## std library.
180%!test <49091>
181%! re = 2.99822295029797;
182%! im = pi/2;
183%! assert (acosh (-10i), re - i*im);
184
185%!testif ; ! ismac ()
186%! x = single ([1, 0, -1, 0]);
187%! v = single ([0, pi/2*i, pi*i, pi/2*i]);
188%! assert (acosh (x), v, sqrt (eps ("single")));
189
190%!testif ; ismac () <52627>
191%! ## Same test code as above, but intended only for test statistics on Mac.
192%! ## Mac trig/hyperbolic functions have huge tolerances.
193%! x = single ([1, 0, -1, 0]);
194%! v = single ([0, pi/2*i, pi*i, pi/2*i]);
195%! assert (acosh (x), v, sqrt (eps ("single")));
196
197%!test <49091>
198%! re = single (2.99822295029797);
199%! im = single (pi/2);
200%! assert (acosh (single (10i)), re + i*im, 5*eps ("single"));
201%! assert (acosh (single (-10i)), re - i*im, 5*eps ("single"));
202
203## Test large magnitude arguments (bug #45507)
204## Test fails with older versions of libm, solution is to upgrade.
205%!testif ; ! ismac () && ! ispc () <*45507>
206%! x = [1, -1, i, -i] .* 1e150;
207%! v = [0, pi, pi/2, -pi/2];
208%! assert (imag (acosh (x)), v);
209
210%!testif ; ismac () || ispc () <52627>
211%! ## Same test code as above, but intended only for test statistics on Mac and
212%! ## Windows. Their trig/hyperbolic functions have huge tolerances.
213%! x = [1, -1, i, -i] .* 1e150;
214%! v = [0, pi, pi/2, -pi/2];
215%! assert (imag (acosh (x)), v);
216
217%!error acosh ()
218%!error acosh (1, 2)
219*/
220
221DEFUN (angle, args, ,
222 doc: /* -*- texinfo -*-
223@deftypefn {} {} angle (@var{z})
224@xref{XREFarg,,@code{arg}}.
225@seealso{arg}
226@end deftypefn */)
227{
228 if (args.length () != 1)
229 print_usage ();
230
231 return ovl (args(0).arg ());
232}
233
234DEFUN (arg, args, ,
235 doc: /* -*- texinfo -*-
236@deftypefn {} {} arg (@var{z})
237@deftypefnx {} {} angle (@var{z})
238Compute the argument, i.e., angle of @var{z}.
239
240This is defined as,
241@tex
242$\theta = atan2 (y, x),$
243@end tex
244@ifnottex
245@var{theta} = @code{atan2 (@var{y}, @var{x})},
246@end ifnottex
247in radians.
248
249For example:
250
251@example
252@group
253arg (3 + 4i)
254 @result{} 0.92730
255@end group
256@end example
257@seealso{abs}
258@end deftypefn */)
259{
260 if (args.length () != 1)
261 print_usage ();
262
263 return ovl (args(0).arg ());
264}
265
266/*
267%!assert (arg (1), 0)
268%!assert (arg (i), pi/2)
269%!assert (arg (-1), pi)
270%!assert (arg (-i), -pi/2)
271%!assert (arg ([1, i; -1, -i]), [0, pi/2; pi, -pi/2])
272
273%!assert (arg (single (1)), single (0))
274%!assert (arg (single (i)), single (pi/2))
275%!test
276%! if (ismac ())
277%! ## Avoid failing for a MacOS feature
278%! assert (arg (single (-1)), single (pi), 2*eps (single (1)));
279%! else
280%! assert (arg (single (-1)), single (pi));
281%! endif
282%!assert (arg (single (-i)), single (-pi/2))
283%!assert (arg (single ([1, i; -1, -i])), single ([0, pi/2; pi, -pi/2]), 2e1*eps ("single"))
284
285%!error arg ()
286%!error arg (1, 2)
287*/
288
289DEFUN (asin, args, ,
290 doc: /* -*- texinfo -*-
291@deftypefn {} {} asin (@var{x})
292Compute the inverse sine in radians for each element of @var{x}.
293@seealso{sin, asind}
294@end deftypefn */)
295{
296 if (args.length () != 1)
297 print_usage ();
298
299 return ovl (args(0).asin ());
300}
301
302/*
303%!shared rt2, rt3
304%! rt2 = sqrt (2);
305%! rt3 = sqrt (3);
306
307%!test
308%! x = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
309%! v = [0, pi/6, pi/4, pi/3, pi/2, pi/3, pi/4, pi/6, 0];
310%! assert (asin (x), v, sqrt (eps));
311
312%!test
313%! x = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
314%! v = single ([0, pi/6, pi/4, pi/3, pi/2, pi/3, pi/4, pi/6, 0]);
315%! assert (asin (x), v, sqrt (eps ("single")));
316
317## Test values on either side of branch cut
318%!test
319%! rval = pi/2;
320%! ival = 1.31695789692481635;
321%! obs = asin ([2, 2-i*eps, 2+i*eps]);
322%! exp = [rval - ival*i, rval - ival*i, rval + ival*i];
323%! if (ismac ())
324%! ## Math libraries on macOS seem to implement asin with less accuracy.
325%! tol = 6*eps;
326%! else
327%! tol = 2*eps;
328%! endif
329%! assert (obs, exp, tol);
330%! obs = asin ([-2, -2-i*eps, -2+i*eps]);
331%! exp = [-rval + ival*i, -rval - ival*i, -rval + ival*i];
332%! assert (obs, exp, tol);
333%! assert (asin ([2 0]), [rval - ival*i, 0], tol);
334%! assert (asin ([2 0i]), [rval - ival*i, 0], tol);
335
336## Test large magnitude arguments (bug #45507)
337## Test fails with older versions of libm, solution is to upgrade.
338%!testif ; ! ismac () && ! ispc () <*45507>
339%! x = [1, -1, i, -i] .* 1e150;
340%! v = [pi/2, -pi/2, 0, -0];
341%! assert (real (asin (x)), v);
342
343%!testif ; ismac () || ispc () <52627>
344%! ## Same test code as above, but intended only for test statistics on Mac and
345%! ## Windows. Their trig/hyperbolic functions have huge tolerances.
346%! x = [1, -1, i, -i] .* 1e150;
347%! v = [pi/2, -pi/2, 0, -0];
348%! assert (real (asin (x)), v);
349
350%!error asin ()
351%!error asin (1, 2)
352*/
353
354DEFUN (asinh, args, ,
355 doc: /* -*- texinfo -*-
356@deftypefn {} {} asinh (@var{x})
357Compute the inverse hyperbolic sine for each element of @var{x}.
358@seealso{sinh}
359@end deftypefn */)
360{
361 if (args.length () != 1)
362 print_usage ();
363
364 return ovl (args(0).asinh ());
365}
366
367/*
368%!test
369%! v = [0, pi/2*i, 0, -pi/2*i];
370%! x = [0, i, 0, -i];
371%! assert (asinh (x), v, sqrt (eps));
372
373%!test
374%! v = single ([0, pi/2*i, 0, -pi/2*i]);
375%! x = single ([0, i, 0, -i]);
376%! assert (asinh (x), v, sqrt (eps ("single")));
377
378## Test large magnitude arguments (bug #45507)
379## Test fails with older versions of libm, solution is to upgrade.
380%!testif ; ! ismac () && ! ispc () <*45507>
381%! x = [1, -1, i, -i] .* 1e150;
382%! v = [0, 0, pi/2, -pi/2];
383%! assert (imag (asinh (x)), v);
384
385%!testif ; ismac () || ispc () <52627>
386%! ## Same test code as above, but intended only for test statistics on Mac and
387%! ## Windows. Their trig/hyperbolic functions have huge tolerances.
388%! x = [1, -1, i, -i] .* 1e150;
389%! v = [0, 0, pi/2, -pi/2];
390%! assert (imag (asinh (x)), v);
391
392%!error asinh ()
393%!error asinh (1, 2)
394*/
395
396DEFUN (atan, args, ,
397 doc: /* -*- texinfo -*-
398@deftypefn {} {} atan (@var{x})
399Compute the inverse tangent in radians for each element of @var{x}.
400@seealso{tan, atand}
401@end deftypefn */)
402{
403 if (args.length () != 1)
404 print_usage ();
405
406 return ovl (args(0).atan ());
407}
408
409/*
410%!shared rt2, rt3
411%! rt2 = sqrt (2);
412%! rt3 = sqrt (3);
413
414%!test
415%! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
416%! x = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
417%! assert (atan (x), v, sqrt (eps));
418
419%!test
420%! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
421%! x = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
422%! assert (atan (x), v, sqrt (eps ("single")));
423
424## Test large magnitude arguments (bug #44310, bug #45507)
425%!test <*44310>
426%! x = [1, -1, i, -i] .* 1e150;
427%! v = [pi/2, -pi/2, pi/2, -pi/2];
428%! assert (real (atan (x)), v);
429%! assert (imag (atan (x)), [0, 0, 0, 0], eps);
430
431%!error atan ()
432%!error atan (1, 2)
433*/
434
435DEFUN (atanh, args, ,
436 doc: /* -*- texinfo -*-
437@deftypefn {} {} atanh (@var{x})
438Compute the inverse hyperbolic tangent for each element of @var{x}.
439@seealso{tanh}
440@end deftypefn */)
441{
442 if (args.length () != 1)
443 print_usage ();
444
445 return ovl (args(0).atanh ());
446}
447
448/*
449%!test
450%! v = [0, 0];
451%! x = [0, 0];
452%! assert (atanh (x), v, sqrt (eps));
453
454%!test
455%! v = single ([0, 0]);
456%! x = single ([0, 0]);
457%! assert (atanh (x), v, sqrt (eps ("single")));
458
459## Test large magnitude arguments (bug #44310, bug #45507)
460%!test <*44310>
461%! x = [1, -1, i, -i] .* 1e150;
462%! v = [pi/2, pi/2, pi/2, -pi/2];
463%! assert (imag (atanh (x)), v);
464%! assert (real (atanh (x)), [0, 0, 0, 0], eps);
465
466%!error atanh ()
467%!error atanh (1, 2)
468*/
469
470DEFUN (cbrt, args, ,
471 doc: /* -*- texinfo -*-
472@deftypefn {} {} cbrt (@var{x})
473Compute the real-valued cube root of each element of @var{x}.
474
475Unlike @code{@var{x}^(1/3)}, the result will be negative if @var{x} is
476negative.
477
478If any element of @var{x} is complex, @code{cbrt} aborts with an error.
479@seealso{nthroot}
480@end deftypefn */)
481{
482 if (args.length () != 1)
483 print_usage ();
484
485 return ovl (args(0).cbrt ());
486}
487
488/*
489%!assert (cbrt (64), 4)
490%!assert (cbrt (-125), -5)
491%!assert (cbrt (0), 0)
492%!assert (cbrt (Inf), Inf)
493%!assert (cbrt (-Inf), -Inf)
494%!assert (cbrt (NaN), NaN)
495%!assert (cbrt (2^300), 2^100)
496%!assert (cbrt (125*2^300), 5*2^100)
497
498%!error cbrt ()
499%!error cbrt (1, 2)
500*/
501
502DEFUN (ceil, args, ,
503 doc: /* -*- texinfo -*-
504@deftypefn {} {} ceil (@var{x})
505Return the smallest integer not less than @var{x}.
506
507This is equivalent to rounding towards positive infinity.
508
509If @var{x} is complex, return
510@code{ceil (real (@var{x})) + ceil (imag (@var{x})) * I}.
511
512@example
513@group
514ceil ([-2.7, 2.7])
515 @result{} -2 3
516@end group
517@end example
518@seealso{floor, round, fix}
519@end deftypefn */)
520{
521 if (args.length () != 1)
522 print_usage ();
523
524 return ovl (args(0).ceil ());
525}
526
527/*
528## double precision
529%!assert (ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1])
530
531## complex double precision
532%!assert (ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i])
533
534## single precision
535%!assert (ceil (single ([2, 1.1, -1.1, -1])), single ([2, 2, -1, -1]))
536
537## complex single precision
538%!assert (ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 2+2i, -1-i, -1-i]))
539
540%!error ceil ()
541%!error ceil (1, 2)
542*/
543
544DEFUN (conj, args, ,
545 doc: /* -*- texinfo -*-
546@deftypefn {} {} conj (@var{z})
547Return the complex conjugate of @var{z}.
548
549The complex conjugate is defined as
550@tex
551$\bar{z} = x - iy$.
552@end tex
553@ifnottex
554@code{conj (@var{z})} = @var{x} - @var{i}@var{y}.
555@end ifnottex
556@seealso{real, imag}
557@end deftypefn */)
558{
559 if (args.length () != 1)
560 print_usage ();
561
562 return ovl (args(0).conj ());
563}
564
565/*
566%!assert (conj (1), 1)
567%!assert (conj (i), -i)
568%!assert (conj (1+i), 1-i)
569%!assert (conj (1-i), 1+i)
570%!assert (conj ([-1, -i; -1+i, -1-i]), [-1, i; -1-i, -1+i])
571
572%!assert (conj (single (1)), single (1))
573%!assert (conj (single (i)), single (-i))
574%!assert (conj (single (1+i)), single (1-i))
575%!assert (conj (single (1-i)), single (1+i))
576%!assert (conj (single ([-1, -i; -1+i, -1-i])), single ([-1, i; -1-i, -1+i]))
577
578%!error conj ()
579%!error conj (1, 2)
580*/
581
582DEFUN (cos, args, ,
583 doc: /* -*- texinfo -*-
584@deftypefn {} {} cos (@var{x})
585Compute the cosine for each element of @var{x} in radians.
586@seealso{acos, cosd, cosh}
587@end deftypefn */)
588{
589 if (args.length () != 1)
590 print_usage ();
591
592 return ovl (args(0).cos ());
593}
594
595/*
596%!shared rt2, rt3
597%! rt2 = sqrt (2);
598%! rt3 = sqrt (3);
599
600%!test
601%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
602%! v = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
603%! assert (cos (x), v, sqrt (eps));
604
605%!test
606%! rt2 = sqrt (2);
607%! rt3 = sqrt (3);
608%! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
609%! v = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
610%! assert (cos (x), v, sqrt (eps ("single")));
611
612%!error cos ()
613%!error cos (1, 2)
614*/
615
616DEFUN (cosh, args, ,
617 doc: /* -*- texinfo -*-
618@deftypefn {} {} cosh (@var{x})
619Compute the hyperbolic cosine for each element of @var{x}.
620@seealso{acosh, sinh, tanh}
621@end deftypefn */)
622{
623 if (args.length () != 1)
624 print_usage ();
625
626 return ovl (args(0).cosh ());
627}
628
629/*
630%!test
631%! x = [0, pi/2*i, pi*i, 3*pi/2*i];
632%! v = [1, 0, -1, 0];
633%! assert (cosh (x), v, sqrt (eps));
634
635%!test
636%! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
637%! v = single ([1, 0, -1, 0]);
638%! assert (cosh (x), v, sqrt (eps ("single")));
639
640%!error cosh ()
641%!error cosh (1, 2)
642*/
643
644DEFUN (erf, args, ,
645 doc: /* -*- texinfo -*-
646@deftypefn {} {} erf (@var{z})
647Compute the error function.
648
649The error function is defined as
650@tex
651$$
652 {\rm erf} (z) = {2 \over \sqrt{\pi}}\int_0^z e^{-t^2} dt
653$$
654@end tex
655@ifnottex
656
657@example
658@group
659 z
660 2 /
661erf (z) = --------- * | e^(-t^2) dt
662 sqrt (pi) /
663 t=0
664@end group
665@end example
666
667@end ifnottex
668@seealso{erfc, erfcx, erfi, dawson, erfinv, erfcinv}
669@end deftypefn */)
670{
671 if (args.length () != 1)
672 print_usage ();
673
674 return ovl (args(0).erf ());
675}
676
677/*
678%!test
679%! a = -1i*sqrt (-1/(6.4187*6.4187));
680%! assert (erf (a), erf (real (a)));
681
682%!test
683%! x = [0,.5,1];
684%! v = [0, .520499877813047, .842700792949715];
685%! assert (erf (x), v, 1.e-10);
686%! assert (erf (-x), -v, 1.e-10);
687%! assert (erfc (x), 1-v, 1.e-10);
688%! assert (erfinv (v), x, 1.e-10);
689
690%!test
691%! a = -1i*sqrt (single (-1/(6.4187*6.4187)));
692%! assert (erf (a), erf (real (a)));
693
694%!test
695%! x = single ([0,.5,1]);
696%! v = single ([0, .520499877813047, .842700792949715]);
697%! assert (erf (x), v, 1.e-6);
698%! assert (erf (-x), -v, 1.e-6);
699%! assert (erfc (x), 1-v, 1.e-6);
700%! assert (erfinv (v), x, 1.e-6);
701
702%!test
703%! x = [1+2i,-1+2i,1e-6+2e-6i,0+2i];
704%! v = [-0.53664356577857-5.04914370344703i, 0.536643565778565-5.04914370344703i, 0.112837916709965e-5+0.225675833419178e-5i, 18.5648024145755526i];
705%! assert (erf (x), v, -1.e-10);
706%! assert (erf (-x), -v, -1.e-10);
707%! assert (erfc (x), 1-v, -1.e-10);
708
709%!error erf ()
710%!error erf (1, 2)
711*/
712
713DEFUN (erfinv, args, ,
714 doc: /* -*- texinfo -*-
715@deftypefn {} {} erfinv (@var{x})
716Compute the inverse error function.
717
718The inverse error function is defined such that
719
720@example
721erf (@var{y}) == @var{x}
722@end example
723@seealso{erf, erfc, erfcx, erfi, dawson, erfcinv}
724@end deftypefn */)
725{
726 if (args.length () != 1)
727 print_usage ();
728
729 return ovl (args(0).erfinv ());
730}
731
732/*
733## middle region
734%!assert (erf (erfinv ([-0.9 -0.3 0 0.4 0.8])), [-0.9 -0.3 0 0.4 0.8], eps)
735%!assert (erf (erfinv (single ([-0.9 -0.3 0 0.4 0.8]))), single ([-0.9 -0.3 0 0.4 0.8]), eps ("single"))
736## tail region
737%!assert (erf (erfinv ([-0.999 -0.99 0.9999 0.99999])), [-0.999 -0.99 0.9999 0.99999], eps)
738%!assert (erf (erfinv (single ([-0.999 -0.99 0.9999 0.99999]))), single ([-0.999 -0.99 0.9999 0.99999]), eps ("single"))
739## backward - loss of accuracy
740%!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)
741%!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)
742## exceptional
743%!assert (erfinv ([-1, 1, 1.1, -2.1]), [-Inf, Inf, NaN, NaN])
744%!error erfinv (1+2i)
745
746%!error erfinv ()
747%!error erfinv (1, 2)
748*/
749
750DEFUN (erfcinv, args, ,
751 doc: /* -*- texinfo -*-
752@deftypefn {} {} erfcinv (@var{x})
753Compute the inverse complementary error function.
754
755The inverse complementary error function is defined such that
756
757@example
758erfc (@var{y}) == @var{x}
759@end example
760@seealso{erfc, erf, erfcx, erfi, dawson, erfinv}
761@end deftypefn */)
762{
763 if (args.length () != 1)
764 print_usage ();
765
766 return ovl (args(0).erfcinv ());
767}
768
769/*
770## middle region
771%!assert (erfc (erfcinv ([1.9 1.3 1 0.6 0.2])), [1.9 1.3 1 0.6 0.2], eps)
772%!assert (erfc (erfcinv (single ([1.9 1.3 1 0.6 0.2]))), single ([1.9 1.3 1 0.6 0.2]), eps ("single"))
773## tail region
774%!assert (erfc (erfcinv ([0.001 0.01 1.9999 1.99999])), [0.001 0.01 1.9999 1.99999], eps)
775%!assert (erfc (erfcinv (single ([0.001 0.01 1.9999 1.99999]))), single ([0.001 0.01 1.9999 1.99999]), eps ("single"))
776## backward - loss of accuracy
777%!assert (erfcinv (erfc ([-3 -1 -0.4 0.7 1.3 2.8])), [-3 -1 -0.4 0.7 1.3 2.8], -1e-12)
778%!assert (erfcinv (erfc (single ([-3 -1 -0.4 0.7 1.3 2.8]))), single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4)
779## exceptional
780%!assert (erfcinv ([2, 0, -0.1, 2.1]), [-Inf, Inf, NaN, NaN])
781%!error erfcinv (1+2i)
782
783%!error erfcinv ()
784%!error erfcinv (1, 2)
785*/
786
787DEFUN (erfc, args, ,
788 doc: /* -*- texinfo -*-
789@deftypefn {} {} erfc (@var{z})
790Compute the complementary error function.
791
792The complementary error function is defined as
793@tex
794$1 - {\rm erf} (z)$.
795@end tex
796@ifnottex
797@w{@code{1 - erf (@var{z})}}.
798@end ifnottex
799@seealso{erfcinv, erfcx, erfi, dawson, erf, erfinv}
800@end deftypefn */)
801{
802 if (args.length () != 1)
803 print_usage ();
804
805 return ovl (args(0).erfc ());
806}
807
808/*
809%!test
810%! a = -1i*sqrt (-1/(6.4187*6.4187));
811%! assert (erfc (a), erfc (real (a)));
812
813%!error erfc ()
814%!error erfc (1, 2)
815*/
816
817DEFUN (erfcx, args, ,
818 doc: /* -*- texinfo -*-
819@deftypefn {} {} erfcx (@var{z})
820Compute the scaled complementary error function.
821
822The scaled complementary error function is defined as
823@tex
824$$
825 e^{z^2} {\rm erfc} (z) \equiv e^{z^2} (1 - {\rm erf} (z))
826$$
827@end tex
828@ifnottex
829
830@example
831exp (z^2) * erfc (z)
832@end example
833
834@end ifnottex
835@seealso{erfc, erf, erfi, dawson, erfinv, erfcinv}
836@end deftypefn */)
837{
838 if (args.length () != 1)
839 print_usage ();
840
841 return ovl (args(0).erfcx ());
842}
843
844/*
845
846%!test
847%! x = [1+2i,-1+2i,1e-6+2e-6i,0+2i];
848%! assert (erfcx (x), exp (x.^2) .* erfc (x), -1.e-10);
849
850%!test
851%! x = [100, 100+20i];
852%! v = [0.0056416137829894329, 0.0054246791754558-0.00108483153786434i];
853%! assert (erfcx (x), v, -1.e-10);
854
855%!error erfcx ()
856%!error erfcx (1, 2)
857*/
858
859DEFUN (erfi, args, ,
860 doc: /* -*- texinfo -*-
861@deftypefn {} {} erfi (@var{z})
862Compute the imaginary error function.
863
864The imaginary error function is defined as
865@tex
866$$
867 -i {\rm erf} (iz)
868$$
869@end tex
870@ifnottex
871
872@example
873-i * erf (i*z)
874@end example
875
876@end ifnottex
877@seealso{erfc, erf, erfcx, dawson, erfinv, erfcinv}
878@end deftypefn */)
879{
880 if (args.length () != 1)
881 print_usage ();
882
883 return ovl (args(0).erfi ());
884}
885
886/*
887
888%!test
889%! x = [-0.1, 0.1, 1, 1+2i,-1+2i,1e-6+2e-6i,0+2i];
890%! assert (erfi (x), -i * erf (i*x), -1.e-10);
891
892%!error erfi ()
893%!error erfi (1, 2)
894*/
895
896DEFUN (dawson, args, ,
897 doc: /* -*- texinfo -*-
898@deftypefn {} {} dawson (@var{z})
899Compute the Dawson (scaled imaginary error) function.
900
901The Dawson function is defined as
902@tex
903$$
904 {\sqrt{\pi} \over 2} e^{-z^2} {\rm erfi} (z) \equiv -i {\sqrt{\pi} \over 2} e^{-z^2} {\rm erf} (iz)
905$$
906@end tex
907@ifnottex
908
909@example
910(sqrt (pi) / 2) * exp (-z^2) * erfi (z)
911@end example
912
913@end ifnottex
914@seealso{erfc, erf, erfcx, erfi, erfinv, erfcinv}
915@end deftypefn */)
916{
917 if (args.length () != 1)
918 print_usage ();
919
920 return ovl (args(0).dawson ());
921}
922
923/*
924
925%!test
926%! x = [0.1, 1, 1+2i,-1+2i,1e-4+2e-4i,0+2i];
927%! v = [0.099335992397852861, 0.53807950691, -13.38892731648-11.828715104i, 13.38892731648-11.828715104i, 0.0001000000073333+0.000200000001333i, 48.160012114291i];
928%! assert (dawson (x), v, -1.e-10);
929%! assert (dawson (-x), -v, -1.e-10);
930
931%!error dawson ()
932%!error dawson (1, 2)
933*/
934
935DEFUN (exp, args, ,
936 doc: /* -*- texinfo -*-
937@deftypefn {} {} exp (@var{x})
938Compute
939@tex
940$e^{x}$
941@end tex
942@ifnottex
943@code{e^x}
944@end ifnottex
945for each element of @var{x}.
946
947To compute the matrix exponential, @pxref{Linear Algebra}.
948@seealso{log}
949@end deftypefn */)
950{
951 if (args.length () != 1)
952 print_usage ();
953
954 return ovl (args(0).exp ());
955}
956
957/*
958%!assert (exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps))
959%!assert (exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps))
960%!assert (exp (single ([0, 1, -1, -1000])), single ([1, e, 1/e, 0]), sqrt (eps ("single")))
961%!assert (exp (single (1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps ("single")))
962
963%!assert (exp ([Inf, -Inf, NaN]), [Inf 0 NaN])
964%!assert (exp (single ([Inf, -Inf, NaN])), single ([Inf 0 NaN]))
965
966%!error exp ()
967%!error exp (1, 2)
968*/
969
970DEFUN (expm1, args, ,
971 doc: /* -*- texinfo -*-
972@deftypefn {} {} expm1 (@var{x})
973Compute
974@tex
975$ e^{x} - 1 $
976@end tex
977@ifnottex
978@code{exp (@var{x}) - 1}
979@end ifnottex
980accurately in the neighborhood of zero.
981@seealso{exp}
982@end deftypefn */)
983{
984 if (args.length () != 1)
985 print_usage ();
986
987 return ovl (args(0).expm1 ());
988}
989
990/*
991%!assert (expm1 (2*eps), 2*eps, 1e-29)
992
993%!assert (expm1 ([Inf, -Inf, NaN]), [Inf -1 NaN])
994%!assert (expm1 (single ([Inf, -Inf, NaN])), single ([Inf -1 NaN]))
995
996%!error expm1 ()
997%!error expm1 (1, 2)
998*/
999
1000DEFUN (isfinite, args, ,
1001 doc: /* -*- texinfo -*-
1002@deftypefn {} {} isfinite (@var{x})
1003Return a logical array which is true where the elements of @var{x} are
1004finite values and false where they are not.
1005
1006For example:
1007
1008@example
1009@group
1010isfinite ([13, Inf, NA, NaN])
1011 @result{} [ 1, 0, 0, 0 ]
1012@end group
1013@end example
1014@seealso{isinf, isnan, isna}
1015@end deftypefn */)
1016{
1017 if (args.length () != 1)
1018 print_usage ();
1019
1020 return ovl (args(0).isfinite ());
1021}
1022
1023/*
1024%!assert (! isfinite (Inf))
1025%!assert (! isfinite (NaN))
1026%!assert (isfinite (rand (1,10)))
1027
1028%!assert (! isfinite (single (Inf)))
1029%!assert (! isfinite (single (NaN)))
1030%!assert (isfinite (single (rand (1,10))))
1031%!assert (isfinite ('a'))
1032
1033%!error isfinite ()
1034%!error isfinite (1, 2)
1035*/
1036
1037DEFUN (fix, args, ,
1038 doc: /* -*- texinfo -*-
1039@deftypefn {} {} fix (@var{x})
1040Truncate fractional portion of @var{x} and return the integer portion.
1041
1042This is equivalent to rounding towards zero. If @var{x} is complex, return
1043@code{fix (real (@var{x})) + fix (imag (@var{x})) * I}.
1044
1045@example
1046@group
1047fix ([-2.7, 2.7])
1048 @result{} -2 2
1049@end group
1050@end example
1051@seealso{ceil, floor, round}
1052@end deftypefn */)
1053{
1054 if (args.length () != 1)
1055 print_usage ();
1056
1057 return ovl (args(0).fix ());
1058}
1059
1060/*
1061%!assert (fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1])
1062%!assert (fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i])
1063%!assert (fix (single ([1.1, 1, -1.1, -1])), single ([1, 1, -1, -1]))
1064%!assert (fix (single ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])), single ([1+i, 1+i, -1-i, -1-i]))
1065
1066%!error fix ()
1067%!error fix (1, 2)
1068*/
1069
1070DEFUN (floor, args, ,
1071 doc: /* -*- texinfo -*-
1072@deftypefn {} {} floor (@var{x})
1073Return the largest integer not greater than @var{x}.
1074
1075This is equivalent to rounding towards negative infinity. If @var{x} is
1076complex, return @code{floor (real (@var{x})) + floor (imag (@var{x})) * I}.
1077
1078@example
1079@group
1080floor ([-2.7, 2.7])
1081 @result{} -3 2
1082@end group
1083@end example
1084@seealso{ceil, round, fix}
1085@end deftypefn */)
1086{
1087 if (args.length () != 1)
1088 print_usage ();
1089
1090 return ovl (args(0).floor ());
1091}
1092
1093/*
1094%!assert (floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1])
1095%!assert (floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i])
1096%!assert (floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]))
1097%!assert (floor (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 1+i, -2-2i, -1-i]))
1098
1099%!error floor ()
1100%!error floor (1, 2)
1101*/
1102
1103DEFUN (gamma, args, ,
1104 doc: /* -*- texinfo -*-
1105@deftypefn {} {} gamma (@var{z})
1106Compute the Gamma function.
1107
1108The Gamma function is defined as
1109@tex
1110$$
1111 \Gamma (z) = \int_0^\infty t^{z-1} e^{-t} dt.
1112$$
1113@end tex
1114@ifnottex
1115
1116@example
1117@group
1118 infinity
1119 /
1120gamma (z) = | t^(z-1) exp (-t) dt.
1121 /
1122 t=0
1123@end group
1124@end example
1125
1126@end ifnottex
1127
1128Programming Note: The gamma function can grow quite large even for small
1129input values. In many cases it may be preferable to use the natural
1130logarithm of the gamma function (@code{gammaln}) in calculations to minimize
1131loss of precision. The final result is then
1132@code{exp (@var{result_using_gammaln}).}
1133@seealso{gammainc, gammaln, factorial}
1134@end deftypefn */)
1135{
1136 if (args.length () != 1)
1137 print_usage ();
1138
1139 return ovl (args(0).gamma ());
1140}
1141
1142/*
1143%!test
1144%! a = -1i*sqrt (-1/(6.4187*6.4187));
1145%! assert (gamma (a), gamma (real (a)));
1146
1147%!test
1148%! x = [.5, 1, 1.5, 2, 3, 4, 5];
1149%! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1150%! assert (gamma (x), v, sqrt (eps));
1151
1152%!test
1153%! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
1154%! assert (gamma (a), gamma (real (a)));
1155
1156%!test
1157%! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
1158%! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1159%! assert (gamma (x), v, sqrt (eps ("single")));
1160
1161%!test
1162%! ## Test exceptional values
1163%! x = [-Inf, -1, -0, 0, 1, Inf, NaN];
1164%! v = [Inf, Inf, -Inf, Inf, 1, Inf, NaN];
1165%! assert (gamma (x), v);
1166%! assert (gamma (single (x)), single (v));
1167
1168%!error gamma ()
1169%!error gamma (1, 2)
1170*/
1171
1172DEFUN (imag, args, ,
1173 doc: /* -*- texinfo -*-
1174@deftypefn {} {} imag (@var{z})
1175Return the imaginary part of @var{z} as a real number.
1176@seealso{real, conj}
1177@end deftypefn */)
1178{
1179 if (args.length () != 1)
1180 print_usage ();
1181
1182 return ovl (args(0).imag ());
1183}
1184
1185/*
1186%!assert (imag (1), 0)
1187%!assert (imag (i), 1)
1188%!assert (imag (1+i), 1)
1189%!assert (imag ([i, 1; 1, i]), full (eye (2)))
1190
1191%!assert (imag (single (1)), single (0))
1192%!assert (imag (single (i)), single (1))
1193%!assert (imag (single (1+i)), single (1))
1194%!assert (imag (single ([i, 1; 1, i])), full (eye (2,"single")))
1195
1196%!error imag ()
1197%!error imag (1, 2)
1198*/
1199
1200DEFUNX ("isalnum", Fisalnum, args, ,
1201 doc: /* -*- texinfo -*-
1202@deftypefn {} {} isalnum (@var{s})
1203Return a logical array which is true where the elements of @var{s} are
1204letters or digits and false where they are not.
1205
1206This is equivalent to (@code{isalpha (@var{s}) | isdigit (@var{s})}).
1207@seealso{isalpha, isdigit, ispunct, isspace, iscntrl}
1208@end deftypefn */)
1209{
1210 if (args.length () != 1)
1211 print_usage ();
1212
1213 return ovl (args(0).xisalnum ());
1214}
1215
1216/*
1217%!test
1218%! charset = char (0:127);
1219%! result = false (1, 128);
1220%! result(double ("A":"Z") + 1) = true;
1221%! result(double ("0":"9") + 1) = true;
1222%! result(double ("a":"z") + 1) = true;
1223%! assert (isalnum (charset), result);
1224%!assert (isalnum(["Ä8Aa?"; "(Uß ;"]), logical ([1 1 1 1 1 0; 0 1 1 1 0 0]))
1225
1226%!error isalnum ()
1227%!error isalnum (1, 2)
1228*/
1229
1230DEFUNX ("isalpha", Fisalpha, args, ,
1231 doc: /* -*- texinfo -*-
1232@deftypefn {} {} isalpha (@var{s})
1233Return a logical array which is true where the elements of @var{s} are
1234letters and false where they are not.
1235
1236This is equivalent to (@code{islower (@var{s}) | isupper (@var{s})}).
1237@seealso{isdigit, ispunct, isspace, iscntrl, isalnum, islower, isupper}
1238@end deftypefn */)
1239{
1240 if (args.length () != 1)
1241 print_usage ();
1242
1243 return ovl (args(0).xisalpha ());
1244}
1245
1246/*
1247%!test
1248%! charset = char (0:127);
1249%! result = false (1, 128);
1250%! result(double ("A":"Z") + 1) = true;
1251%! result(double ("a":"z") + 1) = true;
1252%! assert (isalpha (charset), result);
1253%!assert (isalpha("Ä8Aa(Uß ;"), logical ([1 1 0 1 1 0 1 1 1 0 0]))
1254
1255%!error isalpha ()
1256%!error isalpha (1, 2)
1257*/
1258
1259DEFUNX ("isascii", Fisascii, args, ,
1260 doc: /* -*- texinfo -*-
1261@deftypefn {} {} isascii (@var{s})
1262Return a logical array which is true where the elements of @var{s} are
1263ASCII characters (in the range 0 to 127 decimal) and false where they are
1264not.
1265@end deftypefn */)
1266{
1267 if (args.length () != 1)
1268 print_usage ();
1269
1270 return ovl (args(0).xisascii ());
1271}
1272
1273/*
1274%!test
1275%! charset = char (0:127);
1276%! result = true (1, 128);
1277%! assert (isascii (charset), result);
1278
1279%!error isascii ()
1280%!error isascii (1, 2)
1281*/
1282
1283DEFUNX ("iscntrl", Fiscntrl, args, ,
1284 doc: /* -*- texinfo -*-
1285@deftypefn {} {} iscntrl (@var{s})
1286Return a logical array which is true where the elements of @var{s} are
1287control characters and false where they are not.
1288@seealso{ispunct, isspace, isalpha, isdigit}
1289@end deftypefn */)
1290{
1291 if (args.length () != 1)
1292 print_usage ();
1293
1294 return ovl (args(0).xiscntrl ());
1295}
1296
1297/*
1298%!test
1299%! charset = char (0:127);
1300%! result = false (1, 128);
1301%! result(1:32) = true;
1302%! result(128) = true;
1303%! assert (iscntrl (charset), result);
1304
1305%!error iscntrl ()
1306%!error iscntrl (1, 2)
1307*/
1308
1309DEFUNX ("isdigit", Fisdigit, args, ,
1310 doc: /* -*- texinfo -*-
1311@deftypefn {} {} isdigit (@var{s})
1312Return a logical array which is true where the elements of @var{s} are
1313decimal digits (0-9) and false where they are not.
1314@seealso{isxdigit, isalpha, isletter, ispunct, isspace, iscntrl}
1315@end deftypefn */)
1316{
1317 if (args.length () != 1)
1318 print_usage ();
1319
1320 return ovl (args(0).xisdigit ());
1321}
1322
1323/*
1324%!test
1325%! charset = char (0:127);
1326%! result = false (1, 128);
1327%! result(double ("0":"9") + 1) = true;
1328%! assert (isdigit (charset), result);
1329%!assert (isdigit("Ä8Aa(Uß ;"), logical ([0 0 1 0 0 0 0 0 0 0 0]))
1330
1331%!error isdigit ()
1332%!error isdigit (1, 2)
1333*/
1334
1335DEFUN (isinf, args, ,
1336 doc: /* -*- texinfo -*-
1337@deftypefn {} {} isinf (@var{x})
1338Return a logical array which is true where the elements of @var{x} are
1339infinite and false where they are not.
1340
1341For example:
1342
1343@example
1344@group
1345isinf ([13, Inf, NA, NaN])
1346 @result{} [ 0, 1, 0, 0 ]
1347@end group
1348@end example
1349@seealso{isfinite, isnan, isna}
1350@end deftypefn */)
1351{
1352 if (args.length () != 1)
1353 print_usage ();
1354
1355 return ovl (args(0).isinf ());
1356}
1357
1358/*
1359%!assert (isinf (Inf))
1360%!assert (! isinf (NaN))
1361%!assert (! isinf (NA))
1362%!assert (isinf (rand (1,10)), false (1,10))
1363%!assert (isinf ([NaN -Inf -1 0 1 Inf NA]), [false, true, false, false, false, true, false])
1364
1365%!assert (isinf (single (Inf)))
1366%!assert (! isinf (single (NaN)))
1367%!assert (! isinf (single (NA)))
1368%!assert (isinf (single (rand (1,10))), false (1,10))
1369%!assert (isinf (single ([NaN -Inf -1 0 1 Inf NA])), [false, true, false, false, false, true, false])
1370%!assert (! isinf ('a'))
1371
1372%!error isinf ()
1373%!error isinf (1, 2)
1374*/
1375
1376DEFUNX ("isgraph", Fisgraph, args, ,
1377 doc: /* -*- texinfo -*-
1378@deftypefn {} {} isgraph (@var{s})
1379Return a logical array which is true where the elements of @var{s} are
1380printable characters (but not the space character) and false where they are
1381not.
1382@seealso{isprint}
1383@end deftypefn */)
1384{
1385 if (args.length () != 1)
1386 print_usage ();
1387
1388 return ovl (args(0).xisgraph ());
1389}
1390
1391/*
1392%!test
1393%! charset = char (0:127);
1394%! result = false (1, 128);
1395%! result(34:127) = true;
1396%! assert (isgraph (charset), result);
1397%!assert (isgraph("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 0 1]))
1398
1399%!error isgraph ()
1400%!error isgraph (1, 2)
1401*/
1402
1403DEFUNX ("islower", Fislower, args, ,
1404 doc: /* -*- texinfo -*-
1405@deftypefn {} {} islower (@var{s})
1406Return a logical array which is true where the elements of @var{s} are
1407lowercase letters and false where they are not.
1408@seealso{isupper, isalpha, isletter, isalnum}
1409@end deftypefn */)
1410{
1411 if (args.length () != 1)
1412 print_usage ();
1413
1414 return ovl (args(0).xislower ());
1415}
1416
1417/*
1418%!test
1419%! charset = char (0:127);
1420%! result = false (1, 128);
1421%! result(double ("a":"z") + 1) = true;
1422%! assert (islower (charset), result);
1423%!assert (islower("Ä8Aa(Uß ;"), logical ([0 0 0 0 1 0 0 1 1 0 0]))
1424
1425%!error islower ()
1426%!error islower (1, 2)
1427*/
1428
1429DEFUN (isna, args, ,
1430 doc: /* -*- texinfo -*-
1431@deftypefn {} {} isna (@var{x})
1432Return a logical array which is true where the elements of @var{x} are
1433NA (missing) values and false where they are not.
1434
1435For example:
1436
1437@example
1438@group
1439isna ([13, Inf, NA, NaN])
1440 @result{} [ 0, 0, 1, 0 ]
1441@end group
1442@end example
1443@seealso{isnan, isinf, isfinite}
1444@end deftypefn */)
1445{
1446 if (args.length () != 1)
1447 print_usage ();
1448
1449 return ovl (args(0).isna ());
1450}
1451
1452/*
1453%!assert (! isna (Inf))
1454%!assert (! isna (NaN))
1455%!assert (isna (NA))
1456%!assert (isna (rand (1,10)), false (1,10))
1457%!assert (isna ([NaN -Inf -1 0 1 Inf NA]), [false, false, false, false, false, false, true])
1458
1459%!assert (! isna (single (Inf)))
1460%!assert (! isna (single (NaN)))
1461%!assert (isna (single (NA)))
1462%!assert (isna (single (rand (1,10))), false (1,10))
1463%!assert (isna (single ([NaN -Inf -1 0 1 Inf NA])), [false, false, false, false, false, false, true])
1464
1465%!error isna ()
1466%!error isna (1, 2)
1467*/
1468
1469DEFUN (isnan, args, ,
1470 doc: /* -*- texinfo -*-
1471@deftypefn {} {} isnan (@var{x})
1472Return a logical array which is true where the elements of @var{x} are
1473NaN values and false where they are not.
1474
1475NA values are also considered NaN values. For example:
1476
1477@example
1478@group
1479isnan ([13, Inf, NA, NaN])
1480 @result{} [ 0, 0, 1, 1 ]
1481@end group
1482@end example
1483@seealso{isna, isinf, isfinite}
1484@end deftypefn */)
1485{
1486 if (args.length () != 1)
1487 print_usage ();
1488
1489 return ovl (args(0).isnan ());
1490}
1491
1492/*
1493%!assert (! isnan (Inf))
1494%!assert (isnan (NaN))
1495%!assert (isnan (NA))
1496%!assert (isnan (rand (1,10)), false (1,10))
1497%!assert (isnan ([NaN -Inf -1 0 1 Inf NA]), [true, false, false, false, false, false, true])
1498
1499%!assert (! isnan (single (Inf)))
1500%!assert (isnan (single (NaN)))
1501%!assert (isnan (single (NA)))
1502%!assert (isnan (single (rand (1,10))), false (1,10))
1503%!assert (isnan (single ([NaN -Inf -1 0 1 Inf NA])), [true, false, false, false, false, false, true])
1504%!assert (! isnan ('a'))
1505
1506%!error isnan ()
1507%!error isnan (1, 2)
1508*/
1509
1510DEFUNX ("isprint", Fisprint, args, ,
1511 doc: /* -*- texinfo -*-
1512@deftypefn {} {} isprint (@var{s})
1513Return a logical array which is true where the elements of @var{s} are
1514printable characters (including the space character) and false where they
1515are not.
1516@seealso{isgraph}
1517@end deftypefn */)
1518{
1519 if (args.length () != 1)
1520 print_usage ();
1521
1522 return ovl (args(0).xisprint ());
1523}
1524
1525/*
1526%!test
1527%! charset = char (0:127);
1528%! result = false (1, 128);
1529%! result(33:127) = true;
1530%! assert (isprint (charset), result);
1531%!assert (isprint("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 1 1]))
1532
1533%!error isprint ()
1534%!error isprint (1, 2)
1535*/
1536
1537DEFUNX ("ispunct", Fispunct, args, ,
1538 doc: /* -*- texinfo -*-
1539@deftypefn {} {} ispunct (@var{s})
1540Return a logical array which is true where the elements of @var{s} are
1541punctuation characters and false where they are not.
1542@seealso{isalpha, isdigit, isspace, iscntrl}
1543@end deftypefn */)
1544{
1545 if (args.length () != 1)
1546 print_usage ();
1547
1548 return ovl (args(0).xispunct ());
1549}
1550
1551/*
1552%!test
1553%! charset = char (0:127);
1554%! result = false (1, 128);
1555%! result(34:48) = true;
1556%! result(59:65) = true;
1557%! result(92:97) = true;
1558%! result(124:127) = true;
1559%! assert (ispunct (charset), result);
1560%!assert (ispunct("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 1 0 0 0 0 1]))
1561
1562%!error ispunct ()
1563%!error ispunct (1, 2)
1564*/
1565
1566DEFUNX ("isspace", Fisspace, args, ,
1567 doc: /* -*- texinfo -*-
1568@deftypefn {} {} isspace (@var{s})
1569Return a logical array which is true where the elements of @var{s} are
1570whitespace characters (space, formfeed, newline, carriage return, tab, and
1571vertical tab) and false where they are not.
1572@seealso{iscntrl, ispunct, isalpha, isdigit}
1573@end deftypefn */)
1574{
1575 if (args.length () != 1)
1576 print_usage ();
1577
1578 return ovl (args(0).xisspace ());
1579}
1580
1581/*
1582%!test
1583%! charset = char (0:127);
1584%! result = false (1, 128);
1585%! result(double (" \f\n\r\t\v") + 1) = true;
1586%! assert (isspace (charset), result);
1587%!assert (isspace("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 0 0 0 0 1 0]))
1588
1589%!error isspace ()
1590%!error isspace (1, 2)
1591*/
1592
1593DEFUNX ("isupper", Fisupper, args, ,
1594 doc: /* -*- texinfo -*-
1595@deftypefn {} {} isupper (@var{s})
1596Return a logical array which is true where the elements of @var{s} are
1597uppercase letters and false where they are not.
1598@seealso{islower, isalpha, isletter, isalnum}
1599@end deftypefn */)
1600{
1601 if (args.length () != 1)
1602 print_usage ();
1603
1604 return ovl (args(0).xisupper ());
1605}
1606
1607/*
1608%!test
1609%! charset = char (0:127);
1610%! result = false (1, 128);
1611%! result(double ("A":"Z") + 1) = true;
1612%! assert (isupper (charset), result);
1613%!assert (isupper("Ä8Aa(Uß ;"), logical ([1 1 0 1 0 0 1 0 0 0 0]))
1614
1615%!error isupper ()
1616%!error isupper (1, 2)
1617*/
1618
1619DEFUNX ("isxdigit", Fisxdigit, args, ,
1620 doc: /* -*- texinfo -*-
1621@deftypefn {} {} isxdigit (@var{s})
1622Return a logical array which is true where the elements of @var{s} are
1623hexadecimal digits (0-9 and @nospell{a-fA-F}).
1624@seealso{isdigit}
1625@end deftypefn */)
1626{
1627 if (args.length () != 1)
1628 print_usage ();
1629
1630 return ovl (args(0).xisxdigit ());
1631}
1632
1633/*
1634%!test
1635%! charset = char (0:127);
1636%! result = false (1, 128);
1637%! result(double ("A":"F") + 1) = true;
1638%! result(double ("0":"9") + 1) = true;
1639%! result(double ("a":"f") + 1) = true;
1640%! assert (isxdigit (charset), result);
1641%!assert (isxdigit("Ä8Aa(Uß ;"), logical ([0 0 1 1 1 0 0 0 0 0 0]))
1642
1643%!error isxdigit ()
1644%!error isxdigit (1, 2)
1645*/
1646
1647DEFUN (lgamma, args, ,
1648 doc: /* -*- texinfo -*-
1649@deftypefn {} {} gammaln (@var{x})
1650@deftypefnx {} {} lgamma (@var{x})
1651Return the natural logarithm of the gamma function of @var{x}.
1652@seealso{gamma, gammainc}
1653@end deftypefn */)
1654{
1655 if (args.length () != 1)
1656 print_usage ();
1657
1658 return ovl (args(0).lgamma ());
1659}
1660
1661/*
1662%!test
1663%! a = -1i*sqrt (-1/(6.4187*6.4187));
1664%! assert (gammaln (a), gammaln (real (a)));
1665
1666%!test
1667%! x = [.5, 1, 1.5, 2, 3, 4, 5];
1668%! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1669%! assert (gammaln (x), log (v), sqrt (eps));
1670
1671%!test
1672%! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
1673%! assert (gammaln (a), gammaln (real (a)));
1674
1675%!test
1676%! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
1677%! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1678%! assert (gammaln (x), log (v), sqrt (eps ("single")));
1679
1680%!test
1681%! x = [-1, 0, 1, Inf];
1682%! v = [Inf, Inf, 0, Inf];
1683%! assert (gammaln (x), v);
1684%! assert (gammaln (single (x)), single (v));
1685
1686%!error gammaln ()
1687%!error gammaln (1,2)
1688*/
1689
1690DEFUN (log, args, ,
1691 doc: /* -*- texinfo -*-
1692@deftypefn {} {} log (@var{x})
1693Compute the natural logarithm,
1694@tex
1695$\ln{(x)},$
1696@end tex
1697@ifnottex
1698@code{ln (@var{x})},
1699@end ifnottex
1700for each element of @var{x}.
1701
1702To compute the matrix logarithm, @pxref{Linear Algebra}.
1703@seealso{exp, log1p, log2, log10, logspace}
1704@end deftypefn */)
1705{
1706 if (args.length () != 1)
1707 print_usage ();
1708
1709 return ovl (args(0).log ());
1710}
1711
1712/*
1713%!assert (log ([1, e, e^2]), [0, 1, 2], sqrt (eps))
1714%!assert (log ([-0.5, -1.5, -2.5]), log ([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps))
1715
1716%!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ("single")))
1717%!assert (log (single ([-0.5, -1.5, -2.5])), single (log ([0.5, 1.5, 2.5]) + pi*1i), 4*eps ("single"))
1718
1719%!error log ()
1720%!error log (1, 2)
1721*/
1722
1723DEFUN (log10, args, ,
1724 doc: /* -*- texinfo -*-
1725@deftypefn {} {} log10 (@var{x})
1726Compute the base-10 logarithm of each element of @var{x}.
1727@seealso{log, log2, logspace, exp}
1728@end deftypefn */)
1729{
1730 if (args.length () != 1)
1731 print_usage ();
1732
1733 return ovl (args(0).log10 ());
1734}
1735
1736/*
1737%!assert (log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps))
1738%!assert (log10 (single ([0.01, 0.1, 1, 10, 100])), single ([-2, -1, 0, 1, 2]), sqrt (eps ("single")))
1739
1740%!error log10 ()
1741%!error log10 (1, 2)
1742*/
1743
1744DEFUN (log1p, args, ,
1745 doc: /* -*- texinfo -*-
1746@deftypefn {} {} log1p (@var{x})
1747Compute
1748@tex
1749$\ln{(1 + x)}$
1750@end tex
1751@ifnottex
1752@code{log (1 + @var{x})}
1753@end ifnottex
1754accurately in the neighborhood of zero.
1755@seealso{log, exp, expm1}
1756@end deftypefn */)
1757{
1758 if (args.length () != 1)
1759 print_usage ();
1760
1761 return ovl (args(0).log1p ());
1762}
1763
1764/*
1765%!assert (log1p ([0, 2*eps, -2*eps]), [0, 2*eps, -2*eps], 1e-29)
1766%!assert (log1p (single ([0, 2*eps, -2*eps])), ...
1767%! single ([0, 2*eps, -2*eps]), 1e-29)
1768## Compare to result from Wolfram Alpha rounded to 16 significant digits
1769%!assert <*62094> (log1p (0.1i), ...
1770%! 0.004975165426584041 + 0.09966865249116203i, eps (0.2))
1771%!assert <*62094> (log1p (single (0.1i)), ...
1772%! single (0.004975165426584041 + 0.09966865249116203i), ...
1773%! eps (single (0.2)))
1774
1775%!error log1p ()
1776%!error log1p (1, 2)
1777*/
1778
1779DEFUN (real, args, ,
1780 doc: /* -*- texinfo -*-
1781@deftypefn {} {} real (@var{z})
1782Return the real part of @var{z}.
1783@seealso{imag, conj}
1784@end deftypefn */)
1785{
1786 if (args.length () != 1)
1787 print_usage ();
1788
1789 return ovl (args(0).real ());
1790}
1791
1792/*
1793%!assert (real (1), 1)
1794%!assert (real (i), 0)
1795%!assert (real (1+i), 1)
1796%!assert (real ([1, i; i, 1]), full (eye (2)))
1797
1798%!assert (real (single (1)), single (1))
1799%!assert (real (single (i)), single (0))
1800%!assert (real (single (1+i)), single (1))
1801%!assert (real (single ([1, i; i, 1])), full (eye (2, "single")))
1802
1803%!error real ()
1804%!error real (1, 2)
1805*/
1806
1807DEFUN (round, args, ,
1808 doc: /* -*- texinfo -*-
1809@deftypefn {} {} round (@var{x})
1810Return the integer nearest to @var{x}.
1811
1812If @var{x} is complex, return
1813@code{round (real (@var{x})) + round (imag (@var{x})) * I}. If there
1814are two nearest integers, return the one further away from zero.
1815
1816@example
1817@group
1818round ([-2.7, 2.7])
1819 @result{} -3 3
1820@end group
1821@end example
1822@seealso{ceil, floor, fix, roundb}
1823@end deftypefn */)
1824{
1825 if (args.length () != 1)
1826 print_usage ();
1827
1828 return ovl (args(0).round ());
1829}
1830
1831/*
1832%!assert (round (1), 1)
1833%!assert (round (1.1), 1)
1834%!assert (round (5.5), 6)
1835%!assert (round (i), i)
1836%!assert (round (2.5+3.5i), 3+4i)
1837%!assert (round (-2.6), -3)
1838%!assert (round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
1839
1840%!assert (round (single (1)), single (1))
1841%!assert (round (single (1.1)), single (1))
1842%!assert (round (single (5.5)), single (6))
1843%!assert (round (single (i)), single (i))
1844%!assert (round (single (2.5+3.5i)), single (3+4i))
1845%!assert (round (single (-2.6)), single (-3))
1846%!assert (round (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
1847
1848%!error round ()
1849%!error round (1, 2)
1850*/
1851
1852DEFUN (roundb, args, ,
1853 doc: /* -*- texinfo -*-
1854@deftypefn {} {} roundb (@var{x})
1855Return the integer nearest to @var{x}. If there are two nearest
1856integers, return the even one (banker's rounding).
1857
1858If @var{x} is complex,
1859return @code{roundb (real (@var{x})) + roundb (imag (@var{x})) * I}.
1860@seealso{round}
1861@end deftypefn */)
1862{
1863 if (args.length () != 1)
1864 print_usage ();
1865
1866 return ovl (args(0).roundb ());
1867}
1868
1869/*
1870%!assert (roundb (1), 1)
1871%!assert (roundb (1.1), 1)
1872%!assert (roundb (1.5), 2)
1873%!assert (roundb (4.5), 4)
1874%!assert (roundb (i), i)
1875%!assert (roundb (2.5+3.5i), 2+4i)
1876%!assert (roundb (-2.6), -3)
1877%!assert (roundb ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
1878
1879%!assert (roundb (single (1)), single (1))
1880%!assert (roundb (single (1.1)), single (1))
1881%!assert (roundb (single (1.5)), single (2))
1882%!assert (roundb (single (4.5)), single (4))
1883%!assert (roundb (single (i)), single (i))
1884%!assert (roundb (single (2.5+3.5i)), single (2+4i))
1885%!assert (roundb (single (-2.6)), single (-3))
1886%!assert (roundb (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
1887
1888%!error roundb ()
1889%!error roundb (1, 2)
1890*/
1891
1892DEFUN (sign, args, ,
1893 doc: /* -*- texinfo -*-
1894@deftypefn {} {} sign (@var{x})
1895Compute the @dfn{signum} function.
1896
1897This is defined as
1898@tex
1899$$
1900{\rm sign} (@var{x}) = \cases{1,&$x>0$;\cr 0,&$x=0$;\cr -1,&$x<0$.\cr}
1901$$
1902@end tex
1903@ifnottex
1904
1905@example
1906@group
1907 -1, x < 0;
1908sign (x) = 0, x = 0;
1909 1, x > 0.
1910@end group
1911@end example
1912
1913@end ifnottex
1914
1915For complex arguments, @code{sign} returns @code{x ./ abs (@var{x})}.
1916
1917Note that @code{sign (-0.0)} is 0. Although IEEE 754 floating point
1918allows zero to be signed, 0.0 and -0.0 compare equal. If you must test
1919whether zero is signed, use the @code{signbit} function.
1920@seealso{signbit}
1921@end deftypefn */)
1922{
1923 if (args.length () != 1)
1924 print_usage ();
1925
1926 return ovl (args(0).signum ());
1927}
1928
1929/*
1930%!assert (sign (-2) , -1)
1931%!assert (sign (0), 0)
1932%!assert (sign (3), 1)
1933%!assert (sign ([1, -pi; e, 0]), [1, -1; 1, 0])
1934
1935%!assert (sign (single (-2)) , single (-1))
1936%!assert (sign (single (0)), single (0))
1937%!assert (sign (single (3)), single (1))
1938%!assert (sign (single ([1, -pi; e, 0])), single ([1, -1; 1, 0]))
1939
1940%!error sign ()
1941%!error sign (1, 2)
1942*/
1943
1944DEFUNX ("signbit", Fsignbit, args, ,
1945 doc: /* -*- texinfo -*-
1946@deftypefn {} {} signbit (@var{x})
1947Return logical true if the value of @var{x} has its sign bit set and false
1948otherwise.
1949
1950This behavior is consistent with the other logical functions.
1951@xref{Logical Values}. The behavior differs from the C language function
1952which returns nonzero if the sign bit is set.
1953
1954This is not the same as @code{x < 0.0}, because IEEE 754 floating point
1955allows zero to be signed. The comparison @code{-0.0 < 0.0} is false,
1956but @code{signbit (-0.0)} will return a nonzero value.
1957@seealso{sign}
1958@end deftypefn */)
1959{
1960 if (args.length () != 1)
1961 print_usage ();
1962
1963 octave_value tmp = args(0).xsignbit ();
1964
1965 return ovl (tmp != 0);
1966}
1967
1968/*
1969%!assert (signbit (1) == 0)
1970%!assert (signbit (-2) != 0)
1971%!assert (signbit (0) == 0)
1972%!assert (signbit (-0) != 0)
1973
1974%!assert (signbit (single (1)) == 0)
1975%!assert (signbit (single (-2)) != 0)
1976%!assert (signbit (single (0)) == 0)
1977%!assert (signbit (single (-0)) != 0)
1978
1979%!error sign ()
1980%!error sign (1, 2)
1981*/
1982
1983DEFUN (sin, args, ,
1984 doc: /* -*- texinfo -*-
1985@deftypefn {} {} sin (@var{x})
1986Compute the sine for each element of @var{x} in radians.
1987@seealso{asin, sind, sinh}
1988@end deftypefn */)
1989{
1990 if (args.length () != 1)
1991 print_usage ();
1992
1993 return ovl (args(0).sin ());
1994}
1995
1996/*
1997%!shared rt2, rt3
1998%! rt2 = sqrt (2);
1999%! rt3 = sqrt (3);
2000
2001%!test
2002%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
2003%! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
2004%! assert (sin (x), v, sqrt (eps));
2005
2006%!test
2007%! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
2008%! v = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
2009%! assert (sin (x), v, sqrt (eps ("single")));
2010
2011%!error sin ()
2012%!error sin (1, 2)
2013*/
2014
2015DEFUN (sinh, args, ,
2016 doc: /* -*- texinfo -*-
2017@deftypefn {} {} sinh (@var{x})
2018Compute the hyperbolic sine for each element of @var{x}.
2019@seealso{asinh, cosh, tanh}
2020@end deftypefn */)
2021{
2022 if (args.length () != 1)
2023 print_usage ();
2024
2025 return ovl (args(0).sinh ());
2026}
2027
2028/*
2029%!test
2030%! x = [0, pi/2*i, pi*i, 3*pi/2*i];
2031%! v = [0, i, 0, -i];
2032%! assert (sinh (x), v, sqrt (eps));
2033
2034%!test
2035%! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
2036%! v = single ([0, i, 0, -i]);
2037%! assert (sinh (x), v, sqrt (eps ("single")));
2038
2039%!error sinh ()
2040%!error sinh (1, 2)
2041*/
2042
2043DEFUN (sqrt, args, ,
2044 doc: /* -*- texinfo -*-
2045@deftypefn {} {} sqrt (@var{x})
2046Compute the square root of each element of @var{x}.
2047
2048If @var{x} is negative, a complex result is returned.
2049
2050To compute the matrix square root, @pxref{Linear Algebra}.
2051@seealso{realsqrt, nthroot}
2052@end deftypefn */)
2053{
2054 if (args.length () != 1)
2055 print_usage ();
2056
2057 return ovl (args(0).sqrt ());
2058}
2059
2060/*
2061%!assert (sqrt (4), 2)
2062%!assert (sqrt (-1), i)
2063%!assert (sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps))
2064%!assert (sqrt ([4, -4; i, 1-i]), [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt (eps))
2065
2066%!assert (sqrt (single (4)), single (2))
2067%!assert (sqrt (single (-1)), single (i))
2068%!assert (sqrt (single (1+i)), single (exp (0.5 * log (1+i))), sqrt (eps ("single")))
2069%!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")))
2070
2071%!error sqrt ()
2072%!error sqrt (1, 2)
2073*/
2074
2075DEFUN (tan, args, ,
2076 doc: /* -*- texinfo -*-
2077@deftypefn {} {} tan (@var{z})
2078Compute the tangent for each element of @var{x} in radians.
2079@seealso{atan, tand, tanh}
2080@end deftypefn */)
2081{
2082 if (args.length () != 1)
2083 print_usage ();
2084
2085 return ovl (args(0).tan ());
2086}
2087
2088/*
2089%!shared rt2, rt3
2090%! rt2 = sqrt (2);
2091%! rt3 = sqrt (3);
2092
2093%!test
2094%! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
2095%! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
2096%! assert (tan (x), v, sqrt (eps));
2097
2098%!test
2099%! x = single ([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
2100%! v = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
2101%! assert (tan (x), v, sqrt (eps ("single")));
2102
2103%!error tan ()
2104%!error tan (1, 2)
2105*/
2106
2107DEFUN (tanh, args, ,
2108 doc: /* -*- texinfo -*-
2109@deftypefn {} {} tanh (@var{x})
2110Compute hyperbolic tangent for each element of @var{x}.
2111@seealso{atanh, sinh, cosh}
2112@end deftypefn */)
2113{
2114 if (args.length () != 1)
2115 print_usage ();
2116
2117 return ovl (args(0).tanh ());
2118}
2119
2120/*
2121%!test
2122%! x = [0, pi*i];
2123%! v = [0, 0];
2124%! assert (tanh (x), v, sqrt (eps));
2125
2126%!test
2127%! x = single ([0, pi*i]);
2128%! v = single ([0, 0]);
2129%! assert (tanh (x), v, sqrt (eps ("single")));
2130
2131%!error tanh ()
2132%!error tanh (1, 2)
2133*/
2134
2135DEFUNX ("tolower", Ftolower, args, ,
2136 doc: /* -*- texinfo -*-
2137@deftypefn {} {} tolower (@var{s})
2138@deftypefnx {} {} lower (@var{s})
2139Return a copy of the string or cell string @var{s}, with each uppercase
2140character replaced by the corresponding lowercase one; non-alphabetic
2141characters are left unchanged.
2142
2143For example:
2144
2145@example
2146@group
2147tolower ("MiXeD cAsE 123")
2148 @result{} "mixed case 123"
2149@end group
2150@end example
2151@seealso{toupper}
2152@end deftypefn */)
2153{
2154 if (args.length () != 1)
2155 print_usage ();
2156
2157 return ovl (args(0).xtolower ());
2158}
2159
2160DEFALIAS (lower, tolower);
2161
2162/*
2163%!assert (tolower ("OCTAVE"), "octave")
2164%!assert (tolower ("123OCTave! _&"), "123octave! _&")
2165%!assert (tolower ({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}})
2166%!assert (tolower (["ABC"; "DEF"]), ["abc"; "def"])
2167%!assert (tolower ({["ABC"; "DEF"]}), {["abc";"def"]})
2168%!assert (tolower (["ABCÄÖÜSS"; "abcäöüß"]), ["abcäöüss"; "abcäöüß"])
2169%!assert (tolower (repmat ("ÄÖÜ", 2, 1, 3)), repmat ("äöü", 2, 1, 3))
2170%!assert (tolower (68), 68)
2171%!assert (tolower ({[68, 68; 68, 68]}), {[68, 68; 68, 68]})
2172%!assert (tolower (68i), 68i)
2173%!assert (tolower ({[68i, 68; 68, 68i]}), {[68i, 68; 68, 68i]})
2174%!assert (tolower (single (68i)), single (68i))
2175%!assert (tolower ({single([68i, 68; 68, 68i])}), {single([68i, 68; 68, 68i])})
2176
2177%!test
2178%! classes = {@char, @double, @single, ...
2179%! @int8, @int16, @int32, @int64, ...
2180%! @uint8, @uint16, @uint32, @uint64};
2181%! for i = 1:numel (classes)
2182%! cls = classes{i};
2183%! assert (class (tolower (cls (97))), class (cls (97)));
2184%! assert (class (tolower (cls ([98, 99]))), class (cls ([98, 99])));
2185%! endfor
2186%!test
2187%! a(3,3,3,3) = "D";
2188%! assert (tolower (a)(3,3,3,3), "d");
2189
2190%!test
2191%! charset = char (0:127);
2192%! result = charset;
2193%! result (double ("A":"Z") + 1) = result (double ("a":"z") + 1);
2194%! assert (tolower (charset), result);
2195
2196%!error <Invalid call to tolower> lower ()
2197%!error <Invalid call to tolower> tolower ()
2198%!error tolower (1, 2)
2199*/
2200
2201DEFUNX ("toupper", Ftoupper, args, ,
2202 doc: /* -*- texinfo -*-
2203@deftypefn {} {} toupper (@var{s})
2204@deftypefnx {} {} upper (@var{s})
2205Return a copy of the string or cell string @var{s}, with each lowercase
2206character replaced by the corresponding uppercase one; non-alphabetic
2207characters are left unchanged.
2208
2209For example:
2210
2211@example
2212@group
2213toupper ("MiXeD cAsE 123")
2214 @result{} "MIXED CASE 123"
2215@end group
2216@end example
2217@seealso{tolower}
2218@end deftypefn */)
2219{
2220 if (args.length () != 1)
2221 print_usage ();
2222
2223 return ovl (args(0).xtoupper ());
2224}
2225
2226DEFALIAS (upper, toupper);
2227
2228/*
2229%!assert (toupper ("octave"), "OCTAVE")
2230%!assert (toupper ("123OCTave! _&"), "123OCTAVE! _&")
2231%!assert (toupper ({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI", {"JKL"}}})
2232%!assert (toupper (["abc"; "def"]), ["ABC"; "DEF"])
2233%!assert (toupper ({["abc"; "def"]}), {["ABC";"DEF"]})
2234%!assert (toupper (["ABCÄÖÜSS"; "abcäöüß"]), ["ABCÄÖÜSS"; "ABCÄÖÜSS"])
2235%!assert (toupper (repmat ("äöü", 2, 1, 3)), repmat ("ÄÖÜ", 2, 1, 3))
2236%!assert (toupper (100), 100)
2237%!assert (toupper ({[100, 100; 100, 100]}), {[100, 100; 100, 100]})
2238%!assert (toupper (100i), 100i)
2239%!assert (toupper ({[100i, 100; 100, 100i]}), {[100i, 100; 100, 100i]})
2240%!assert (toupper (single (100i)), single (100i))
2241%!assert (toupper ({single([100i, 100; 100, 100i])}),
2242%! {single([100i, 100; 100, 100i])})
2243
2244%!test
2245%! classes = {@char, @double, @single, ...
2246%! @int8, @int16, @int32, @int64, ...
2247%! @uint8, @uint16, @uint32, @uint64};
2248%! for i = 1:numel (classes)
2249%! cls = classes{i};
2250%! assert (class (toupper (cls (97))), class (cls (97)));
2251%! assert (class (toupper (cls ([98, 99]))), class (cls ([98, 99])));
2252%! endfor
2253%!test
2254%! a(3,3,3,3) = "d";
2255%! assert (toupper (a)(3,3,3,3), "D");
2256%!test
2257%! charset = char (0:127);
2258%! result = charset;
2259%! result (double ("a":"z") + 1) = result (double ("A":"Z") + 1);
2260%! assert (toupper (charset), result);
2261
2262%!error <Invalid call to toupper> toupper ()
2263%!error <Invalid call to toupper> upper ()
2264%!error toupper (1, 2)
2265*/
2266
2267DEFALIAS (gammaln, lgamma);
2268
2269OCTAVE_NAMESPACE_END
ComplexColumnVector conj(const ComplexColumnVector &a)
Definition: CColVector.cc:217
octave_value xsignbit(void) const
Definition: ov.h:1628
ColumnVector real(const ComplexColumnVector &a)
Definition: dColVector.cc:137
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:143
OCTINTERP_API void print_usage(void)
Definition: defun-int.h:72
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
Definition: defun.h:85
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
Definition: defun.h:160
function gamma(X)
Definition: gamma.f:3
OCTAVE_EXPORT octave_value_list Fisalnum(const octave_value_list &args, int)
Definition: mappers.cc:1208
OCTAVE_EXPORT octave_value_list Fisxdigit(const octave_value_list &args, int)
Definition: mappers.cc:1625
OCTAVE_EXPORT octave_value_list Fisalpha(const octave_value_list &args, int)
Definition: mappers.cc:1238
OCTAVE_EXPORT octave_value_list Fisupper(const octave_value_list &args, int)
Definition: mappers.cc:1599
OCTAVE_EXPORT octave_value_list Fisdigit(const octave_value_list &args, int)
Definition: mappers.cc:1315
OCTAVE_EXPORT octave_value_list Fiscntrl(const octave_value_list &args, int)
Definition: mappers.cc:1289
OCTAVE_EXPORT octave_value_list Ftolower(const octave_value_list &args, int)
Definition: mappers.cc:2152
OCTAVE_EXPORT octave_value_list Fisgraph(const octave_value_list &args, int)
Definition: mappers.cc:1383
OCTAVE_EXPORT octave_value_list Fislower(const octave_value_list &args, int)
Definition: mappers.cc:1409
OCTAVE_EXPORT octave_value_list Fsignbit(const octave_value_list &args, int)
Definition: mappers.cc:1958
OCTAVE_EXPORT octave_value_list Fisascii(const octave_value_list &args, int)
Definition: mappers.cc:1265
OCTAVE_EXPORT octave_value_list Fisspace(const octave_value_list &args, int)
Definition: mappers.cc:1573
OCTAVE_EXPORT octave_value_list Fisprint(const octave_value_list &args, int)
Definition: mappers.cc:1517
OCTAVE_EXPORT octave_value_list Fispunct(const octave_value_list &args, int)
Definition: mappers.cc:1543
OCTAVE_EXPORT octave_value_list Ftoupper(const octave_value_list &args, int)
Definition: mappers.cc:2218
std::complex< double > erfi(std::complex< double > z, double relerr=0)
std::complex< double > erfc(std::complex< double > z, double relerr=0)
std::complex< double > erfcx(std::complex< double > z, double relerr=0)
std::complex< double > erf(std::complex< double > z, double relerr=0)
double fix(double x)
Definition: lo-mappers.h:118
Complex atan(const Complex &x)
Definition: lo-mappers.h:71
double signum(double x)
Definition: lo-mappers.h:229
double asinh(double x)
Definition: lo-specfun.h:58
bool isna(double x)
Definition: lo-mappers.cc:47
double atanh(double x)
Definition: lo-specfun.h:63
bool isfinite(double x)
Definition: lo-mappers.h:192
double roundb(double x)
Definition: lo-mappers.h:147
bool isnan(bool)
Definition: lo-mappers.h:178
Complex log1p(const Complex &x)
Definition: lo-specfun.cc:1958
bool isinf(double x)
Definition: lo-mappers.h:203
Complex acos(const Complex &x)
Definition: lo-mappers.cc:85
double round(double x)
Definition: lo-mappers.h:136
Complex asin(const Complex &x)
Definition: lo-mappers.cc:107
double acosh(double x)
Definition: lo-specfun.h:40
double erfcinv(double x)
Definition: lo-specfun.cc:1744
double lgamma(double x)
Definition: lo-specfun.h:336
double erfinv(double x)
Definition: lo-specfun.cc:1863
std::complex< T > ceil(const std::complex< T > &x)
Definition: lo-mappers.h:103
std::complex< T > floor(const std::complex< T > &x)
Definition: lo-mappers.h:130
double dawson(double x)
Definition: lo-specfun.cc:1517
double cbrt(double x)
Definition: lo-specfun.h:289
Complex expm1(const Complex &x)
Definition: lo-specfun.cc:1874
static int xisascii(int c)
Definition: ov-ch-mat.cc:246
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
static T abs(T x)
Definition: pr-output.cc:1678