GNU Octave  9.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-2024 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 ; ! __have_feature__ ("LLVM_LIBCXX") <*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 ; __have_feature__ ("LLVM_LIBCXX") <52627>
139 %! ## Same test code as above, but intended for test statistics with libc++.
140 %! ## 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 ; ! __have_feature__ ("LLVM_LIBCXX") <*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 ; __have_feature__ ("LLVM_LIBCXX") <52627>
211 %! ## Same test code as above, but intended for test statistics with libc++.
212 %! ## 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 ; ! __have_feature__ ("LLVM_LIBCXX") <*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 ; __have_feature__ ("LLVM_LIBCXX") <52627>
345 %! ## Same test code as above, but intended for test statistics with libc++.
346 %! ## 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 ; ! __have_feature__ ("LLVM_LIBCXX") <*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 ; __have_feature__ ("LLVM_LIBCXX") <52627>
387 %! ## Same test code as above, but intended for test statistics with libc++.
388 %! ## 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 %!testif ; ! ispc ()
790 %! assert (erfcinv (erfc (single ([-3 -1 -0.4 0.7 1.3 2.8]))),
791 %! single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4)
792 %!testif ; ispc () <65075>
793 %! ## Same test code as above, but intended for test statistics with the UCRT.
794 %! ## The deviations are twice as high with it.
795 %! assert (erfcinv (erfc (single ([-3 -1 -0.4 0.7 1.3 2.8]))),
796 %! single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4)
797 ## exceptional
798 %!assert (erfcinv ([2, 0, -0.1, 2.1]), [-Inf, Inf, NaN, NaN])
799 %!error erfcinv (1+2i)
800 
801 %!error erfcinv ()
802 %!error erfcinv (1, 2)
803 */
804 
805 DEFUN (erfc, args, ,
806  doc: /* -*- texinfo -*-
807 @deftypefn {} {@var{v} =} erfc (@var{z})
808 Compute the complementary error function.
809 
810 The complementary error function is defined as
811 @tex
812 $1 - {\rm erf} (z)$.
813 @end tex
814 @ifnottex
815 @w{@code{1 - erf (@var{z})}}.
816 @end ifnottex
817 @seealso{erfcinv, erfcx, erfi, dawson, erf, erfinv}
818 @end deftypefn */)
819 {
820  if (args.length () != 1)
821  print_usage ();
822 
823  return ovl (args(0).erfc ());
824 }
825 
826 /*
827 %!test
828 %! a = -1i* sqrt (-1/(6.4187*6.4187));
829 %! assert (erfc (a), erfc (real (a)));
830 
831 %!error erfc ()
832 %!error erfc (1, 2)
833 */
834 
835 DEFUN (erfcx, args, ,
836  doc: /* -*- texinfo -*-
837 @deftypefn {} {@var{v} =} erfcx (@var{z})
838 Compute the scaled complementary error function.
839 
840 The scaled complementary error function is defined as
841 @tex
842 $$
843  e^{z^2} {\rm erfc} (z) \equiv e^{z^2} (1 - {\rm erf} (z))
844 $$
845 @end tex
846 @ifnottex
847 
848 @example
849 exp (z^2) * erfc (z)
850 @end example
851 
852 @end ifnottex
853 @seealso{erfc, erf, erfi, dawson, erfinv, erfcinv}
854 @end deftypefn */)
855 {
856  if (args.length () != 1)
857  print_usage ();
858 
859  return ovl (args(0).erfcx ());
860 }
861 
862 /*
863 
864 %!test
865 %! x = [1+2i,-1+2i,1e-6+2e-6i,0+2i];
866 %! assert (erfcx (x), exp (x.^2) .* erfc (x), -1.e-10);
867 
868 %!test
869 %! x = [100, 100+20i];
870 %! v = [0.0056416137829894329, 0.0054246791754558-0.00108483153786434i];
871 %! assert (erfcx (x), v, -1.e-10);
872 
873 %!error erfcx ()
874 %!error erfcx (1, 2)
875 */
876 
877 DEFUN (erfi, args, ,
878  doc: /* -*- texinfo -*-
879 @deftypefn {} {@var{v} =} erfi (@var{z})
880 Compute the imaginary error function.
881 
882 The imaginary error function is defined as
883 @tex
884 $$
885  -i {\rm erf} (iz)
886 $$
887 @end tex
888 @ifnottex
889 
890 @example
891 -i * erf (i*z)
892 @end example
893 
894 @end ifnottex
895 @seealso{erfc, erf, erfcx, dawson, erfinv, erfcinv}
896 @end deftypefn */)
897 {
898  if (args.length () != 1)
899  print_usage ();
900 
901  return ovl (args(0).erfi ());
902 }
903 
904 /*
905 
906 %!test
907 %! x = [-0.1, 0.1, 1, 1+2i,-1+2i,1e-6+2e-6i,0+2i];
908 %! assert (erfi (x), -i * erf (i*x), -1.e-10);
909 
910 %!error erfi ()
911 %!error erfi (1, 2)
912 */
913 
914 DEFUN (dawson, args, ,
915  doc: /* -*- texinfo -*-
916 @deftypefn {} {@var{v} =} dawson (@var{z})
917 Compute the Dawson (scaled imaginary error) function.
918 
919 The Dawson function is defined as
920 @tex
921 $$
922  {\sqrt{\pi} \over 2} e^{-z^2} {\rm erfi} (z) \equiv -i {\sqrt{\pi} \over 2} e^{-z^2} {\rm erf} (iz)
923 $$
924 @end tex
925 @ifnottex
926 
927 @example
928 (sqrt (pi) / 2) * exp (-z^2) * erfi (z)
929 @end example
930 
931 @end ifnottex
932 @seealso{erfc, erf, erfcx, erfi, erfinv, erfcinv}
933 @end deftypefn */)
934 {
935  if (args.length () != 1)
936  print_usage ();
937 
938  return ovl (args(0).dawson ());
939 }
940 
941 /*
942 
943 %!test
944 %! x = [0.1, 1, 1+2i,-1+2i,1e-4+2e-4i,0+2i];
945 %! v = [0.099335992397852861, 0.53807950691, -13.38892731648-11.828715104i, 13.38892731648-11.828715104i, 0.0001000000073333+0.000200000001333i, 48.160012114291i];
946 %! assert (dawson (x), v, -1.e-10);
947 %! assert (dawson (-x), -v, -1.e-10);
948 
949 %!error dawson ()
950 %!error dawson (1, 2)
951 */
952 
953 DEFUN (exp, args, ,
954  doc: /* -*- texinfo -*-
955 @deftypefn {} {@var{y} =} exp (@var{x})
956 Compute
957 @tex
958 $e^{x}$
959 @end tex
960 @ifnottex
961 @code{e^x}
962 @end ifnottex
963 for each element of @var{x}.
964 
965 To compute the matrix exponential, @pxref{Linear Algebra}.
966 @seealso{log}
967 @end deftypefn */)
968 {
969  if (args.length () != 1)
970  print_usage ();
971 
972  return ovl (args(0).exp ());
973 }
974 
975 /*
976 %!assert (exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps))
977 %!assert (exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps))
978 %!assert (exp (single ([0, 1, -1, -1000])),
979 %! single ([1, e, 1/e, 0]), sqrt (eps ("single")))
980 %!assert (exp (single (1+i)),
981 %! single (e * (cos (1) + sin (1) * i)), sqrt (eps ("single")))
982 
983 %!assert (exp ([Inf, -Inf, NaN]), [Inf 0 NaN])
984 %!assert (exp (single ([Inf, -Inf, NaN])), single ([Inf 0 NaN]))
985 
986 %!error exp ()
987 %!error exp (1, 2)
988 */
989 
990 DEFUN (expm1, args, ,
991  doc: /* -*- texinfo -*-
992 @deftypefn {} {@var{y} =} expm1 (@var{x})
993 Compute
994 @tex
995 $ e^{x} - 1 $
996 @end tex
997 @ifnottex
998 @code{exp (@var{x}) - 1}
999 @end ifnottex
1000 accurately in the neighborhood of zero.
1001 @seealso{exp}
1002 @end deftypefn */)
1003 {
1004  if (args.length () != 1)
1005  print_usage ();
1006 
1007  return ovl (args(0).expm1 ());
1008 }
1009 
1010 /*
1011 %!assert (expm1 (2*eps), 2*eps, 1e-29)
1012 
1013 %!assert (expm1 ([Inf, -Inf, NaN]), [Inf -1 NaN])
1014 %!assert (expm1 (single ([Inf, -Inf, NaN])), single ([Inf -1 NaN]))
1015 
1016 %!error expm1 ()
1017 %!error expm1 (1, 2)
1018 */
1019 
1020 DEFUN (isfinite, args, ,
1021  doc: /* -*- texinfo -*-
1022 @deftypefn {} {@var{tf} =} isfinite (@var{x})
1023 Return a logical array which is true where the elements of @var{x} are
1024 finite values and false where they are not.
1025 
1026 For example:
1027 
1028 @example
1029 @group
1030 isfinite ([13, Inf, NA, NaN])
1031  @result{} [ 1, 0, 0, 0 ]
1032 @end group
1033 @end example
1034 @seealso{isinf, isnan, isna}
1035 @end deftypefn */)
1036 {
1037  if (args.length () != 1)
1038  print_usage ();
1039 
1040  return ovl (args(0).isfinite ());
1041 }
1042 
1043 /*
1044 %!assert (! isfinite (Inf))
1045 %!assert (! isfinite (NaN))
1046 %!assert (isfinite (rand (1,10)))
1047 
1048 %!assert (! isfinite (single (Inf)))
1049 %!assert (! isfinite (single (NaN)))
1050 %!assert (isfinite (single (rand (1,10))))
1051 %!assert (isfinite ('a'))
1052 
1053 %!error isfinite ()
1054 %!error isfinite (1, 2)
1055 */
1056 
1057 DEFUN (fix, args, ,
1058  doc: /* -*- texinfo -*-
1059 @deftypefn {} {@var{y} =} fix (@var{x})
1060 Truncate fractional portion of @var{x} and return the integer portion.
1061 
1062 This is equivalent to rounding towards zero. If @var{x} is complex, return
1063 @code{fix (real (@var{x})) + fix (imag (@var{x})) * I}.
1064 
1065 @example
1066 @group
1067 fix ([-2.7, 2.7])
1068  @result{} -2 2
1069 @end group
1070 @end example
1071 @seealso{ceil, floor, round}
1072 @end deftypefn */)
1073 {
1074  if (args.length () != 1)
1075  print_usage ();
1076 
1077  return ovl (args(0).fix ());
1078 }
1079 
1080 /*
1081 %!assert (fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1])
1082 %!assert (fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i])
1083 %!assert (fix (single ([1.1, 1, -1.1, -1])), single ([1, 1, -1, -1]))
1084 %!assert (fix (single ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])),
1085 %! single ([1+i, 1+i, -1-i, -1-i]))
1086 
1087 %!error fix ()
1088 %!error fix (1, 2)
1089 */
1090 
1091 DEFUN (floor, args, ,
1092  doc: /* -*- texinfo -*-
1093 @deftypefn {} {@var{y} =} floor (@var{x})
1094 Return the largest integer not greater than @var{x}.
1095 
1096 This is equivalent to rounding towards negative infinity. If @var{x} is
1097 complex, return @code{floor (real (@var{x})) + floor (imag (@var{x})) * I}.
1098 
1099 @example
1100 @group
1101 floor ([-2.7, 2.7])
1102  @result{} -3 2
1103 @end group
1104 @end example
1105 @seealso{ceil, round, fix}
1106 @end deftypefn */)
1107 {
1108  if (args.length () != 1)
1109  print_usage ();
1110 
1111  return ovl (args(0).floor ());
1112 }
1113 
1114 /*
1115 %!assert (floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1])
1116 %!assert (floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i])
1117 %!assert (floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]))
1118 %!assert (floor (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])),
1119 %! single ([2+2i, 1+i, -2-2i, -1-i]))
1120 
1121 %!error floor ()
1122 %!error floor (1, 2)
1123 */
1124 
1125 DEFUN (gamma, args, ,
1126  doc: /* -*- texinfo -*-
1127 @deftypefn {} {@var{v} =} gamma (@var{z})
1128 Compute the Gamma function.
1129 
1130 The Gamma function is defined as
1131 @tex
1132 $$
1133  \Gamma (z) = \int_0^\infty t^{z-1} e^{-t} dt.
1134 $$
1135 @end tex
1136 @ifnottex
1137 
1138 @example
1139 @group
1140  infinity
1141  /
1142 gamma (z) = | t^(z-1) exp (-t) dt.
1143  /
1144  t=0
1145 @end group
1146 @end example
1147 
1148 @end ifnottex
1149 
1150 Programming Note: The gamma function can grow quite large even for small
1151 input values. In many cases it may be preferable to use the natural
1152 logarithm of the gamma function (@code{gammaln}) in calculations to minimize
1153 loss of precision. The final result is then
1154 @code{exp (@var{result_using_gammaln}).}
1155 @seealso{gammainc, gammaln, factorial}
1156 @end deftypefn */)
1157 {
1158  if (args.length () != 1)
1159  print_usage ();
1160 
1161  return ovl (args(0).gamma ());
1162 }
1163 
1164 /*
1165 %!test
1166 %! a = -1i* sqrt (-1/(6.4187*6.4187));
1167 %! assert (gamma (a), gamma (real (a)));
1168 
1169 %!test
1170 %! x = [.5, 1, 1.5, 2, 3, 4, 5];
1171 %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1172 %! assert (gamma (x), v, sqrt (eps));
1173 
1174 %!test
1175 %! a = single (-1i* sqrt (-1/(6.4187*6.4187)));
1176 %! assert (gamma (a), gamma (real (a)));
1177 
1178 %!test
1179 %! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
1180 %! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1181 %! assert (gamma (x), v, sqrt (eps ("single")));
1182 
1183 %!test
1184 %! ## Test exceptional values
1185 %! x = [-Inf, -1, -0, 0, 1, Inf, NaN];
1186 %! v = [Inf, Inf, -Inf, Inf, 1, Inf, NaN];
1187 %! assert (gamma (x), v);
1188 %! assert (gamma (single (x)), single (v));
1189 
1190 %!error gamma ()
1191 %!error gamma (1, 2)
1192 */
1193 
1194 DEFUN (imag, args, ,
1195  doc: /* -*- texinfo -*-
1196 @deftypefn {} {@var{y} =} imag (@var{z})
1197 Return the imaginary part of @var{z} as a real number.
1198 @seealso{real, conj}
1199 @end deftypefn */)
1200 {
1201  if (args.length () != 1)
1202  print_usage ();
1203 
1204  return ovl (args(0).imag ());
1205 }
1206 
1207 /*
1208 %!assert (imag (1), 0)
1209 %!assert (imag (i), 1)
1210 %!assert (imag (1+i), 1)
1211 %!assert (imag ([i, 1; 1, i]), full (eye (2)))
1212 
1213 %!assert (imag (single (1)), single (0))
1214 %!assert (imag (single (i)), single (1))
1215 %!assert (imag (single (1+i)), single (1))
1216 %!assert (imag (single ([i, 1; 1, i])), full (eye (2,"single")))
1217 
1218 %!error imag ()
1219 %!error imag (1, 2)
1220 */
1221 
1222 DEFUNX ("isalnum", Fisalnum, args, ,
1223  doc: /* -*- texinfo -*-
1224 @deftypefn {} {@var{tf} =} isalnum (@var{s})
1225 Return a logical array which is true where the elements of @var{s} are
1226 letters or digits and false where they are not.
1227 
1228 This is equivalent to (@code{isalpha (@var{s}) | isdigit (@var{s})}).
1229 @seealso{isalpha, isdigit, ispunct, isspace, iscntrl}
1230 @end deftypefn */)
1231 {
1232  if (args.length () != 1)
1233  print_usage ();
1234 
1235  return ovl (args(0).xisalnum ());
1236 }
1237 
1238 /*
1239 %!test
1240 %! charset = char (0:127);
1241 %! result = false (1, 128);
1242 %! result(double ("A":"Z") + 1) = true;
1243 %! result(double ("0":"9") + 1) = true;
1244 %! result(double ("a":"z") + 1) = true;
1245 %! assert (isalnum (charset), result);
1246 %!assert (isalnum(["Ä8Aa?"; "(Uß ;"]), logical ([1 1 1 1 1 0; 0 1 1 1 0 0]))
1247 
1248 %!error isalnum ()
1249 %!error isalnum (1, 2)
1250 */
1251 
1252 DEFUNX ("isalpha", Fisalpha, args, ,
1253  doc: /* -*- texinfo -*-
1254 @deftypefn {} {@var{tf} =} isalpha (@var{s})
1255 Return a logical array which is true where the elements of @var{s} are
1256 letters and false where they are not.
1257 
1258 This is equivalent to (@code{islower (@var{s}) | isupper (@var{s})}).
1259 @seealso{isdigit, ispunct, isspace, iscntrl, isalnum, islower, isupper}
1260 @end deftypefn */)
1261 {
1262  if (args.length () != 1)
1263  print_usage ();
1264 
1265  return ovl (args(0).xisalpha ());
1266 }
1267 
1268 /*
1269 %!test
1270 %! charset = char (0:127);
1271 %! result = false (1, 128);
1272 %! result(double ("A":"Z") + 1) = true;
1273 %! result(double ("a":"z") + 1) = true;
1274 %! assert (isalpha (charset), result);
1275 %!assert (isalpha("Ä8Aa(Uß ;"), logical ([1 1 0 1 1 0 1 1 1 0 0]))
1276 
1277 %!error isalpha ()
1278 %!error isalpha (1, 2)
1279 */
1280 
1281 DEFUNX ("isascii", Fisascii, args, ,
1282  doc: /* -*- texinfo -*-
1283 @deftypefn {} {@var{tf} =} isascii (@var{s})
1284 Return a logical array which is true where the elements of @var{s} are
1285 ASCII characters (in the range 0 to 127 decimal) and false where they are
1286 not.
1287 @end deftypefn */)
1288 {
1289  if (args.length () != 1)
1290  print_usage ();
1291 
1292  return ovl (args(0).xisascii ());
1293 }
1294 
1295 /*
1296 %!test
1297 %! charset = char (0:127);
1298 %! result = true (1, 128);
1299 %! assert (isascii (charset), result);
1300 
1301 %!error isascii ()
1302 %!error isascii (1, 2)
1303 */
1304 
1305 DEFUNX ("iscntrl", Fiscntrl, args, ,
1306  doc: /* -*- texinfo -*-
1307 @deftypefn {} {@var{tf} =} iscntrl (@var{s})
1308 Return a logical array which is true where the elements of @var{s} are
1309 control characters and false where they are not.
1310 @seealso{ispunct, isspace, isalpha, isdigit}
1311 @end deftypefn */)
1312 {
1313  if (args.length () != 1)
1314  print_usage ();
1315 
1316  return ovl (args(0).xiscntrl ());
1317 }
1318 
1319 /*
1320 %!test
1321 %! charset = char (0:127);
1322 %! result = false (1, 128);
1323 %! result(1:32) = true;
1324 %! result(128) = true;
1325 %! assert (iscntrl (charset), result);
1326 
1327 %!error iscntrl ()
1328 %!error iscntrl (1, 2)
1329 */
1330 
1331 DEFUNX ("isdigit", Fisdigit, args, ,
1332  doc: /* -*- texinfo -*-
1333 @deftypefn {} {@var{tf} =} isdigit (@var{s})
1334 Return a logical array which is true where the elements of @var{s} are
1335 decimal digits (0-9) and false where they are not.
1336 @seealso{isxdigit, isalpha, isletter, ispunct, isspace, iscntrl}
1337 @end deftypefn */)
1338 {
1339  if (args.length () != 1)
1340  print_usage ();
1341 
1342  return ovl (args(0).xisdigit ());
1343 }
1344 
1345 /*
1346 %!test
1347 %! charset = char (0:127);
1348 %! result = false (1, 128);
1349 %! result(double ("0":"9") + 1) = true;
1350 %! assert (isdigit (charset), result);
1351 %!assert (isdigit("Ä8Aa(Uß ;"), logical ([0 0 1 0 0 0 0 0 0 0 0]))
1352 
1353 %!error isdigit ()
1354 %!error isdigit (1, 2)
1355 */
1356 
1357 DEFUN (isinf, args, ,
1358  doc: /* -*- texinfo -*-
1359 @deftypefn {} {@var{tf} =} isinf (@var{x})
1360 Return a logical array which is true where the elements of @var{x} are
1361 infinite and false where they are not.
1362 
1363 For example:
1364 
1365 @example
1366 @group
1367 isinf ([13, Inf, NA, NaN])
1368  @result{} [ 0, 1, 0, 0 ]
1369 @end group
1370 @end example
1371 @seealso{isfinite, isnan, isna}
1372 @end deftypefn */)
1373 {
1374  if (args.length () != 1)
1375  print_usage ();
1376 
1377  return ovl (args(0).isinf ());
1378 }
1379 
1380 /*
1381 %!assert (isinf (Inf))
1382 %!assert (! isinf (NaN))
1383 %!assert (! isinf (NA))
1384 %!assert (isinf (rand (1,10)), false (1,10))
1385 %!assert (isinf ([NaN -Inf -1 0 1 Inf NA]),
1386 %! [false, true, false, false, false, true, false])
1387 
1388 %!assert (isinf (single (Inf)))
1389 %!assert (! isinf (single (NaN)))
1390 %!assert (! isinf (single (NA)))
1391 %!assert (isinf (single (rand (1,10))), false (1,10))
1392 %!assert (isinf (single ([NaN -Inf -1 0 1 Inf NA])),
1393 %! [false, true, false, false, false, true, false])
1394 %!assert (! isinf ('a'))
1395 
1396 %!error isinf ()
1397 %!error isinf (1, 2)
1398 */
1399 
1400 DEFUNX ("isgraph", Fisgraph, args, ,
1401  doc: /* -*- texinfo -*-
1402 @deftypefn {} {@var{tf} =} isgraph (@var{s})
1403 Return a logical array which is true where the elements of @var{s} are
1404 printable characters (but not the space character) and false where they are
1405 not.
1406 @seealso{isprint}
1407 @end deftypefn */)
1408 {
1409  if (args.length () != 1)
1410  print_usage ();
1411 
1412  return ovl (args(0).xisgraph ());
1413 }
1414 
1415 /*
1416 %!test
1417 %! charset = char (0:127);
1418 %! result = false (1, 128);
1419 %! result(34:127) = true;
1420 %! assert (isgraph (charset), result);
1421 %!assert (isgraph("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 0 1]))
1422 
1423 %!error isgraph ()
1424 %!error isgraph (1, 2)
1425 */
1426 
1427 DEFUNX ("islower", Fislower, args, ,
1428  doc: /* -*- texinfo -*-
1429 @deftypefn {} {@var{tf} =} islower (@var{s})
1430 Return a logical array which is true where the elements of @var{s} are
1431 lowercase letters and false where they are not.
1432 @seealso{isupper, isalpha, isletter, isalnum}
1433 @end deftypefn */)
1434 {
1435  if (args.length () != 1)
1436  print_usage ();
1437 
1438  return ovl (args(0).xislower ());
1439 }
1440 
1441 /*
1442 %!test
1443 %! charset = char (0:127);
1444 %! result = false (1, 128);
1445 %! result(double ("a":"z") + 1) = true;
1446 %! assert (islower (charset), result);
1447 %!assert (islower("Ä8Aa(Uß ;"), logical ([0 0 0 0 1 0 0 1 1 0 0]))
1448 
1449 %!error islower ()
1450 %!error islower (1, 2)
1451 */
1452 
1453 DEFUN (isna, args, ,
1454  doc: /* -*- texinfo -*-
1455 @deftypefn {} {@var{tf} =} isna (@var{x})
1456 Return a logical array which is true where the elements of @var{x} are
1457 NA (missing) values and false where they are not.
1458 
1459 For example:
1460 
1461 @example
1462 @group
1463 isna ([13, Inf, NA, NaN])
1464  @result{} [ 0, 0, 1, 0 ]
1465 @end group
1466 @end example
1467 @seealso{isnan, isinf, isfinite}
1468 @end deftypefn */)
1469 {
1470  if (args.length () != 1)
1471  print_usage ();
1472 
1473  return ovl (args(0).isna ());
1474 }
1475 
1476 /*
1477 %!assert (! isna (Inf))
1478 %!assert (! isna (NaN))
1479 %!assert (isna (NA))
1480 %!assert (isna (rand (1,10)), false (1,10))
1481 %!assert (isna ([NaN -Inf -1 0 1 Inf NA]),
1482 %! [false, false, false, false, false, false, true])
1483 
1484 %!assert (! isna (single (Inf)))
1485 %!assert (! isna (single (NaN)))
1486 %!assert (isna (single (NA)))
1487 %!assert (isna (single (rand (1,10))), false (1,10))
1488 %!assert (isna (single ([NaN -Inf -1 0 1 Inf NA])),
1489 %! [false, false, false, false, false, false, true])
1490 
1491 %!error isna ()
1492 %!error isna (1, 2)
1493 */
1494 
1495 DEFUN (isnan, args, ,
1496  doc: /* -*- texinfo -*-
1497 @deftypefn {} {@var{tf} =} isnan (@var{x})
1498 Return a logical array which is true where the elements of @var{x} are
1499 NaN values and false where they are not.
1500 
1501 NA values are also considered NaN values. For example:
1502 
1503 @example
1504 @group
1505 isnan ([13, Inf, NA, NaN])
1506  @result{} [ 0, 0, 1, 1 ]
1507 @end group
1508 @end example
1509 @seealso{isna, isinf, isfinite}
1510 @end deftypefn */)
1511 {
1512  if (args.length () != 1)
1513  print_usage ();
1514 
1515  return ovl (args(0).isnan ());
1516 }
1517 
1518 /*
1519 %!assert (! isnan (Inf))
1520 %!assert (isnan (NaN))
1521 %!assert (isnan (NA))
1522 %!assert (isnan (rand (1,10)), false (1,10))
1523 %!assert (isnan ([NaN -Inf -1 0 1 Inf NA]),
1524 %! [true, false, false, false, false, false, true])
1525 
1526 %!assert (! isnan (single (Inf)))
1527 %!assert (isnan (single (NaN)))
1528 %!assert (isnan (single (NA)))
1529 %!assert (isnan (single (rand (1,10))), false (1,10))
1530 %!assert (isnan (single ([NaN -Inf -1 0 1 Inf NA])),
1531 %! [true, false, false, false, false, false, true])
1532 %!assert (! isnan ('a'))
1533 
1534 %!error isnan ()
1535 %!error isnan (1, 2)
1536 */
1537 
1538 DEFUNX ("isprint", Fisprint, args, ,
1539  doc: /* -*- texinfo -*-
1540 @deftypefn {} {@var{tf} =} isprint (@var{s})
1541 Return a logical array which is true where the elements of @var{s} are
1542 printable characters (including the space character) and false where they
1543 are not.
1544 @seealso{isgraph}
1545 @end deftypefn */)
1546 {
1547  if (args.length () != 1)
1548  print_usage ();
1549 
1550  return ovl (args(0).xisprint ());
1551 }
1552 
1553 /*
1554 %!test
1555 %! charset = char (0:127);
1556 %! result = false (1, 128);
1557 %! result(33:127) = true;
1558 %! assert (isprint (charset), result);
1559 %!assert (isprint("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 1 1]))
1560 
1561 %!error isprint ()
1562 %!error isprint (1, 2)
1563 */
1564 
1565 DEFUNX ("ispunct", Fispunct, args, ,
1566  doc: /* -*- texinfo -*-
1567 @deftypefn {} {@var{tf} =} ispunct (@var{s})
1568 Return a logical array which is true where the elements of @var{s} are
1569 punctuation characters and false where they are not.
1570 @seealso{isalpha, isdigit, isspace, iscntrl}
1571 @end deftypefn */)
1572 {
1573  if (args.length () != 1)
1574  print_usage ();
1575 
1576  return ovl (args(0).xispunct ());
1577 }
1578 
1579 /*
1580 %!test
1581 %! charset = char (0:127);
1582 %! result = false (1, 128);
1583 %! result(34:48) = true;
1584 %! result(59:65) = true;
1585 %! result(92:97) = true;
1586 %! result(124:127) = true;
1587 %! assert (ispunct (charset), result);
1588 %!assert (ispunct("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 1 0 0 0 0 1]))
1589 
1590 %!error ispunct ()
1591 %!error ispunct (1, 2)
1592 */
1593 
1594 DEFUNX ("isspace", Fisspace, args, ,
1595  doc: /* -*- texinfo -*-
1596 @deftypefn {} {@var{tf} =} isspace (@var{s})
1597 Return a logical array which is true where the elements of @var{s} are
1598 whitespace characters (space, formfeed, newline, carriage return, tab, and
1599 vertical tab) and false where they are not.
1600 @seealso{iscntrl, ispunct, isalpha, isdigit}
1601 @end deftypefn */)
1602 {
1603  if (args.length () != 1)
1604  print_usage ();
1605 
1606  return ovl (args(0).xisspace ());
1607 }
1608 
1609 /*
1610 %!test
1611 %! charset = char (0:127);
1612 %! result = false (1, 128);
1613 %! result(double (" \f\n\r\t\v") + 1) = true;
1614 %! assert (isspace (charset), result);
1615 %!assert (isspace("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 0 0 0 0 1 0]))
1616 
1617 %!error isspace ()
1618 %!error isspace (1, 2)
1619 */
1620 
1621 DEFUNX ("isupper", Fisupper, args, ,
1622  doc: /* -*- texinfo -*-
1623 @deftypefn {} {@var{tf} =} isupper (@var{s})
1624 Return a logical array which is true where the elements of @var{s} are
1625 uppercase letters and false where they are not.
1626 @seealso{islower, isalpha, isletter, isalnum}
1627 @end deftypefn */)
1628 {
1629  if (args.length () != 1)
1630  print_usage ();
1631 
1632  return ovl (args(0).xisupper ());
1633 }
1634 
1635 /*
1636 %!test
1637 %! charset = char (0:127);
1638 %! result = false (1, 128);
1639 %! result(double ("A":"Z") + 1) = true;
1640 %! assert (isupper (charset), result);
1641 %!assert (isupper("Ä8Aa(Uß ;"), logical ([1 1 0 1 0 0 1 0 0 0 0]))
1642 
1643 %!error isupper ()
1644 %!error isupper (1, 2)
1645 */
1646 
1647 DEFUNX ("isxdigit", Fisxdigit, args, ,
1648  doc: /* -*- texinfo -*-
1649 @deftypefn {} {@var{tf} =} isxdigit (@var{s})
1650 Return a logical array which is true where the elements of @var{s} are
1651 hexadecimal digits (0-9 and @nospell{a-fA-F}).
1652 @seealso{isdigit}
1653 @end deftypefn */)
1654 {
1655  if (args.length () != 1)
1656  print_usage ();
1657 
1658  return ovl (args(0).xisxdigit ());
1659 }
1660 
1661 /*
1662 %!test
1663 %! charset = char (0:127);
1664 %! result = false (1, 128);
1665 %! result(double ("A":"F") + 1) = true;
1666 %! result(double ("0":"9") + 1) = true;
1667 %! result(double ("a":"f") + 1) = true;
1668 %! assert (isxdigit (charset), result);
1669 %!assert (isxdigit("Ä8Aa(Uß ;"), logical ([0 0 1 1 1 0 0 0 0 0 0]))
1670 
1671 %!error isxdigit ()
1672 %!error isxdigit (1, 2)
1673 */
1674 
1675 DEFUN (lgamma, args, ,
1676  doc: /* -*- texinfo -*-
1677 @deftypefn {} {@var{y} =} gammaln (@var{x})
1678 @deftypefnx {} {@var{y} =} lgamma (@var{x})
1679 Return the natural logarithm of the gamma function of @var{x}.
1680 
1681 Programming Note: @code{lgamma} is an alias for @code{gammaln} and either name
1682 can be used in Octave.
1683 @seealso{gamma, gammainc}
1684 @end deftypefn */)
1685 {
1686  if (args.length () != 1)
1687  print_usage ();
1688 
1689  return ovl (args(0).lgamma ());
1690 }
1691 
1692 /*
1693 %!test
1694 %! a = -1i* sqrt (-1/(6.4187*6.4187));
1695 %! assert (gammaln (a), gammaln (real (a)));
1696 
1697 %!test
1698 %! x = [.5, 1, 1.5, 2, 3, 4, 5];
1699 %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1700 %! assert (gammaln (x), log (v), sqrt (eps));
1701 
1702 %!test
1703 %! a = single (-1i* sqrt (-1/(6.4187*6.4187)));
1704 %! assert (gammaln (a), gammaln (real (a)));
1705 
1706 %!test
1707 %! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
1708 %! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1709 %! assert (gammaln (x), log (v), sqrt (eps ("single")));
1710 
1711 %!test
1712 %! x = [-1, 0, 1, Inf];
1713 %! v = [Inf, Inf, 0, Inf];
1714 %! assert (gammaln (x), v);
1715 %! assert (gammaln (single (x)), single (v));
1716 
1717 %!error gammaln ()
1718 %!error gammaln (1,2)
1719 */
1720 
1721 DEFUN (log, args, ,
1722  doc: /* -*- texinfo -*-
1723 @deftypefn {} {@var{y} =} log (@var{x})
1724 Compute the natural logarithm,
1725 @tex
1726 $\ln{(x)},$
1727 @end tex
1728 @ifnottex
1729 @code{ln (@var{x})},
1730 @end ifnottex
1731 for each element of @var{x}.
1732 
1733 To compute the matrix logarithm, @pxref{Linear Algebra}.
1734 @seealso{exp, log1p, log2, log10, logspace}
1735 @end deftypefn */)
1736 {
1737  if (args.length () != 1)
1738  print_usage ();
1739 
1740  return ovl (args(0).log ());
1741 }
1742 
1743 /*
1744 %!assert (log ([1, e, e^2]), [0, 1, 2], sqrt (eps))
1745 %!assert (log ([-0.5, -1.5, -2.5]), log ([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps))
1746 
1747 %!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ("single")))
1748 %!assert (log (single ([-0.5, -1.5, -2.5])),
1749 %! single (log ([0.5, 1.5, 2.5]) + pi*1i), 4* eps ("single"))
1750 
1751 %!error log ()
1752 %!error log (1, 2)
1753 */
1754 
1755 DEFUN (log10, args, ,
1756  doc: /* -*- texinfo -*-
1757 @deftypefn {} {@var{y} =} log10 (@var{x})
1758 Compute the base-10 logarithm of each element of @var{x}.
1759 @seealso{log, log2, logspace, exp}
1760 @end deftypefn */)
1761 {
1762  if (args.length () != 1)
1763  print_usage ();
1764 
1765  return ovl (args(0).log10 ());
1766 }
1767 
1768 /*
1769 %!assert (log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps))
1770 %!assert (log10 (single ([0.01, 0.1, 1, 10, 100])),
1771 %! single ([-2, -1, 0, 1, 2]), sqrt (eps ("single")))
1772 
1773 %!error log10 ()
1774 %!error log10 (1, 2)
1775 */
1776 
1777 DEFUN (log1p, args, ,
1778  doc: /* -*- texinfo -*-
1779 @deftypefn {} {@var{y} =} log1p (@var{x})
1780 Compute
1781 @tex
1782 $\ln{(1 + x)}$
1783 @end tex
1784 @ifnottex
1785 @code{log (1 + @var{x})}
1786 @end ifnottex
1787 accurately in the neighborhood of zero.
1788 @seealso{log, exp, expm1}
1789 @end deftypefn */)
1790 {
1791  if (args.length () != 1)
1792  print_usage ();
1793 
1794  return ovl (args(0).log1p ());
1795 }
1796 
1797 /*
1798 %!assert (log1p ([0, 2*eps, -2*eps]), [0, 2*eps, -2*eps], 1e-29)
1799 %!assert (log1p (single ([0, 2*eps, -2*eps])), ...
1800 %! single ([0, 2*eps, -2*eps]), 1e-29)
1801 ## Compare to result from Wolfram Alpha rounded to 16 significant digits
1802 %!assert <*62094> (log1p (0.1i), ...
1803 %! 0.004975165426584041 + 0.09966865249116203i, eps (0.2))
1804 %!assert <*62094> (log1p (single (0.1i)), ...
1805 %! single (0.004975165426584041 + 0.09966865249116203i), ...
1806 %! eps (single (0.2)))
1807 
1808 %!error log1p ()
1809 %!error log1p (1, 2)
1810 */
1811 
1812 DEFUN (real, args, ,
1813  doc: /* -*- texinfo -*-
1814 @deftypefn {} {@var{x} =} real (@var{z})
1815 Return the real part of @var{z}.
1816 @seealso{imag, conj}
1817 @end deftypefn */)
1818 {
1819  if (args.length () != 1)
1820  print_usage ();
1821 
1822  return ovl (args(0).real ());
1823 }
1824 
1825 /*
1826 %!assert (real (1), 1)
1827 %!assert (real (i), 0)
1828 %!assert (real (1+i), 1)
1829 %!assert (real ([1, i; i, 1]), full (eye (2)))
1830 
1831 %!assert (real (single (1)), single (1))
1832 %!assert (real (single (i)), single (0))
1833 %!assert (real (single (1+i)), single (1))
1834 %!assert (real (single ([1, i; i, 1])), full (eye (2, "single")))
1835 
1836 %!error real ()
1837 %!error real (1, 2)
1838 */
1839 
1840 DEFUN (round, args, ,
1841  doc: /* -*- texinfo -*-
1842 @deftypefn {} {@var{y} =} round (@var{x})
1843 Return the integer nearest to @var{x}.
1844 
1845 If @var{x} is complex, return
1846 @code{round (real (@var{x})) + round (imag (@var{x})) * I}. If there
1847 are two nearest integers, return the one further away from zero.
1848 
1849 @example
1850 @group
1851 round ([-2.7, 2.7])
1852  @result{} -3 3
1853 @end group
1854 @end example
1855 @seealso{ceil, floor, fix, roundb}
1856 @end deftypefn */)
1857 {
1858  if (args.length () != 1)
1859  print_usage ();
1860 
1861  return ovl (args(0).round ());
1862 }
1863 
1864 /*
1865 %!assert (round (1), 1)
1866 %!assert (round (1.1), 1)
1867 %!assert (round (5.5), 6)
1868 %!assert (round (i), i)
1869 %!assert (round (2.5+3.5i), 3+4i)
1870 %!assert (round (-2.6), -3)
1871 %!assert (round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
1872 
1873 %!assert (round (single (1)), single (1))
1874 %!assert (round (single (1.1)), single (1))
1875 %!assert (round (single (5.5)), single (6))
1876 %!assert (round (single (i)), single (i))
1877 %!assert (round (single (2.5+3.5i)), single (3+4i))
1878 %!assert (round (single (-2.6)), single (-3))
1879 %!assert (round (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
1880 
1881 %!error round ()
1882 %!error round (1, 2)
1883 */
1884 
1885 DEFUN (roundb, args, ,
1886  doc: /* -*- texinfo -*-
1887 @deftypefn {} {@var{y} =} roundb (@var{x})
1888 Return the integer nearest to @var{x}. If there are two nearest
1889 integers, return the even one (banker's rounding).
1890 
1891 If @var{x} is complex,
1892 return @code{roundb (real (@var{x})) + roundb (imag (@var{x})) * I}.
1893 @seealso{round}
1894 @end deftypefn */)
1895 {
1896  if (args.length () != 1)
1897  print_usage ();
1898 
1899  return ovl (args(0).roundb ());
1900 }
1901 
1902 /*
1903 %!assert (roundb (1), 1)
1904 %!assert (roundb (1.1), 1)
1905 %!assert (roundb (1.5), 2)
1906 %!assert (roundb (4.5), 4)
1907 %!assert (roundb (i), i)
1908 %!assert (roundb (2.5+3.5i), 2+4i)
1909 %!assert (roundb (-2.6), -3)
1910 %!assert (roundb ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
1911 
1912 %!assert (roundb (single (1)), single (1))
1913 %!assert (roundb (single (1.1)), single (1))
1914 %!assert (roundb (single (1.5)), single (2))
1915 %!assert (roundb (single (4.5)), single (4))
1916 %!assert (roundb (single (i)), single (i))
1917 %!assert (roundb (single (2.5+3.5i)), single (2+4i))
1918 %!assert (roundb (single (-2.6)), single (-3))
1919 %!assert (roundb (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
1920 
1921 %!error roundb ()
1922 %!error roundb (1, 2)
1923 */
1924 
1925 DEFUN (sign, args, ,
1926  doc: /* -*- texinfo -*-
1927 @deftypefn {} {@var{y} =} sign (@var{x})
1928 Compute the @dfn{signum} function.
1929 
1930 This is defined as
1931 @tex
1932 $$
1933 {\rm sign} (@var{x}) = \cases{1,&$x>0$;\cr 0,&$x=0$;\cr -1,&$x<0$.\cr}
1934 $$
1935 @end tex
1936 @ifnottex
1937 
1938 @example
1939 @group
1940  -1, x < 0;
1941 sign (x) = 0, x = 0;
1942  1, x > 0.
1943 @end group
1944 @end example
1945 
1946 @end ifnottex
1947 
1948 For complex arguments, @code{sign} returns @code{x ./ abs (@var{x})}.
1949 
1950 Note that @code{sign (-0.0)} is 0. Although IEEE 754 floating point
1951 allows zero to be signed, 0.0 and -0.0 compare equal. If you must test
1952 whether zero is signed, use the @code{signbit} function.
1953 @seealso{signbit}
1954 @end deftypefn */)
1955 {
1956  if (args.length () != 1)
1957  print_usage ();
1958 
1959  return ovl (args(0).signum ());
1960 }
1961 
1962 /*
1963 %!assert (sign (-2) , -1)
1964 %!assert (sign (0), 0)
1965 %!assert (sign (3), 1)
1966 %!assert (sign ([1, -pi; e, 0]), [1, -1; 1, 0])
1967 
1968 %!assert (sign (single (-2)) , single (-1))
1969 %!assert (sign (single (0)), single (0))
1970 %!assert (sign (single (3)), single (1))
1971 %!assert (sign (single ([1, -pi; e, 0])), single ([1, -1; 1, 0]))
1972 
1973 %!error sign ()
1974 %!error sign (1, 2)
1975 */
1976 
1977 DEFUNX ("signbit", Fsignbit, args, ,
1978  doc: /* -*- texinfo -*-
1979 @deftypefn {} {@var{y} =} signbit (@var{x})
1980 Return logical true if the value of @var{x} has its sign bit set and false
1981 otherwise.
1982 
1983 This behavior is consistent with the other logical functions.
1984 @xref{Logical Values}. The behavior differs from the C language function
1985 which returns nonzero if the sign bit is set.
1986 
1987 This is not the same as @code{x < 0.0}, because IEEE 754 floating point
1988 allows zero to be signed. The comparison @code{-0.0 < 0.0} is false,
1989 but @code{signbit (-0.0)} will return a nonzero value.
1990 @seealso{sign}
1991 @end deftypefn */)
1992 {
1993  if (args.length () != 1)
1994  print_usage ();
1995 
1996  octave_value tmp = args(0).xsignbit ();
1997 
1998  return ovl (tmp != 0);
1999 }
2000 
2001 /*
2002 %!assert (signbit (1) == 0)
2003 %!assert (signbit (-2) != 0)
2004 %!assert (signbit (0) == 0)
2005 %!assert (signbit (-0) != 0)
2006 
2007 %!assert (signbit (single (1)) == 0)
2008 %!assert (signbit (single (-2)) != 0)
2009 %!assert (signbit (single (0)) == 0)
2010 %!assert (signbit (single (-0)) != 0)
2011 
2012 %!error sign ()
2013 %!error sign (1, 2)
2014 */
2015 
2016 DEFUN (sin, args, ,
2017  doc: /* -*- texinfo -*-
2018 @deftypefn {} {@var{y} =} sin (@var{x})
2019 Compute the sine for each element of @var{x} in radians.
2020 @seealso{asin, sind, sinh}
2021 @end deftypefn */)
2022 {
2023  if (args.length () != 1)
2024  print_usage ();
2025 
2026  return ovl (args(0).sin ());
2027 }
2028 
2029 /*
2030 %!shared rt2, rt3
2031 %! rt2 = sqrt (2);
2032 %! rt3 = sqrt (3);
2033 
2034 %!test
2035 %! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
2036 %! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
2037 %! assert (sin (x), v, sqrt (eps));
2038 
2039 %!test
2040 %! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
2041 %! v = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
2042 %! assert (sin (x), v, sqrt (eps ("single")));
2043 
2044 %!error sin ()
2045 %!error sin (1, 2)
2046 */
2047 
2048 DEFUN (sinh, args, ,
2049  doc: /* -*- texinfo -*-
2050 @deftypefn {} {@var{y} =} sinh (@var{x})
2051 Compute the hyperbolic sine for each element of @var{x}.
2052 @seealso{asinh, cosh, tanh}
2053 @end deftypefn */)
2054 {
2055  if (args.length () != 1)
2056  print_usage ();
2057 
2058  return ovl (args(0).sinh ());
2059 }
2060 
2061 /*
2062 %!test
2063 %! x = [0, pi/2*i, pi*i, 3*pi/2*i];
2064 %! v = [0, i, 0, -i];
2065 %! assert (sinh (x), v, sqrt (eps));
2066 
2067 %!test
2068 %! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
2069 %! v = single ([0, i, 0, -i]);
2070 %! assert (sinh (x), v, sqrt (eps ("single")));
2071 
2072 %!error sinh ()
2073 %!error sinh (1, 2)
2074 */
2075 
2076 DEFUN (sqrt, args, ,
2077  doc: /* -*- texinfo -*-
2078 @deftypefn {} {@var{y} =} sqrt (@var{x})
2079 Compute the square root of each element of @var{x}.
2080 
2081 If @var{x} is negative, a complex result is returned.
2082 
2083 To compute the matrix square root, @pxref{Linear Algebra}.
2084 @seealso{realsqrt, nthroot}
2085 @end deftypefn */)
2086 {
2087  if (args.length () != 1)
2088  print_usage ();
2089 
2090  return ovl (args(0).sqrt ());
2091 }
2092 
2093 /*
2094 %!assert (sqrt (4), 2)
2095 %!assert (sqrt (-1), i)
2096 %!assert (sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps))
2097 %!assert (sqrt ([4, -4; i, 1-i]),
2098 %! [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt (eps))
2099 
2100 %!assert (sqrt (single (4)), single (2))
2101 %!assert (sqrt (single (-1)), single (i))
2102 %!assert (sqrt (single (1+i)),
2103 %! single (exp (0.5 * log (1+i))), sqrt (eps ("single")))
2104 %!assert (sqrt (single ([4, -4; i, 1-i])),
2105 %! single ([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]),
2106 %! sqrt (eps ("single")))
2107 
2108 %!error sqrt ()
2109 %!error sqrt (1, 2)
2110 */
2111 
2112 DEFUN (tan, args, ,
2113  doc: /* -*- texinfo -*-
2114 @deftypefn {} {@var{y} =} tan (@var{z})
2115 Compute the tangent for each element of @var{x} in radians.
2116 @seealso{atan, tand, tanh}
2117 @end deftypefn */)
2118 {
2119  if (args.length () != 1)
2120  print_usage ();
2121 
2122  return ovl (args(0).tan ());
2123 }
2124 
2125 /*
2126 %!shared rt2, rt3
2127 %! rt2 = sqrt (2);
2128 %! rt3 = sqrt (3);
2129 
2130 %!test
2131 %! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
2132 %! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
2133 %! assert (tan (x), v, sqrt (eps));
2134 
2135 %!test
2136 %! x = single ([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
2137 %! v = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
2138 %! assert (tan (x), v, sqrt (eps ("single")));
2139 
2140 %!error tan ()
2141 %!error tan (1, 2)
2142 */
2143 
2144 DEFUN (tanh, args, ,
2145  doc: /* -*- texinfo -*-
2146 @deftypefn {} {@var{y} =} tanh (@var{x})
2147 Compute hyperbolic tangent for each element of @var{x}.
2148 @seealso{atanh, sinh, cosh}
2149 @end deftypefn */)
2150 {
2151  if (args.length () != 1)
2152  print_usage ();
2153 
2154  return ovl (args(0).tanh ());
2155 }
2156 
2157 /*
2158 %!test
2159 %! x = [0, pi*i];
2160 %! v = [0, 0];
2161 %! assert (tanh (x), v, sqrt (eps));
2162 
2163 %!test
2164 %! x = single ([0, pi*i]);
2165 %! v = single ([0, 0]);
2166 %! assert (tanh (x), v, sqrt (eps ("single")));
2167 
2168 %!error tanh ()
2169 %!error tanh (1, 2)
2170 */
2171 
2172 DEFUN (lower, args, ,
2173  doc: /* -*- texinfo -*-
2174 @deftypefn {} {@var{y} =} lower (@var{s})
2175 @deftypefnx {} {@var{y} =} tolower (@var{s})
2176 Return a copy of the string or cell string @var{s}, with each uppercase
2177 character replaced by the corresponding lowercase one; non-alphabetic
2178 characters are left unchanged.
2179 
2180 For example:
2181 
2182 @example
2183 @group
2184 lower ("MiXeD cAsE 123")
2185  @result{} "mixed case 123"
2186 @end group
2187 @end example
2188 
2189 Programming Note: @code{tolower} is an alias for @code{lower} and either name
2190 can be used in Octave.
2191 
2192 @seealso{upper}
2193 @end deftypefn */)
2194 {
2195  if (args.length () != 1)
2196  print_usage ();
2197 
2198  return ovl (args(0).xtolower ());
2199 }
2200 
2201 DEFALIAS (tolower, lower);
2202 
2203 /*
2204 %!assert (lower ("OCTAVE"), "octave")
2205 %!assert (lower ("123OCTave! _&"), "123octave! _&")
2206 %!assert (lower ({"ABC", "DEF", {"GHI", {"JKL"}}}),
2207 %! {"abc", "def", {"ghi", {"jkl"}}})
2208 %!assert (lower (["ABC"; "DEF"]), ["abc"; "def"])
2209 %!assert (lower ({["ABC"; "DEF"]}), {["abc";"def"]})
2210 %!assert (lower (["ABCÄÖÜSS"; "abcäöüß"]),
2211 %! ["abcäöüss"; "abcäöüß"])
2212 %!assert (lower (repmat ("ÄÖÜ", 2, 1, 3)), repmat ("äöü", 2, 1, 3))
2213 %!assert (lower (68), 68)
2214 %!assert (lower ({[68, 68; 68, 68]}), {[68, 68; 68, 68]})
2215 %!assert (lower (68i), 68i)
2216 %!assert (lower ({[68i, 68; 68, 68i]}), {[68i, 68; 68, 68i]})
2217 %!assert (lower (single (68i)), single (68i))
2218 %!assert (lower ({single([68i, 68; 68, 68i])}), {single([68i, 68; 68, 68i])})
2219 
2220 %!test
2221 %! classes = {@char, @double, @single, ...
2222 %! @int8, @int16, @int32, @int64, ...
2223 %! @uint8, @uint16, @uint32, @uint64};
2224 %! for i = 1:numel (classes)
2225 %! cls = classes{i};
2226 %! assert (class (lower (cls (97))), class (cls (97)));
2227 %! assert (class (lower (cls ([98, 99]))), class (cls ([98, 99])));
2228 %! endfor
2229 %!test
2230 %! a(3,3,3,3) = "D";
2231 %! assert (lower (a)(3,3,3,3), "d");
2232 
2233 %!test
2234 %! charset = char (0:127);
2235 %! result = charset;
2236 %! result (double ("A":"Z") + 1) = result (double ("a":"z") + 1);
2237 %! assert (lower (charset), result);
2238 
2239 %!error <Invalid call to lower> lower ()
2240 %!error <Invalid call to lower> tolower ()
2241 %!error lower (1, 2)
2242 */
2243 
2244 DEFUN (upper, args, ,
2245  doc: /* -*- texinfo -*-
2246 @deftypefn {} {@var{y} =} upper (@var{s})
2247 @deftypefnx {} {@var{y} =} toupper (@var{s})
2248 Return a copy of the string or cell string @var{s}, with each lowercase
2249 character replaced by the corresponding uppercase one; non-alphabetic
2250 characters are left unchanged.
2251 
2252 For example:
2253 
2254 @example
2255 @group
2256 upper ("MiXeD cAsE 123")
2257  @result{} "MIXED CASE 123"
2258 @end group
2259 @end example
2260 
2261 Programming Note: @code{toupper} is an alias for @code{upper} and either name
2262 can be used in Octave.
2263 
2264 @seealso{lower}
2265 @end deftypefn */)
2266 {
2267  if (args.length () != 1)
2268  print_usage ();
2269 
2270  return ovl (args(0).xtoupper ());
2271 }
2272 
2273 DEFALIAS (toupper, upper);
2274 
2275 /*
2276 %!assert (upper ("octave"), "OCTAVE")
2277 %!assert (upper ("123OCTave! _&"), "123OCTAVE! _&")
2278 %!assert (upper ({"abc", "def", {"ghi", {"jkl"}}}),
2279 %! {"ABC", "DEF", {"GHI", {"JKL"}}})
2280 %!assert (upper (["abc"; "def"]), ["ABC"; "DEF"])
2281 %!assert (upper ({["abc"; "def"]}), {["ABC";"DEF"]})
2282 %!assert (upper (["ABCÄÖÜSS"; "abcäöüß"]),
2283 %! ["ABCÄÖÜSS"; "ABCÄÖÜSS"])
2284 %!assert (upper (repmat ("äöü", 2, 1, 3)), repmat ("ÄÖÜ", 2, 1, 3))
2285 %!assert (upper (100), 100)
2286 %!assert (upper ({[100, 100; 100, 100]}), {[100, 100; 100, 100]})
2287 %!assert (upper (100i), 100i)
2288 %!assert (upper ({[100i, 100; 100, 100i]}), {[100i, 100; 100, 100i]})
2289 %!assert (upper (single (100i)), single (100i))
2290 %!assert (upper ({single([100i, 100; 100, 100i])}),
2291 %! {single([100i, 100; 100, 100i])})
2292 
2293 %!test
2294 %! classes = {@char, @double, @single, ...
2295 %! @int8, @int16, @int32, @int64, ...
2296 %! @uint8, @uint16, @uint32, @uint64};
2297 %! for i = 1:numel (classes)
2298 %! cls = classes{i};
2299 %! assert (class (upper (cls (97))), class (cls (97)));
2300 %! assert (class (upper (cls ([98, 99]))), class (cls ([98, 99])));
2301 %! endfor
2302 %!test
2303 %! a(3,3,3,3) = "d";
2304 %! assert (upper (a)(3,3,3,3), "D");
2305 %!test
2306 %! charset = char (0:127);
2307 %! result = charset;
2308 %! result (double ("a":"z") + 1) = result (double ("A":"Z") + 1);
2309 %! assert (upper (charset), result);
2310 
2311 %!error <Invalid call to upper> upper ()
2312 %!error <Invalid call to upper> toupper ()
2313 %!error upper (1, 2)
2314 */
2315 
2316 DEFALIAS (gammaln, lgamma);
2317 
2318 OCTAVE_END_NAMESPACE(octave)
ComplexColumnVector conj(const ComplexColumnVector &a)
Definition: CColVector.cc:217
octave_value xsignbit() const
Definition: ov.h:1507
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
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:1823
double dawson(double x)
Definition: lo-specfun.cc:1467
double erfcinv(double x)
Definition: lo-specfun.cc:1697
Complex expm1(const Complex &x)
Definition: lo-specfun.cc:1835
Complex log1p(const Complex &x)
Definition: lo-specfun.cc:1919
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_value_list Fisascii(const octave_value_list &args, int)
Definition: mappers.cc:1287
octave_value_list Fispunct(const octave_value_list &args, int)
Definition: mappers.cc:1571
octave_value_list Fisgraph(const octave_value_list &args, int)
Definition: mappers.cc:1407
octave_value_list Fisupper(const octave_value_list &args, int)
Definition: mappers.cc:1627
octave_value_list Fisspace(const octave_value_list &args, int)
Definition: mappers.cc:1601
octave_value_list Fislower(const octave_value_list &args, int)
Definition: mappers.cc:1433
octave_value_list Fisdigit(const octave_value_list &args, int)
Definition: mappers.cc:1337
octave_value_list Fiscntrl(const octave_value_list &args, int)
Definition: mappers.cc:1311
octave_value_list Fisalnum(const octave_value_list &args, int)
Definition: mappers.cc:1230
octave_value_list Fisalpha(const octave_value_list &args, int)
Definition: mappers.cc:1260
octave_value_list Fisxdigit(const octave_value_list &args, int)
Definition: mappers.cc:1653
octave_value_list Fsignbit(const octave_value_list &args, int)
Definition: mappers.cc:1991
octave_value_list Fisprint(const octave_value_list &args, int)
Definition: mappers.cc:1545
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)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219
template int8_t abs(int8_t)