changeset 2500:e39839e18edc

[project @ 1996-11-12 17:13:53 by jwe]
author jwe
date Tue, 12 Nov 1996 17:13:53 +0000
parents 20db7604d5c6
children 194524db6644
files liboctave/ChangeLog liboctave/idx-vector.cc
diffstat 2 files changed, 56 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Tue Nov 12 06:16:21 1996 +0000
+++ b/liboctave/ChangeLog	Tue Nov 12 17:13:53 1996 +0000
@@ -1,3 +1,8 @@
+Tue Nov 12 11:11:21 1996  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* idx-vector.cc (idx_is_inf_or_nan): New function.
+	(IDX_VEC_REP::idx_vector_rep): Use it.
+
 Sun Nov 10 17:09:24 1996  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* str-vec.h, str-vec.cc: Add constructors to make string vectors
--- a/liboctave/idx-vector.cc	Tue Nov 12 06:16:21 1996 +0000
+++ b/liboctave/idx-vector.cc	Tue Nov 12 17:13:53 1996 +0000
@@ -38,6 +38,7 @@
 
 #include "idx-vector.h"
 #include "lo-error.h"
+#include "lo-mappers.h"
 
 #define IDX_VEC_REP idx_vector::idx_vector_rep
 
@@ -73,10 +74,26 @@
 static inline int
 tree_to_mat_idx (double x)
 {
-  if (x > 0)
-    return ((int) (x + 0.5) - 1);
-  else
-    return ((int) (x - 0.5) - 1);
+  return (x > 0) ? ((int) (x + 0.5) - 1) : ((int) (x - 0.5) - 1);
+}
+
+static inline bool
+idx_is_inf_or_nan (double x)
+{
+  bool retval = false;
+
+  if (xisnan (x))
+    {
+      (*current_liboctave_error_handler) ("NaN invalid as index");
+      retval = true;
+    }
+  else if (xisinf (x))
+    {
+      (*current_liboctave_error_handler) ("Inf invalid as index");
+      retval = true;
+    }
+
+  return retval;
 }
 
 IDX_VEC_REP::idx_vector_rep (const ColumnVector& v)
@@ -106,8 +123,16 @@
   else
     {
       data = new int [len];
+
       for (int i = 0; i < len; i++)
-	data[i] = tree_to_mat_idx (v.elem (i));
+	{
+	  double d = v.elem (i);
+
+	  if (idx_is_inf_or_nan (d))
+	    return;
+	  else
+	    data[i] = tree_to_mat_idx (d);
+	}
     }
 
   init_state ();
@@ -141,9 +166,17 @@
     {
       int k = 0;
       data = new int [len];
+
       for (int j = 0; j < orig_nc; j++)
 	for (int i = 0; i < orig_nr; i++)
-	  data[k++] = tree_to_mat_idx (m.elem (i, j));
+	  {
+	    double d = m.elem (i, j);
+
+	    if (idx_is_inf_or_nan (d))
+	      return;
+	    else
+	      data[k++] = tree_to_mat_idx (d);
+	  }
     }
 
   init_state ();
@@ -163,11 +196,14 @@
   orig_nr = 1;
   orig_nc = 1;
 
-  data = new int [len];
+  if (idx_is_inf_or_nan (d))
+    return;
+  else
+    {
+      data = new int [len];
 
-  data[0] = tree_to_mat_idx (d);
-
-  init_state ();
+      data[0] = tree_to_mat_idx (d);
+    }
 }
 
 IDX_VEC_REP::idx_vector_rep (const Range& r)
@@ -208,7 +244,11 @@
   for (int i = 0; i < len; i++)
     {
       double val = b + i * step;
-      data[i] = tree_to_mat_idx (val);
+
+      if (idx_is_inf_or_nan (val))
+	return;
+      else
+	data[i] = tree_to_mat_idx (val);
     }
 
   init_state ();