Mercurial > hg > octave-terminal
changeset 7198:4555c116b420
[project @ 2007-11-27 03:06:10 by jwe]
author | jwe |
---|---|
date | Tue, 27 Nov 2007 03:06:10 +0000 |
parents | e1c865f21751 |
children | cd6ceb8cbf09 |
files | liboctave/ChangeLog liboctave/idx-vector.h liboctave/oct-inttypes.h src/ChangeLog src/ls-mat5.cc src/ov-intx.h |
diffstat | 6 files changed, 77 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2007-11-26 John W. Eaton <jwe@octave.org> + + * idx-vector.h (idx_vector::idx_vector_rep (const intNDArray<U>&)): + Eliminate unnecessary second arg from call to tree_to_mat_idx. + + * oct-inttypes.h (operator bool, operator char): Delete. + (bool_value, char_value, double_value, float_value): New functions. + 2007-11-26 David Bateman <dbateman@free.fr> * intNDArray.cc (template <class T> intNDArray<T>
--- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -74,13 +74,8 @@ { data = new octave_idx_type [len]; - bool conversion_error = false; - for (octave_idx_type i = 0; i < len; i++) - data[i] = tree_to_mat_idx (inda.elem (i), conversion_error); - - if (conversion_error) - return; + data[i] = tree_to_mat_idx (inda.elem (i)); } init_state ();
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -250,15 +250,21 @@ OCTAVE_INT_FIT_TO_RANGE (- static_cast<double> (ival), T) : 0; } + bool bool_value (void) const { return static_cast<bool> (value ()); } + + char char_value (void) const { return static_cast<char> (value ()); } + + double double_value (void) const { return static_cast<double> (value ()); } + + float float_value (void) const { return static_cast<float> (value ()); } + operator T (void) const { return value (); } - operator bool (void) const { return static_cast<bool> (value ()); } - - operator char (void) const { return static_cast<char> (value ()); } + // char and bool operators intentionally omitted. - operator double (void) const { return static_cast<double> (value ()); } + operator double (void) const { return double_value (); } - operator float (void) const { return static_cast<float> (value ()); } + operator float (void) const { return float_value (); } octave_int<T>& operator += (const octave_int<T>& x) {
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,41 @@ +2007-11-26 John W. Eaton <jwe@octave.org> + + * oct-stream.cc (do_write): Call float_value and double_value on + octave_int<T> objects instead of relying on conversion operators. + + * ls-mat5.cc (read_mat5_binary_element, OCTAVE_MAT5_INTEGER_READ): + Call double_value on octave_int<T> objects + instead of relying on conversion operator. + (read_mat5_binary_file_header): + Call char_value on octave_int<T> objects + instead of relying on conversion operator. + (read_mat5_binary_element): + Call bool_value on octave_int<T> objects + instead of relying on conversion operator. + + * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::double_value, + OCTAVE_VALUE_INT_MATRIX_T::scalar_value, + OCTAVE_VALUE_INT_MATRIX_T::matrix_value, + OCTAVE_VALUE_INT_MATRIX_T::complex_matrix_value, + OCTAVE_VALUE_INT_MATRIX_T::array_value, + OCTAVE_VALUE_INT_MATRIX_T::complex_array_value, + OCTAVE_VALUE_INT_SCALAR_T::double_value, + OCTAVE_VALUE_INT_SCALAR_T::scalar_value, + OCTAVE_VALUE_INT_SCALAR_T::matrix_value, + OCTAVE_VALUE_INT_SCALAR_T::complex_matrix_value, + OCTAVE_VALUE_INT_SCALAR_T::array_value, + OCTAVE_VALUE_INT_SCALAR_T::complex_array_value, + Call double_value on octave_int<T> objects + instead of relying on conversion operator. + (OCTAVE_VALUE_INT_MATRIX_T::bool_array_value, + OCTAVE_VALUE_INT_SCALAR_T::bool_array_value): + Call bool_value on octave_int<T> objects + instead of relying on conversion operator. + (OCTAVE_VALUE_INT_MATRIX_T::char_array_value, + OCTAVE_VALUE_INT_SCALAR_T::char_array_value): + Call char_value on octave_int<T> objects + instead of relying on conversion operator. + 2007-11-26 David Bateman <dbateman@free.fr> * Sparse-op-defs.h (SPARSE_BASE_REDUCTION_OP): Check that the fill
--- a/src/ls-mat5.cc +++ b/src/ls-mat5.cc @@ -334,7 +334,7 @@ ComplexNDArray ctmp (dims); \ \ for (int i = 0; i < n; i++) \ - ctmp(i) = Complex (double (re(i)), im(i)); \ + ctmp(i) = Complex (re(i).double_value (), im(i)); \ \ tc = ctmp; \ } \ @@ -863,7 +863,7 @@ { Octave_map m2 = m1.contents("workspace")(0).map_value(); uint32NDArray MCOS = m2.contents("MCOS")(0).uint32_array_value(); - octave_idx_type off = static_cast<octave_idx_type>(double (MCOS (4))); + octave_idx_type off = static_cast<octave_idx_type>(MCOS(4).double_value ()); m2 = subsys_ov.map_value(); m2 = m2.contents("MCOS")(0).map_value(); tc2 = m2.contents("MCOS")(0).cell_value()(1 + off).cell_value()(1); @@ -1140,7 +1140,7 @@ boolNDArray out (dims); for (int i = 0; i < nel; i++) - out (i) = static_cast<bool> (double (in (i))); + out (i) = in(i).bool_value (); tc = out; } @@ -1377,7 +1377,7 @@ // FIXME -- find a way to avoid casting away const here char *ctmp = const_cast<char *> (outbuf.c_str ()); for (octave_idx_type j = 8; j < ilen; j++) - ctmp [j - 8] = itmp (j); + ctmp[j-8] = itmp(j).char_value (); std::istringstream fh_ws (outbuf);
--- a/src/ov-intx.h +++ b/src/ov-intx.h @@ -99,7 +99,7 @@ gripe_implicit_conversion ("Octave:array-as-scalar", type_name (), "real scalar"); - retval = double (matrix(0)); + retval = matrix(0).double_value (); } else gripe_invalid_conversion (type_name (), "real scalar"); @@ -123,7 +123,7 @@ double *vec = retval.fortran_vec (); octave_idx_type nel = matrix.numel (); for (octave_idx_type i = 0; i < nel; i++) - vec[i] = double (matrix(i)); + vec[i] = matrix(i).double_value (); } return retval; } @@ -141,7 +141,7 @@ Complex *vec = retval.fortran_vec (); octave_idx_type nel = matrix.numel (); for (octave_idx_type i = 0; i < nel; i++) - vec[i] = Complex (double (matrix(i))); + vec[i] = Complex (matrix(i).double_value ()); } return retval; } @@ -153,7 +153,7 @@ double *vec = retval.fortran_vec (); octave_idx_type nel = matrix.numel (); for (octave_idx_type i = 0; i < nel; i++) - vec[i] = double (matrix(i)); + vec[i] = matrix(i).double_value (); return retval; } @@ -164,7 +164,7 @@ Complex *vec = retval.fortran_vec (); octave_idx_type nel = matrix.numel (); for (octave_idx_type i = 0; i < nel; i++) - vec[i] = Complex (double (matrix(i))); + vec[i] = Complex (matrix(i).double_value ()); return retval; } @@ -180,7 +180,7 @@ bool *vec = retval.fortran_vec (); for (octave_idx_type i = 0; i < nel; i++) - vec[i] = static_cast<bool> (matrix(i)); + vec[i] = matrix(i).bool_value (); return retval; } @@ -194,7 +194,7 @@ char *vec = retval.fortran_vec (); for (octave_idx_type i = 0; i < nel; i++) - vec[i] = static_cast<char> (matrix(i)); + vec[i] = matrix(i).char_value (); return retval; } @@ -361,16 +361,16 @@ } } - double double_value (bool = false) const { return double (scalar); } + double double_value (bool = false) const { return scalar.double_value (); } - double scalar_value (bool = false) const { return double (scalar); } + double scalar_value (bool = false) const { return scalar.double_value (); } Matrix matrix_value (bool = false) const { Matrix retval (1, 1); - retval(0,0) = double (scalar); + retval(0,0) = scalar.double_value (); return retval; } @@ -378,7 +378,7 @@ complex_matrix_value (bool = false) const { ComplexMatrix retval (1, 1); - retval(0,0) = Complex (double (scalar)); + retval(0,0) = Complex (scalar.double_value ()); return retval; } @@ -387,7 +387,7 @@ array_value (bool = false) const { NDArray retval (dim_vector (1, 1)); - retval(0) = double (scalar); + retval(0) = scalar.double_value (); return retval; } @@ -395,7 +395,7 @@ complex_array_value (bool = false) const { ComplexNDArray retval (dim_vector (1, 1)); - retval(0) = Complex (double (scalar)); + retval(0) = Complex (scalar.double_value ()); return retval; } @@ -407,7 +407,7 @@ if (warn && scalar != 0.0 && scalar != 1.0) gripe_logical_conversion (); - retval(0) = static_cast<bool> (scalar); + retval(0) = scalar.bool_value (); return retval; } @@ -416,7 +416,7 @@ char_array_value (bool = false) const { charNDArray retval (dim_vector (1, 1)); - retval(0) = static_cast<char> (scalar); + retval(0) = scalar.char_value (); return retval; }