changeset 20980:81c2b14c209f

maint: invert if/else/error instances. * Cell.cc, __ilu__.cc, bitfcns.cc, cellfun.cc data.cc, debug.cc, error.cc: Invert if/else/error instances.
author John W. Eaton <jwe@octave.org>
date Thu, 24 Dec 2015 13:55:51 -0500
parents 0963ed389012
children c11cea70b638
files libinterp/corefcn/Cell.cc libinterp/corefcn/__ilu__.cc libinterp/corefcn/bitfcns.cc libinterp/corefcn/cellfun.cc libinterp/corefcn/data.cc libinterp/corefcn/debug.cc libinterp/corefcn/error.cc
diffstat 7 files changed, 400 insertions(+), 416 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/Cell.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/Cell.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -290,20 +290,18 @@
 {
   Cell retval;
 
-  if (ndims () < 3)
-    {
-      if (i < 0 || i >= cols ())
-        error ("invalid column selection");
+  if (ndims () > 2)
+    error ("Cell::column: requires 2-D cell array");
 
-      octave_idx_type nr = rows ();
+  if (i < 0 || i >= cols ())
+    error ("invalid column selection");
 
-      retval.resize (dim_vector (nr, 1));
+  octave_idx_type nr = rows ();
 
-      for (octave_idx_type j = 0; j < nr; j++)
-        retval.xelem (j) = elem (j, i);
-    }
-  else
-    error ("Cell::column: requires 2-D cell array");
+  retval.resize (dim_vector (nr, 1));
+
+  for (octave_idx_type j = 0; j < nr; j++)
+    retval.xelem (j) = elem (j, i);
 
   return retval;
 }
--- a/libinterp/corefcn/__ilu__.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/__ilu__.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -105,14 +105,17 @@
       uptr[k] = j;
       if (opt != OFF)
         data[uptr[k]] -= r;
+
       if (opt != ROW)
         for (jj = uptr[k] + 1; jj < cidx[k+1]; jj++)
           data[jj] /=  data[uptr[k]];
+
       if (k != jrow)
         error ("ilu: A has a zero on the diagonal");
 
       if (data[j] == T(0))
         error ("ilu: encountered a pivot equal to 0");
+
       for (i = j1; i <= j2; i++)
         iw[ridx[i]] = -1;
     }
@@ -758,13 +761,11 @@
       //       will not preserve the row sum for that column/row.
       if (w_data[k] == zero)
         {
-          if (udiag == 1)
-            {
-              w_data[k] = droptol;
-              iw_u.insert (k);
-            }
-          else
+          if (udiag != 1)
             error ("ilu: encountered a pivot equal to 0");
+
+          w_data[k] = droptol;
+          iw_u.insert (k);
         }
 
       // Scale the elements on the L part for IKJ version (milu = [col|off])
@@ -825,8 +826,10 @@
       // octave_idx_type type due to fill-in during the process.
       if (total_len_l < 0 || total_len_u < 0)
         error ("ilu: Integer overflow.  Too many fill-in elements in L or U");
+
       if (opt == ROW)
         uptr[k] = total_len_u - 1;
+
       cidx_u[k+1] = cidx_u[k] - cidx_u[0] + w_len_u;
       cidx_l[k+1] = cidx_l[k] - cidx_l[0] + w_len_l;
 
--- a/libinterp/corefcn/bitfcns.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/bitfcns.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -88,30 +88,25 @@
 
   bool is_array_op = (dvx == dvy);
 
-  octave_value retval;
-  if (is_array_op || is_scalar_op)
-    {
-      Array<T> result;
-
-      if (nelx != 1)
-        result.resize (dvx);
-      else
-        result.resize (dvy);
-
-      for (int i = 0; i < nelx; i++)
-        if (is_scalar_op)
-          for (int k = 0; k < nely; k++)
-            result(i+k) = op (x(i), y(k));
-        else
-          result(i) = op (x(i), y(i));
-
-      retval = result;
-    }
-  else
+  if (! is_array_op && ! is_scalar_op)
     error ("%s: size of X and Y must match, or one operand must be a scalar",
            fname.c_str ());
 
-  return retval;
+  Array<T> result;
+
+  if (nelx != 1)
+    result.resize (dvx);
+  else
+    result.resize (dvy);
+
+  for (int i = 0; i < nelx; i++)
+    if (is_scalar_op)
+      for (int k = 0; k < nely; k++)
+        result(i+k) = op (x(i), y(k));
+    else
+      result(i) = op (x(i), y(i));
+
+  return result;
 }
 
 // Trampoline function, instantiates the proper template above, with
@@ -466,47 +461,43 @@
 #define DO_BITSHIFT(T) \
   double d1, d2; \
  \
-  if (n.all_integers (d1, d2)) \
-    { \
-      int m_nel = m.numel (); \
-      int n_nel = n.numel (); \
+  if (! n.all_integers (d1, d2)) \
+    error ("bitshift: K must be a scalar or array of integers"); \
  \
-      bool is_scalar_op = (m_nel == 1 || n_nel == 1); \
+  int m_nel = m.numel (); \
+  int n_nel = n.numel (); \
  \
-      dim_vector m_dv = m.dims (); \
-      dim_vector n_dv = n.dims (); \
+  bool is_scalar_op = (m_nel == 1 || n_nel == 1); \
  \
-      bool is_array_op = (m_dv == n_dv); \
+  dim_vector m_dv = m.dims (); \
+  dim_vector n_dv = n.dims (); \
+ \
+  bool is_array_op = (m_dv == n_dv); \
  \
-      if (is_array_op || is_scalar_op) \
-        { \
-          T ## NDArray result; \
+  if (! is_array_op && ! is_scalar_op) \
+    error ("bitshift: size of A and N must match, or one operand must be a scalar"); \
  \
-          if (m_nel != 1) \
-            result.resize (m_dv); \
-          else \
-            result.resize (n_dv); \
+  T ## NDArray result; \
  \
-          for (int i = 0; i < m_nel; i++) \
-            if (is_scalar_op) \
-              for (int k = 0; k < n_nel; k++) \
-                if (static_cast<int> (n(k)) >= bits_in_type) \
-                  result(i+k) = 0; \
-                else \
-                  result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \
-            else \
-              if (static_cast<int> (n(i)) >= bits_in_type) \
-                result(i) = 0; \
-              else \
-                result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \
+  if (m_nel != 1) \
+    result.resize (m_dv); \
+  else \
+    result.resize (n_dv); \
  \
-          retval = result; \
-        } \
+  for (int i = 0; i < m_nel; i++) \
+    if (is_scalar_op) \
+      for (int k = 0; k < n_nel; k++) \
+        if (static_cast<int> (n(k)) >= bits_in_type) \
+          result(i+k) = 0; \
+        else \
+          result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \
+    else \
+      if (static_cast<int> (n(i)) >= bits_in_type) \
+        result(i) = 0; \
       else \
-        error ("bitshift: size of A and N must match, or one operand must be a scalar"); \
-    } \
-  else \
-    error ("bitshift: K must be a scalar or array of integers"); \
+        result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \
+ \
+  retval = result;
 
 #define DO_UBITSHIFT(T, N) \
   do \
@@ -585,13 +576,11 @@
       //        as the third argument.
       if (args(2).numel () > 1)
         error ("bitshift: N must be a scalar integer");
-      else
-        {
-          nbits = args(2).xint_value ("bitshift: N must be an integer");
+
+      nbits = args(2).xint_value ("bitshift: N must be an integer");
 
-          if (nbits < 0)
-            error ("bitshift: N must be positive");
-        }
+      if (nbits < 0)
+        error ("bitshift: N must be positive");
     }
 
   octave_value retval;
--- a/libinterp/corefcn/cellfun.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/cellfun.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -181,42 +181,38 @@
     }
   else if (name == "size")
     {
-      if (nargin == 3)
-        {
-          int d = args(2).nint_value () - 1;
+      if (nargin != 3)
+        error ("cellfun: not enough arguments for \"size\"");
+
+      int d = args(2).nint_value () - 1;
 
-          if (d < 0)
-            error ("cellfun: K must be a positive integer");
+      if (d < 0)
+        error ("cellfun: K must be a positive integer");
 
-          NDA result (f_args.dims ());
+      NDA result (f_args.dims ());
 
-          for (octave_idx_type count = 0; count < k; count++)
-            {
-              dim_vector dv = f_args.elem (count).dims ();
-              if (d < dv.length ())
-                result(count) = static_cast<double> (dv(d));
-              else
-                result(count) = 1.0;
-            }
+      for (octave_idx_type count = 0; count < k; count++)
+        {
+          dim_vector dv = f_args.elem (count).dims ();
+          if (d < dv.length ())
+            result(count) = static_cast<double> (dv(d));
+          else
+            result(count) = 1.0;
+        }
 
-          retval(0) = result;
-        }
-      else
-        error ("cellfun: not enough arguments for \"size\"");
+      retval(0) = result;
     }
   else if (name == "isclass")
     {
-      if (nargin == 3)
-        {
-          std::string class_name = args(2).string_value ();
-          BNDA result (f_args.dims ());
-          for (octave_idx_type count = 0; count < k; count++)
-            result(count) = (f_args.elem (count).class_name () == class_name);
+      if (nargin != 3)
+        error ("cellfun: not enough arguments for \"isclass\"");
 
-          retval(0) = result;
-        }
-      else
-        error ("cellfun: not enough arguments for \"isclass\"");
+      std::string class_name = args(2).string_value ();
+      BNDA result (f_args.dims ());
+      for (octave_idx_type count = 0; count < k; count++)
+        result(count) = (f_args.elem (count).class_name () == class_name);
+
+      retval(0) = result;
     }
 
   return retval;
@@ -446,244 +442,241 @@
         }
     }
 
-  if (func.is_function_handle () || func.is_inline_function ()
-      || func.is_function ())
-    {
-
-      bool uniform_output = true;
-      octave_value error_handler;
-
-      get_mapper_fun_options (args, nargin, uniform_output, error_handler);
+  if (! func.is_function_handle () && ! func.is_inline_function ()
+      && ! func.is_function ())
+    error ("cellfun: argument NAME must be a string or function handle");
 
-      // The following is an optimization because the symbol table can give a
-      // more specific function class, so this can result in fewer polymorphic
-      // function calls as the function gets called for each value of the array.
-      {
-        if (func.is_function_handle ())
-          {
-            octave_fcn_handle* f = func.fcn_handle_value ();
+  bool uniform_output = true;
+  octave_value error_handler;
 
-            // Overloaded function handles need to check the type of the
-            // arguments for each element of the array, so they cannot be
-            // optimized this way.
-            if (f -> is_overloaded ())
-              goto nevermind;
-          }
+  get_mapper_fun_options (args, nargin, uniform_output, error_handler);
 
-        std::string name = func.function_value () -> name ();
-        octave_value f = symbol_table::find_function (name);
-
-        if (f.is_defined ())
-          {
-            // Except for these two which are special cases...
-            if (name != "size" && name != "class")
-              {
-                // Try first the optimized code path for built-in functions
-                octave_value_list tmp_args = args;
-                tmp_args(0) = name;
+  // The following is an optimization because the symbol table can give a
+  // more specific function class, so this can result in fewer polymorphic
+  // function calls as the function gets called for each value of the array.
+  {
+    if (func.is_function_handle ())
+      {
+        octave_fcn_handle* f = func.fcn_handle_value ();
 
-                if (uniform_output)
-                  retval =
-                    try_cellfun_internal_ops<boolNDArray, NDArray> (tmp_args,
-                                                                    nargin);
-                else
-                  retval =
-                    try_cellfun_internal_ops<Cell, Cell> (tmp_args, nargin);
-
-                if (! retval.empty ())
-                  return retval;
-              }
-
-            // Okay, we tried, doesn't work, let's do the best we can instead
-            // and avoid polymorphic calls for each element of the array.
-            func = f;
-          }
+        // Overloaded function handles need to check the type of the
+        // arguments for each element of the array, so they cannot be
+        // optimized this way.
+        if (f -> is_overloaded ())
+          goto nevermind;
       }
 
-    nevermind:
-
-      // Extract cell arguments.
+    std::string name = func.function_value () -> name ();
+    octave_value f = symbol_table::find_function (name);
 
-      octave_value_list inputlist (nargin, octave_value ());
-
-      OCTAVE_LOCAL_BUFFER (Cell, inputs, nargin);
-      OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
+    if (f.is_defined ())
+      {
+        // Except for these two which are special cases...
+        if (name != "size" && name != "class")
+          {
+            // Try first the optimized code path for built-in functions
+            octave_value_list tmp_args = args;
+            tmp_args(0) = name;
 
-      // This is to prevent copy-on-write.
-      const Cell *cinputs = inputs;
+            if (uniform_output)
+              retval =
+                try_cellfun_internal_ops<boolNDArray, NDArray> (tmp_args,
+                                                                nargin);
+            else
+              retval =
+                try_cellfun_internal_ops<Cell, Cell> (tmp_args, nargin);
 
-      octave_idx_type k = 1;
-
-      dim_vector fdims (1, 1);
-
-      // Collect arguments.  Pre-fill scalar elements of inputlist array.
+            if (! retval.empty ())
+              return retval;
+          }
 
-      for (int j = 0; j < nargin; j++)
-        {
-          if (! args(j+1).is_cell ())
-            error ("cellfun: arguments must be cells");
+        // Okay, we tried, doesn't work, let's do the best we can instead
+        // and avoid polymorphic calls for each element of the array.
+        func = f;
+      }
+  }
 
-          inputs[j] = args(j+1).cell_value ();
-          mask[j] = inputs[j].numel () != 1;
-          if (! mask[j])
-            inputlist(j) = cinputs[j](0);
-        }
+ nevermind:
+
+  // Extract cell arguments.
+
+  octave_value_list inputlist (nargin, octave_value ());
+
+  OCTAVE_LOCAL_BUFFER (Cell, inputs, nargin);
+  OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
 
-      for (int j = 0; j < nargin; j++)
-        {
-          if (mask[j])
-            {
-              fdims = inputs[j].dims ();
-              k = inputs[j].numel ();
-              for (int i = j+1; i < nargin; i++)
-                {
-                  if (mask[i] && inputs[i].dims () != fdims)
-                    error ("cellfun: dimensions mismatch");
-                }
-              break;
-            }
-        }
+  // This is to prevent copy-on-write.
+  const Cell *cinputs = inputs;
+
+  octave_idx_type k = 1;
+
+  dim_vector fdims (1, 1);
+
+  // Collect arguments.  Pre-fill scalar elements of inputlist array.
+
+  for (int j = 0; j < nargin; j++)
+    {
+      if (! args(j+1).is_cell ())
+        error ("cellfun: arguments must be cells");
+
+      inputs[j] = args(j+1).cell_value ();
+      mask[j] = inputs[j].numel () != 1;
+      if (! mask[j])
+        inputlist(j) = cinputs[j](0);
+    }
 
-      unwind_protect frame;
-      frame.protect_var (buffer_error_messages);
-
-      if (error_handler.is_defined ())
-        buffer_error_messages++;
-
-      // Apply functions.
-
-      if (uniform_output)
+  for (int j = 0; j < nargin; j++)
+    {
+      if (mask[j])
         {
-          std::list<octave_value_list> idx_list (1);
-          idx_list.front ().resize (1);
-          std::string idx_type = "(";
+          fdims = inputs[j].dims ();
+          k = inputs[j].numel ();
+          for (int i = j+1; i < nargin; i++)
+            {
+              if (mask[i] && inputs[i].dims () != fdims)
+                error ("cellfun: dimensions mismatch");
+            }
+          break;
+        }
+    }
 
-          OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
+  unwind_protect frame;
+  frame.protect_var (buffer_error_messages);
+
+  if (error_handler.is_defined ())
+    buffer_error_messages++;
 
-          for (octave_idx_type count = 0; count < k; count++)
+  // Apply functions.
+
+  if (uniform_output)
+    {
+      std::list<octave_value_list> idx_list (1);
+      idx_list.front ().resize (1);
+      std::string idx_type = "(";
+
+      OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
+
+      for (octave_idx_type count = 0; count < k; count++)
+        {
+          for (int j = 0; j < nargin; j++)
             {
-              for (int j = 0; j < nargin; j++)
-                {
-                  if (mask[j])
-                    inputlist.xelem (j) = cinputs[j](count);
-                }
+              if (mask[j])
+                inputlist.xelem (j) = cinputs[j](count);
+            }
 
-              const octave_value_list tmp
-                = get_output_list (count, nargout, inputlist, func,
-                                   error_handler);
+          const octave_value_list tmp
+            = get_output_list (count, nargout, inputlist, func,
+                               error_handler);
+
+          if (nargout > 0 && tmp.length () < nargout)
+            error ("cellfun: function returned fewer than nargout values");
 
-              if (nargout > 0 && tmp.length () < nargout)
-                error ("cellfun: function returned fewer than nargout values");
+          if  (nargout > 0
+               || (nargout == 0
+                   && tmp.length () > 0 && tmp(0).is_defined ()))
+            {
+              int num_to_copy = tmp.length ();
 
-              if  (nargout > 0
-                   || (nargout == 0
-                       && tmp.length () > 0 && tmp(0).is_defined ()))
+              if (num_to_copy > nargout1)
+                num_to_copy = nargout1;
+
+              if (count == 0)
                 {
-                  int num_to_copy = tmp.length ();
-
-                  if (num_to_copy > nargout1)
-                    num_to_copy = nargout1;
-
-                  if (count == 0)
+                  for (int j = 0; j < num_to_copy; j++)
                     {
-                      for (int j = 0; j < num_to_copy; j++)
+                      if (tmp(j).is_defined ())
                         {
-                          if (tmp(j).is_defined ())
+                          octave_value val = tmp(j);
+
+                          if (val.numel () != 1)
+                            error ("cellfun: all values must be scalars when UniformOutput = true");
+
+                          retv[j] = val.resize (fdims);
+                        }
+                    }
+                }
+              else
+                {
+                  for (int j = 0; j < num_to_copy; j++)
+                    {
+                      if (tmp(j).is_defined ())
+                        {
+                          octave_value val = tmp(j);
+
+                          if (! retv[j].fast_elem_insert (count, val))
                             {
-                              octave_value val = tmp(j);
-
                               if (val.numel () != 1)
                                 error ("cellfun: all values must be scalars when UniformOutput = true");
 
-                              retv[j] = val.resize (fdims);
-                            }
-                        }
-                    }
-                  else
-                    {
-                      for (int j = 0; j < num_to_copy; j++)
-                        {
-                          if (tmp(j).is_defined ())
-                            {
-                              octave_value val = tmp(j);
-
-                              if (! retv[j].fast_elem_insert (count, val))
-                                {
-                                  if (val.numel () != 1)
-                                    error ("cellfun: all values must be scalars when UniformOutput = true");
-
-                                  idx_list.front ()(0) = count + 1.0;
-                                  retv[j].assign (octave_value::op_asn_eq,
-                                                  idx_type, idx_list, val);
-                                }
+                              idx_list.front ()(0) = count + 1.0;
+                              retv[j].assign (octave_value::op_asn_eq,
+                                              idx_type, idx_list, val);
                             }
                         }
                     }
                 }
             }
+        }
 
+      retval.resize (nargout1);
+
+      for (int j = 0; j < nargout1; j++)
+        {
+          if (nargout > 0 && retv[j].is_undefined ())
+            retval(j) = NDArray (fdims);
+          else
+            retval(j) = retv[j];
+        }
+    }
+  else
+    {
+      OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
+
+      for (int j = 0; j < nargout1; j++)
+        results[j].resize (fdims, Matrix ());
+
+      bool have_some_output = false;
+
+      for (octave_idx_type count = 0; count < k; count++)
+        {
+          for (int j = 0; j < nargin; j++)
+            {
+              if (mask[j])
+                inputlist.xelem (j) = cinputs[j](count);
+            }
+
+          const octave_value_list tmp
+            = get_output_list (count, nargout, inputlist, func,
+                               error_handler);
+
+          if (nargout > 0 && tmp.length () < nargout)
+            error ("cellfun: function returned fewer than nargout values");
+
+          if  (nargout > 0
+               || (nargout == 0
+                   && tmp.length () > 0 && tmp(0).is_defined ()))
+            {
+              int num_to_copy = tmp.length ();
+
+              if (num_to_copy > nargout1)
+                num_to_copy = nargout1;
+
+              if (num_to_copy > 0)
+                have_some_output = true;
+
+              for (int j = 0; j < num_to_copy; j++)
+                results[j](count) = tmp(j);
+            }
+        }
+
+      if (have_some_output || fdims.any_zero ())
+        {
           retval.resize (nargout1);
 
           for (int j = 0; j < nargout1; j++)
-            {
-              if (nargout > 0 && retv[j].is_undefined ())
-                retval(j) = NDArray (fdims);
-              else
-                retval(j) = retv[j];
-            }
-        }
-      else
-        {
-          OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
-
-          for (int j = 0; j < nargout1; j++)
-            results[j].resize (fdims, Matrix ());
-
-          bool have_some_output = false;
-
-          for (octave_idx_type count = 0; count < k; count++)
-            {
-              for (int j = 0; j < nargin; j++)
-                {
-                  if (mask[j])
-                    inputlist.xelem (j) = cinputs[j](count);
-                }
-
-              const octave_value_list tmp
-                = get_output_list (count, nargout, inputlist, func,
-                                   error_handler);
-
-              if (nargout > 0 && tmp.length () < nargout)
-                error ("cellfun: function returned fewer than nargout values");
-
-              if  (nargout > 0
-                   || (nargout == 0
-                       && tmp.length () > 0 && tmp(0).is_defined ()))
-                {
-                  int num_to_copy = tmp.length ();
-
-                  if (num_to_copy > nargout1)
-                    num_to_copy = nargout1;
-
-                  if (num_to_copy > 0)
-                    have_some_output = true;
-
-                  for (int j = 0; j < num_to_copy; j++)
-                    results[j](count) = tmp(j);
-                }
-            }
-
-          if (have_some_output || fdims.any_zero ())
-            {
-              retval.resize (nargout1);
-
-              for (int j = 0; j < nargout1; j++)
-                retval(j) = results[j];
-            }
+            retval(j) = results[j];
         }
     }
-  else
-    error ("cellfun: argument NAME must be a string or function handle");
 
   return retval;
 }
--- a/libinterp/corefcn/data.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/data.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -230,11 +230,14 @@
 
   if (! args(0).is_numeric_type ())
     gripe_wrong_type_arg ("atan2", args(0));
-  else if (! args(1).is_numeric_type ())
+
+  if (! args(1).is_numeric_type ())
     gripe_wrong_type_arg ("atan2", args(1));
-  else if (args(0).is_complex_type () || args(1).is_complex_type ())
+
+  if (args(0).is_complex_type () || args(1).is_complex_type ())
     error ("atan2: not defined for complex numbers");
-  else if (args(0).is_single_type () || args(1).is_single_type ())
+
+  if (args(0).is_single_type () || args(1).is_single_type ())
     {
       if (args(0).is_scalar_type () && args(1).is_scalar_type ())
         retval = atan2f (args(0).float_value (), args(1).float_value ());
@@ -613,11 +616,14 @@
 
   if (! args(0).is_numeric_type ())
     gripe_wrong_type_arg ("rem", args(0));
-  else if (! args(1).is_numeric_type ())
+
+  if (! args(1).is_numeric_type ())
     gripe_wrong_type_arg ("rem", args(1));
-  else if (args(0).is_complex_type () || args(1).is_complex_type ())
+
+  if (args(0).is_complex_type () || args(1).is_complex_type ())
     error ("rem: not defined for complex numbers");
-  else if (args(0).is_integer_type () || args(1).is_integer_type ())
+
+  if (args(0).is_integer_type () || args(1).is_integer_type ())
     {
       builtin_type_t btyp0 = args(0).builtin_type ();
       builtin_type_t btyp1 = args(1).builtin_type ();
@@ -626,10 +632,13 @@
       if (btyp1 == btyp_double || btyp1 == btyp_float)
         btyp1 = btyp0;
 
-      if (btyp0 == btyp1)
+      if (btyp0 != btyp1)
+        error ("rem: cannot combine %s and %d",
+               args(0).class_name ().c_str (),
+               args(1).class_name ().c_str ());
+
+      switch (btyp0)
         {
-          switch (btyp0)
-            {
 #define MAKE_INT_BRANCH(X) \
   case btyp_ ## X: \
     { \
@@ -637,27 +646,22 @@
       X##NDArray a1 = args(1).X##_array_value (); \
       retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \
     } \
-    break;
-
-              MAKE_INT_BRANCH (int8);
-              MAKE_INT_BRANCH (int16);
-              MAKE_INT_BRANCH (int32);
-              MAKE_INT_BRANCH (int64);
-              MAKE_INT_BRANCH (uint8);
-              MAKE_INT_BRANCH (uint16);
-              MAKE_INT_BRANCH (uint32);
-              MAKE_INT_BRANCH (uint64);
+    break
+
+          MAKE_INT_BRANCH (int8);
+          MAKE_INT_BRANCH (int16);
+          MAKE_INT_BRANCH (int32);
+          MAKE_INT_BRANCH (int64);
+          MAKE_INT_BRANCH (uint8);
+          MAKE_INT_BRANCH (uint16);
+          MAKE_INT_BRANCH (uint32);
+          MAKE_INT_BRANCH (uint64);
 
 #undef MAKE_INT_BRANCH
 
-            default:
-              panic_impossible ();
-            }
+        default:
+          panic_impossible ();
         }
-      else
-        error ("rem: cannot combine %s and %d",
-               args(0).class_name ().c_str (),
-               args(1).class_name ().c_str ());
     }
   else if (args(0).is_single_type () || args(1).is_single_type ())
     {
@@ -793,11 +797,14 @@
 
   if (! args(0).is_numeric_type ())
     gripe_wrong_type_arg ("mod", args(0));
-  else if (! args(1).is_numeric_type ())
+
+  if (! args(1).is_numeric_type ())
     gripe_wrong_type_arg ("mod", args(1));
-  else if (args(0).is_complex_type () || args(1).is_complex_type ())
+
+  if (args(0).is_complex_type () || args(1).is_complex_type ())
     error ("mod: not defined for complex numbers");
-  else if (args(0).is_integer_type () || args(1).is_integer_type ())
+
+  if (args(0).is_integer_type () || args(1).is_integer_type ())
     {
       builtin_type_t btyp0 = args(0).builtin_type ();
       builtin_type_t btyp1 = args(1).builtin_type ();
@@ -806,10 +813,13 @@
       if (btyp1 == btyp_double || btyp1 == btyp_float)
         btyp1 = btyp0;
 
-      if (btyp0 == btyp1)
+      if (btyp0 != btyp1)
+        error ("mod: cannot combine %s and %d",
+               args(0).class_name ().c_str (),
+               args(1).class_name ().c_str ());
+
+      switch (btyp0)
         {
-          switch (btyp0)
-            {
 #define MAKE_INT_BRANCH(X) \
   case btyp_ ## X: \
     { \
@@ -817,27 +827,22 @@
       X##NDArray a1 = args(1).X##_array_value (); \
       retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \
     } \
-    break;
-
-              MAKE_INT_BRANCH (int8);
-              MAKE_INT_BRANCH (int16);
-              MAKE_INT_BRANCH (int32);
-              MAKE_INT_BRANCH (int64);
-              MAKE_INT_BRANCH (uint8);
-              MAKE_INT_BRANCH (uint16);
-              MAKE_INT_BRANCH (uint32);
-              MAKE_INT_BRANCH (uint64);
+    break
+
+          MAKE_INT_BRANCH (int8);
+          MAKE_INT_BRANCH (int16);
+          MAKE_INT_BRANCH (int32);
+          MAKE_INT_BRANCH (int64);
+          MAKE_INT_BRANCH (uint8);
+          MAKE_INT_BRANCH (uint16);
+          MAKE_INT_BRANCH (uint32);
+          MAKE_INT_BRANCH (uint64);
 
 #undef MAKE_INT_BRANCH
 
-            default:
-              panic_impossible ();
-            }
+        default:
+          panic_impossible ();
         }
-      else
-        error ("mod: cannot combine %s and %d",
-               args(0).class_name ().c_str (),
-               args(1).class_name ().c_str ());
     }
   else if (args(0).is_single_type () || args(1).is_single_type ())
     {
@@ -1370,15 +1375,13 @@
     {
       octave_value arg0 = args(0);
 
-      if (arg0.ndims () == 2 && (arg0.rows () == 1 || arg0.columns () == 1))
-        {
-          octave_idx_type m = args(1).xint_value ("diag: invalid dimensions");
-          octave_idx_type n = args(2).xint_value ("diag: invalid dimensions");
-
-          retval = arg0.diag (m, n);
-        }
-      else
+      if (arg0.ndims () != 2 || (arg0.rows () != 1 && arg0.columns () != 1))
         error ("diag: V must be a vector");
+
+      octave_idx_type m = args(1).xint_value ("diag: invalid dimensions");
+      octave_idx_type n = args(2).xint_value ("diag: invalid dimensions");
+
+      retval = arg0.diag (m, n);
     }
 
   return retval;
@@ -1798,11 +1801,11 @@
                  cname.c_str ());
         }
 
-      if (result.length () > 0)
-        retval = result(0);
-      else
+      if (result.length () == 0)
         error ("conversion from %s to %s failed", dtype.c_str (),
                cname.c_str ());
+
+      retval = result(0);
     }
   else
     {
@@ -1826,11 +1829,11 @@
                  cname.c_str ());
         }
 
-      if (result.length () > 0)
-        retval = result(0);
-      else
+      if (result.length () == 0)
         error ("%s constructor failed for %s argument", dtype.c_str (),
                cname.c_str ());
+
+      retval = result(0);
     }
 
   return retval;
@@ -1862,11 +1865,11 @@
           error (e, "%s/%s method failed", dtype.c_str (), cattype.c_str ());
         }
 
-      if (tmp2.length () > 0)
-        retval = tmp2(0);
-      else
+      if (tmp2.length () == 0)
         error ("%s/%s method did not return a value", dtype.c_str (),
                cattype.c_str ());
+
+      retval = tmp2(0);
     }
   else
     {
@@ -5335,8 +5338,8 @@
         {
           if (new_size(i) < 0)
             error ("reshape: SIZE must be non-negative");
-          else
-            new_dims(i) = new_size(i);
+
+          new_dims(i) = new_size(i);
         }
     }
   else
@@ -5350,11 +5353,9 @@
             {
               if (empty_dim > 0)
                 error ("reshape: only a single dimension can be unknown");
-              else
-                {
-                  empty_dim = i;
-                  new_dims(i-1) = 1;
-                }
+
+              empty_dim = i;
+              new_dims(i-1) = 1;
             }
           else
             {
@@ -5379,8 +5380,8 @@
               if (a_nel != size_empty_dim * nel)
                 error ("reshape: SIZE is not divisible by the product of known dimensions (= %d)",
                        nel);
-              else
-                new_dims(empty_dim-1) = size_empty_dim;
+
+              new_dims(empty_dim-1) = size_empty_dim;
             }
         }
     }
@@ -5605,19 +5606,18 @@
   else if (p_arg.is_string ())
     {
       std::string str = p_arg.string_value ();
-      if ((strflag == sfcols || strflag == sfrows))
-        {
-          if (str == "cols" || str == "columns" || str == "rows")
-            error ("norm: invalid combination of options");
-          else if (str == "fro")
-            p_arg = octave_value (2);
-          else if (str == "inf")
-            p_arg = octave_Inf;
-          else
-            error ("norm: unrecognized option: %s", str.c_str ());
-        }
+      if (strflag != sfcols && strflag != sfrows)
+        error ("norm: invalid combination of options");
+
+      if (str == "cols" || str == "columns" || str == "rows")
+        error ("norm: invalid combination of options");
+
+      if (str == "fro")
+        p_arg = octave_value (2);
+      else if (str == "inf")
+        p_arg = octave_Inf;
       else
-        error ("norm: invalid combination of options");
+        error ("norm: unrecognized option: %s", str.c_str ());
     }
   else if (! p_arg.is_scalar_type ())
     gripe_wrong_type_arg ("norm", p_arg, true);
@@ -6771,6 +6771,7 @@
     {
       if (arg.is_sparse_type ())
         error ("issorted: sparse matrices not yet supported");
+
       if (arg.ndims () != 2)
         error ("issorted: A must be a 2-dimensional object");
 
@@ -7584,8 +7585,8 @@
       dim = args(2).int_value (true, false);
       if (dim < 1 || dim > args(0).ndims ())
         error ("diff: DIM must be a valid dimension");
-      else
-        dim -= 1;
+
+      dim -= 1;
     }
 
   return do_diff (args(0), order, dim);
@@ -7732,7 +7733,8 @@
 
   if (! args(0).is_numeric_type ())
     error ("base64_encode: encoding is supported only for numeric arrays");
-  else if (args(0).is_complex_type () || args(0).is_sparse_type ())
+
+  if (args(0).is_complex_type () || args(0).is_sparse_type ())
     error ("base64_encode: encoding complex or sparse data is not supported");
 
   octave_value_list retval;
--- a/libinterp/corefcn/debug.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/debug.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -902,12 +902,12 @@
     case 0: // dbtype
       dbg_fcn = get_user_code ();
 
-      if (dbg_fcn)
-        do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                   0, std::numeric_limits<int>::max ());
-      else
+      if (! dbg_fcn)
         error ("dbtype: must be inside a user function to give no arguments to dbtype\n");
 
+      do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                 0, std::numeric_limits<int>::max ());
+
       break;
 
     case 1: // (dbtype start:end) || (dbtype func) || (dbtype lineno)
@@ -935,11 +935,11 @@
                 if (std::min (start, end) <= 0)
                   error ("dbtype: start and end lines must be >= 1\n");
 
-                if (start <= end)
-                  do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                             start, end);
-                else
+                if (start > end)
                   error ("dbtype: start line must be less than end line\n");
+
+                do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                           start, end);
               }
           }
         else  // (dbtype func) || (dbtype lineno)
@@ -950,11 +950,11 @@
               {
                 dbg_fcn = get_user_code (arg);
 
-                if (dbg_fcn)
-                  do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                             0, std::numeric_limits<int>::max ());
-                else
+                if (! dbg_fcn)
                   error ("dbtype: function <%s> not found\n", arg.c_str ());
+
+                do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                           0, std::numeric_limits<int>::max ());
               }
             else  // (dbtype lineno)
               {
@@ -1001,7 +1001,8 @@
 
         if (std::min (start, end) <= 0)
           error ("dbtype: start and end lines must be >= 1\n");
-        else if (start > end)
+
+        if (start > end)
           error ("dbtype: start line must be less than end line\n");
 
         do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (), start, end);
--- a/libinterp/corefcn/error.cc	Thu Dec 24 12:50:28 2015 -0500
+++ b/libinterp/corefcn/error.cc	Thu Dec 24 13:55:51 2015 -0500
@@ -1852,15 +1852,13 @@
     {
       if (args(0).is_string ())
         {
-          if (args(0).string_value () == "reset")
-            {
-              Vlast_error_message = std::string ();
-              Vlast_error_id = std::string ();
+          if (args(0).string_value () != "reset")
+            error ("lasterror: unrecognized string argument");
 
-              Vlast_error_stack = initialize_last_error_stack ();
-            }
-          else
-            error ("lasterror: unrecognized string argument");
+          Vlast_error_message = std::string ();
+          Vlast_error_id = std::string ();
+
+          Vlast_error_stack = initialize_last_error_stack ();
         }
       else if (args(0).is_map ())
         {