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