diff scripts/general/logical.m @ 7922:935be827eaf8

error for NaN values in & and | expressions
author John W. Eaton <jwe@octave.org>
date Fri, 11 Jul 2008 14:56:30 -0400
parents b5731e43283a
children eb63fbe60fab
line wrap: on
line diff
--- a/scripts/general/logical.m	Thu Jul 10 17:36:20 2008 -0400
+++ b/scripts/general/logical.m	Fri Jul 11 14:56:30 2008 -0400
@@ -42,7 +42,11 @@
     elseif (isempty (x))
       y = zeros (size (x), "logical");
     elseif (isnumeric (x))
-      y = x != 0;
+      if (any (isnan (x(:))))
+	error ("invalid conversion from NaN to logical");
+      else
+	y = x != 0;
+      endif
     else
       error ("logical not defined for type `%s'", typeinfo (x));
     endif
@@ -59,4 +63,6 @@
 %!assert (logical (-13), true);
 %!assert (logical (int8 (13)), true);
 %!assert (logical (int8 (-13)), true);
-%!assert (logical ([-1, 0, 1, NaN, Inf]), [-1, 0, 1, NaN, Inf] != 0);
+%!assert (logical ([-1, 0, 1, Inf]), [-1, 0, 1, Inf] != 0);
+%!error (logical ([-1, 0, 1, NaN, Inf]))
+%!error (logical (NaN))