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