1######################################################################## 2## 3## Copyright (C) 2016-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {@var{deg} =} rad2deg (@var{rad}) 28## 29## Convert radians to degrees. 30## 31## The input @var{rad} must be a scalar, vector, or N-dimensional array of 32## double or single floating point values. @var{rad} may be complex in which 33## case the real and imaginary components are converted separately. 34## 35## The output @var{deg} is the same size and shape as @var{rad} with radians 36## converted to degrees using the conversion constant @code{180/pi}. 37## 38## Example: 39## 40## @example 41## @group 42## rad2deg ([0, pi/2, pi, 3/2*pi, 2*pi]) 43## @result{} 0 90 180 270 360 44## @end group 45## @end example 46## @seealso{deg2rad} 47## @end deftypefn 48 49function deg = rad2deg (rad) 50 51 if (nargin != 1) 52 print_usage (); 53 endif 54 55 if (! isfloat (rad)) 56 error ("rad2deg: RAD must be a floating point class (double or single)"); 57 endif 58 59 deg = rad * (180/pi); 60 61endfunction 62 63 64%!assert (rad2deg (0), 0) 65%!assert (rad2deg (pi/2), 90) 66%!assert (rad2deg (pi), 180) 67%!assert (rad2deg (pi*[0, 1/2, 1, 3/2, 2]), [0, 90, 180, 270, 360]) 68 69## Test input validation 70%!error rad2deg () 71%!error rad2deg (1, 2) 72%!error <RAD must be a floating point class> rad2deg (uint8 (1)) 73%!error <RAD must be a floating point class> rad2deg ("A") 74