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