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