# HG changeset patch # User jwe # Date 845142775 0 # Node ID 09652906683810a66c702920daf52fe1423e17f3 # Parent 58e5955495d7b0dc473e9a50a1602c2c4d132d6b [project @ 1996-10-12 17:50:47 by jwe] diff --git a/liboctave/MArray.cc b/liboctave/MArray.cc --- 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 \ MArray \ FCN (const MArray& a, const MArray& 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 (); \ } \ if (l == 0) \ @@ -139,10 +139,10 @@ return MArray (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. diff --git a/liboctave/MArray2.cc b/liboctave/MArray2.cc --- 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 \ MArray2 \ FCN (const MArray2& a, const MArray2& 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 (); \ } \ if (r == 0 || c == 0) \ @@ -153,10 +152,10 @@ return MArray2 (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. diff --git a/liboctave/MDiagArray2.cc b/liboctave/MDiagArray2.cc --- 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 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 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 \ MDiagArray2 \ FCN (const MDiagArray2& a, const MDiagArray2& 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 (); \ } \ if (c == 0 || r == 0) \ @@ -125,9 +132,9 @@ return MDiagArray2 (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. diff --git a/liboctave/Range.cc b/liboctave/Range.cc --- 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 diff --git a/liboctave/Range.h b/liboctave/Range.h --- 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);