annotate scripts/general/rad2deg.m @ 31205:b0e90ca8e679 stable

quad2d: fix unintended complex conjugate return (bug #62972) quad2d: use .' instead of ' to avoid complex conjugate in q and qerr.
author Arun Giridhar <arungiridhar@gmail.com>
date Sun, 28 Aug 2022 12:21:17 -0400
parents 796f54d4ddbf
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2016-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
7 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
8 ## This file is part of Octave.
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
14 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
19 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
25
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20734
diff changeset
27 ## @deftypefn {} {@var{deg} =} rad2deg (@var{rad})
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
28 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
29 ## Convert radians to degrees.
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
30 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
31 ## The input @var{rad} must be a scalar, vector, or N-dimensional array of
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
32 ## double or single floating point values. @var{rad} may be complex in which
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
33 ## case the real and imaginary components are converted separately.
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
34 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
35 ## The output @var{deg} is the same size and shape as @var{rad} with radians
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
36 ## converted to degrees using the conversion constant @code{180/pi}.
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
37 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
38 ## Example:
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
39 ##
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
40 ## @example
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
41 ## @group
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
42 ## rad2deg ([0, pi/2, pi, 3/2*pi, 2*pi])
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
43 ## @result{} 0 90 180 270 360
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
44 ## @end group
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
45 ## @end example
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
46 ## @seealso{deg2rad}
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
47 ## @end deftypefn
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
48
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
49 function deg = rad2deg (rad)
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
50
28891
de5f2f9a64ff maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents: 28886
diff changeset
51 if (nargin < 1)
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
52 print_usage ();
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
53 endif
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
54
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
55 if (! isfloat (rad))
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
56 error ("rad2deg: RAD must be a floating point class (double or single)");
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
57 endif
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
58
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
59 deg = rad * (180/pi);
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
60
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
61 endfunction
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
62
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
63
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
64 %!assert (rad2deg (0), 0)
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
65 %!assert (rad2deg (pi/2), 90)
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
66 %!assert (rad2deg (pi), 180)
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
67 %!assert (rad2deg (pi*[0, 1/2, 1, 3/2, 2]), [0, 90, 180, 270, 360])
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
68
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
69 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 27923
diff changeset
70 %!error <Invalid call> rad2deg ()
20734
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
71 %!error <RAD must be a floating point class> rad2deg (uint8 (1))
e44d904ac525 Add new functions deg2rad and rad2deg to core (bug #46340).
Rik <rik@octave.org>
parents:
diff changeset
72 %!error <RAD must be a floating point class> rad2deg ("A")