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