Mercurial > hg > octave-lyh
changeset 8626:1dce30ab0e72
don't convert NaN to logical in bool expressions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 29 Jan 2009 12:50:25 -0500 |
parents | 4d90d21a9cd9 |
children | fdd1cefd3714 |
files | liboctave/ChangeLog liboctave/boolNDArray.h liboctave/chNDArray.h liboctave/intNDArray.h src/Cell.h src/ChangeLog src/ov-base-mat.cc src/ov-base-scalar.cc src/ov-base-scalar.h src/ov-cell.cc src/ov-cell.h |
diffstat | 11 files changed, 52 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2009-01-29 John W. Eaton <jwe@octave.org> + + * intNDArray.h (intNDArray<T>:any_element_is_nan): New function. + * boolNDArrah.h (boolNDArray::any_element_is_nan): New function. + * chNDArray.h (charNDArray::any_element_is_nan): New function. + 2009-01-28 John W. Eaton <jwe@octave.org> * Makefile.in (LIBRARIES, install, uninstall): Use SHLLIBPRE
--- a/liboctave/boolNDArray.h +++ b/liboctave/boolNDArray.h @@ -59,6 +59,8 @@ boolNDArray operator ! (void) const; + bool any_element_is_nan (void) const { return false; } + // FIXME -- this is not quite the right thing. boolNDArray all (int dim = -1) const;
--- a/liboctave/chNDArray.h +++ b/liboctave/chNDArray.h @@ -61,6 +61,8 @@ return *this; } + bool any_element_is_nan (void) const { return false; } + // FIXME -- this is not quite the right thing. boolNDArray all (int dim = -1) const;
--- a/liboctave/intNDArray.h +++ b/liboctave/intNDArray.h @@ -63,6 +63,7 @@ boolNDArray operator ! (void) const; + bool any_element_is_nan (void) const { return false; } bool any_element_not_one_or_zero (void) const; intNDArray diag (octave_idx_type k = 0) const;
--- a/src/Cell.h +++ b/src/Cell.h @@ -121,6 +121,7 @@ Cell& insert (const Cell& a, const Array<octave_idx_type>& ra_idx); // FIXME + bool any_element_is_nan (void) const { return false; } bool is_true (void) const { return false; } static octave_value resize_fill_value (void) { return Matrix (); }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2009-01-29 John W. Eaton <jwe@octave.org> + + * ov-base-scalar.cc (octave_base_scalar<ST>::is_true (void) const): + Error if scalar is NaN. + * ov-base-mat.cc (octave_base_matrix<MT>::is_true (void) const): + Likewise, if any element of matrix is NaN. + * ov-cell.cc (octave_cell::is_true): New function. + * Cell.h (Cell::any_element_is_nan): New function. + 2009-01-29 Jaroslav Hajek <highegg@gmail.com> * pr-output.cc:
--- a/src/ov-base-mat.cc +++ b/src/ov-base-mat.cc @@ -247,9 +247,14 @@ { MT t1 (matrix.reshape (dim_vector (nel, 1))); - boolNDArray t2 = t1.all (); + if (t1.any_element_is_nan ()) + error ("invalid conversion from NaN to logical"); + else + { + boolNDArray t2 = t1.all (); - retval = t2(0); + retval = t2(0); + } } return retval;
--- a/src/ov-base-scalar.cc +++ b/src/ov-base-scalar.cc @@ -101,6 +101,20 @@ } template <class ST> +bool +octave_base_scalar<ST>::is_true (void) const +{ + bool retval = false; + + if (xisnan (scalar)) + error ("invalid conversion from NaN to logical"); + else + retval = (scalar != ST ()); + + return retval; +} + +template <class ST> void octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax) const {
--- a/src/ov-base-scalar.h +++ b/src/ov-base-scalar.h @@ -116,7 +116,7 @@ bool is_numeric_type (void) const { return true; } - bool is_true (void) const { return (scalar != ST ()); } + bool is_true (void) const; void print (std::ostream& os, bool pr_as_read_syntax = false) const;