Mercurial > hg > octave-lyh
diff liboctave/CMatrix.cc @ 1699:0c6d3b73bf69
[project @ 1996-01-07 02:36:50 by jwe]
author | jwe |
---|---|
date | Sun, 07 Jan 1996 02:40:17 +0000 |
parents | 67678f04b8ba |
children | 8b8498bf8ec5 |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -136,7 +136,8 @@ { int a_nr = a.rows (); int a_nc = a.cols (); - if (r < 0 || r + a_nr - 1 > rows () || c < 0 || c + a_nc - 1 > cols ()) + + if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; @@ -153,7 +154,7 @@ ComplexMatrix::insert (const RowVector& a, int r, int c) { int a_len = a.length (); - if (r < 0 || r >= rows () || c < 0 || c + a_len - 1 > cols ()) + if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; @@ -169,7 +170,7 @@ ComplexMatrix::insert (const ColumnVector& a, int r, int c) { int a_len = a.length (); - if (r < 0 || r + a_len - 1 > rows () || c < 0 || c >= cols ()) + if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; @@ -184,13 +185,17 @@ ComplexMatrix& ComplexMatrix::insert (const DiagMatrix& a, int r, int c) { - if (r < 0 || r + a.rows () - 1 > rows () - || c < 0 || c + a.cols () - 1 > cols ()) + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; } + fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); + for (int i = 0; i < a.length (); i++) elem (r+i, c+i) = a.elem (i, i); @@ -208,7 +213,7 @@ ComplexMatrix::insert (const ComplexRowVector& a, int r, int c) { int a_len = a.length (); - if (r < 0 || r >= rows () || c < 0 || c + a_len - 1 > cols ()) + if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; @@ -224,7 +229,7 @@ ComplexMatrix::insert (const ComplexColumnVector& a, int r, int c) { int a_len = a.length (); - if (r < 0 || r + a_len - 1 > rows () || c < 0 || c >= cols ()) + if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; @@ -239,13 +244,17 @@ ComplexMatrix& ComplexMatrix::insert (const ComplexDiagMatrix& a, int r, int c) { - if (r < 0 || r + a.rows () - 1 > rows () - || c < 0 || c + a.cols () - 1 > cols ()) + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) { (*current_liboctave_error_handler) ("range error for insert"); return *this; } + fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); + for (int i = 0; i < a.length (); i++) elem (r+i, c+i) = a.elem (i, i);