changeset 26197:95633ec174cf

rat.m: Add input validation to detect and fail on complex inputs (bug #55198) emit an error. Add FIXME note that this test should be removed when support for complex numbers is added in bug #55198. Add BIST test to verify input validation.
author Rik <rik@octave.org>
date Mon, 10 Dec 2018 17:06:44 -0800
parents b8f23ab958e8
children d57d30caffd6
files scripts/general/rat.m
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/rat.m	Mon Dec 10 16:58:22 2018 -0800
+++ b/scripts/general/rat.m	Mon Dec 10 17:06:44 2018 -0800
@@ -67,6 +67,12 @@
     error ("rat: X must be a single or double array");
   endif
 
+  ## FIXME: This test should be removed when complex support is added.
+  ##        See bug #55198.
+  if (iscomplex (x))
+    error ("rat: X must be a real, not complex, array");
+  endif
+
   y = x(:);
 
   ## Replace Inf with 0 while calculating ratios.
@@ -214,6 +220,7 @@
 %!error rat ()
 %!error rat (1, 2, 3)
 %!error <X must be a single or double array> rat (int8 (3))
+%!error <X must be a real, not complex, array> rat (1+1i)
 %!error <TOL must be a numeric scalar> rat (1, "a")
 %!error <TOL must be a numeric scalar> rat (1, [1 2])
 %!error <TOL must be a numeric scalar . 0> rat (1, -1)