Mercurial > hg > octave-nkf
changeset 2383:096529066838
[project @ 1996-10-12 17:50:47 by jwe]
author | jwe |
---|---|
date | Sat, 12 Oct 1996 17:52:55 +0000 |
parents | 58e5955495d7 |
children | d9147efd1a93 |
files | liboctave/MArray.cc liboctave/MArray2.cc liboctave/MDiagArray2.cc liboctave/Range.cc liboctave/Range.h |
diffstat | 5 files changed, 66 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/MArray.cc +++ b/liboctave/MArray.cc @@ -62,9 +62,9 @@ int l = a.length (); if (l > 0) { - if (l != b.length ()) - (*current_liboctave_error_handler) \ - ("nonconformant += array operation attempted"); \ + int bl = b.length (); + if (l != bl) + gripe_nonconformant ("operator +=", l, bl); else DO_VV_OP2 (+=); } @@ -78,9 +78,9 @@ int l = a.length (); if (l > 0) { - if (l != b.length ()) - (*current_liboctave_error_handler) \ - ("nonconformant -= array operation attempted"); \ + int bl = b.length (); + if (l != bl) + gripe_nonconformant ("operator -=", l, bl); else DO_VV_OP2 (-=); } @@ -121,16 +121,16 @@ // Element by element MArray by MArray ops. -#define MARRAY_AA_OP(FCN, OP, OP_STR) \ +#define MARRAY_AA_OP(FCN, OP) \ template <class T> \ MArray<T> \ FCN (const MArray<T>& a, const MArray<T>& b) \ { \ int l = a.length (); \ - if (l != b.length ()) \ + int bl = b.length (); \ + if (l != bl) \ { \ - (*current_liboctave_error_handler) \ - ("nonconformant array " OP_STR " attempted"); \ + gripe_nonconformant (#FCN, l, bl); \ return MArray<T> (); \ } \ if (l == 0) \ @@ -139,10 +139,10 @@ return MArray<T> (result, l); \ } -MARRAY_AA_OP (operator +, +, "addition") -MARRAY_AA_OP (operator -, -, "subtraction") -MARRAY_AA_OP (product, *, "multiplication") -MARRAY_AA_OP (quotient, /, "division") +MARRAY_AA_OP (operator +, +) +MARRAY_AA_OP (operator -, -) +MARRAY_AA_OP (product, *) +MARRAY_AA_OP (quotient, /) // Unary MArray ops.
--- a/liboctave/MArray2.cc +++ b/liboctave/MArray2.cc @@ -61,11 +61,10 @@ { int r = a.rows (); int c = a.cols (); - if (r != b.rows () || c != b.cols ()) - { - (*current_liboctave_error_handler) - ("nonconformant += array operation attempted"); - } + int br = b.rows (); + int bc = b.cols (); + if (r != br || c != bc) + gripe_nonconformant ("operator +=", r, c, br, bc); else { if (r > 0 && c > 0) @@ -83,11 +82,10 @@ { int r = a.rows (); int c = a.cols (); - if (r != b.rows () || c != b.cols ()) - { - (*current_liboctave_error_handler) - ("nonconformant -= array operation attempted"); - } + int br = b.rows (); + int bc = b.cols (); + if (r != br || c != bc) + gripe_nonconformant ("operator -=", r, c, br, bc); else { if (r > 0 && c > 0) @@ -133,17 +131,18 @@ // Element by element MArray2 by MArray2 ops. -#define MARRAY_A2A2_OP(FCN, OP, OP_STR) \ +#define MARRAY_A2A2_OP(FCN, OP) \ template <class T> \ MArray2<T> \ FCN (const MArray2<T>& a, const MArray2<T>& b) \ { \ int r = a.rows (); \ int c = a.cols (); \ - if (r != b.rows () || c != b.cols ()) \ + int br = b.rows (); \ + int bc = b.cols (); \ + if (r != br || c != bc) \ { \ - (*current_liboctave_error_handler) \ - ("nonconformant array " OP_STR " attempted"); \ + gripe_nonconformant (#FCN, r, c, br, bc); \ return MArray2<T> (); \ } \ if (r == 0 || c == 0) \ @@ -153,10 +152,10 @@ return MArray2<T> (result, r, c); \ } -MARRAY_A2A2_OP (operator +, +, "addition") -MARRAY_A2A2_OP (operator -, -, "subtraction") -MARRAY_A2A2_OP (product, *, "product") -MARRAY_A2A2_OP (quotient, /, "quotient") +MARRAY_A2A2_OP (operator +, +) +MARRAY_A2A2_OP (operator -, -) +MARRAY_A2A2_OP (product, *) +MARRAY_A2A2_OP (quotient, /) // Unary MArray2 ops.
--- a/liboctave/MDiagArray2.cc +++ b/liboctave/MDiagArray2.cc @@ -43,10 +43,13 @@ { int r = a.rows (); int c = a.cols (); - if (r != b.rows () || c != b.cols ()) + + int b_nr = b.rows (); + int b_nc = b.cols (); + + if (r != b_nr || c != b_nc) { - (*current_liboctave_error_handler) - ("nonconformant array operator += attempted"); + gripe_nonconformant ("operator +=", r, c, b_nr, b_nc); static MDiagArray2<T> foo; return foo; } @@ -64,10 +67,13 @@ { int r = a.rows (); int c = a.cols (); - if (r != b.rows () || c != b.cols ()) + + int b_nr = b.rows (); + int b_nc = b.cols (); + + if (r != b_nr || c != b_nc) { - (*current_liboctave_error_handler) - ("nonconformant array operator -= attempted"); + gripe_nonconformant ("operator -=", r, c, b_nr, b_nc); static MDiagArray2<T> foo; return foo; } @@ -105,17 +111,18 @@ // Element by element MDiagArray2 by MDiagArray2 ops. -#define MARRAY_DADA_OP(FCN, OP, OP_STR) \ +#define MARRAY_DADA_OP(FCN, OP) \ template <class T> \ MDiagArray2<T> \ FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \ { \ int r = a.rows (); \ int c = a.cols (); \ - if (r != b.rows () || c != b.cols ()) \ + int b_nr = b.rows (); \ + int b_nc = b.cols (); \ + if (r != b_nr || c != b_nc) \ { \ - (*current_liboctave_error_handler) \ - ("nonconformant diagonal array " OP_STR " attempted"); \ + gripe_nonconformant (#FCN, r, c, b_nr, b_nc); \ return MDiagArray2<T> (); \ } \ if (c == 0 || r == 0) \ @@ -125,9 +132,9 @@ return MDiagArray2<T> (result, r, c); \ } -MARRAY_DADA_OP (operator +, +, "addition") -MARRAY_DADA_OP (operator -, -, "subtraction") -MARRAY_DADA_OP (product, *, "product") +MARRAY_DADA_OP (operator +, +) +MARRAY_DADA_OP (operator -, -) +MARRAY_DADA_OP (product, *) // Unary MDiagArray2 ops.
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -36,6 +36,19 @@ #include "Range.h" #include "dMatrix.h" +#include "lo-mappers.h" +#include "lo-utils.h" + +bool +Range::all_elements_are_ints (void) const +{ + // If the base and increment are ints, the final value in the range + // will also be an integer, even if the limit is not. + + return (! (xisnan (rng_base) || xisnan (rng_inc)) + && (double) NINT (rng_base) == rng_base + && (double) NINT (rng_inc) == rng_inc); +} Matrix Range::matrix_value (void) const
--- a/liboctave/Range.h +++ b/liboctave/Range.h @@ -56,6 +56,8 @@ double inc (void) const { return rng_inc; } int nelem (void) const { return rng_nelem; } + bool all_elements_are_ints (void) const; + Matrix matrix_value (void) const; double min (void) const; @@ -67,7 +69,6 @@ void set_limit (double l) { rng_limit = l; } void set_inc (double i) { rng_inc = i; } - friend ostream& operator << (ostream& os, const Range& r); friend istream& operator >> (istream& is, Range& r);