Mercurial > hg > octave-lojdl
changeset 1968:a2e206524aa0
[project @ 1996-02-17 02:54:24 by jwe]
author | jwe |
---|---|
date | Sat, 17 Feb 1996 02:57:16 +0000 |
parents | 4cb6aaa0f2c7 |
children | 6c14daf92033 |
files | liboctave/CMatrix.cc liboctave/Makefile.in liboctave/dMatrix.cc liboctave/mach-info.h src/help.cc src/input.cc src/load-save.cc src/mappers.h src/oct-hist.cc src/oct-obj.cc src/oct-obj.h src/pr-output.cc src/pt-plot.cc src/utils.cc src/variables.cc |
diffstat | 15 files changed, 260 insertions(+), 206 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -41,6 +41,7 @@ #include "CmplxSVD.h" #include "f77-fcn.h" #include "lo-error.h" +#include "lo-utils.h" #include "mx-base.h" #include "mx-inlines.cc" #include "oct-cmplx.h" @@ -2821,6 +2822,85 @@ elem (i, j) = f (elem (i, j)); } +// Return nonzero if any element of CM has a non-integer real or +// imaginary part. Also extract the largest and smallest (real or +// imaginary) values and return them in MAX_VAL and MIN_VAL. + +int +ComplexMatrix::all_integers (double& max_val, double& min_val) const +{ + int nr = rows (); + int nc = columns (); + + if (nr > 0 && nc > 0) + { + Complex val = elem (0, 0); + + double r_val = real (val); + double i_val = imag (val); + + max_val = r_val; + min_val = r_val; + + if (i_val > max_val) + max_val = i_val; + + if (i_val < max_val) + min_val = i_val; + } + else + return 0; + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + Complex val = elem (i, j); + + double r_val = real (val); + double i_val = imag (val); + + if (r_val > max_val) + max_val = r_val; + + if (i_val > max_val) + max_val = i_val; + + if (r_val < min_val) + min_val = r_val; + + if (i_val < min_val) + min_val = i_val; + + if (D_NINT (r_val) != r_val || D_NINT (i_val) != i_val) + return 0; + } + return 1; +} + +int +ComplexMatrix::too_large_for_float (void) const +{ + int nr = rows (); + int nc = columns (); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + Complex val = elem (i, j); + + double r_val = real (val); + double i_val = imag (val); + + if (r_val > FLT_MAX + || i_val > FLT_MAX + || r_val < FLT_MIN + || i_val < FLT_MIN) + return 1; + } + + return 0; +} + Matrix ComplexMatrix::all (void) const {
--- a/liboctave/Makefile.in +++ b/liboctave/Makefile.in @@ -36,10 +36,11 @@ LinConst.h LP.h LPsolve.h LSODE.h NLConst.h NLEqn.h NLFunc.h \ NLP.h NPSOL.h ODE.h ODEFunc.h Objective.h QP.h QPSOL.h Quad.h \ Range.h base-de.h base-min.h byte-swap.h cmd-hist.h data-conv.h \ - dir-ops.h file-ops.h float-fmt.h f77-fcn.h getopt.h idx-vector.h \ - lo-error.h oct-cmplx.h oct-glob.h oct-math.h oct-term.h \ - pathsearch.h prog-args.h statdefs.h str-vec.h sun-utils.h \ - sysdir.h $(MATRIX_INC) + dir-ops.h file-ops.h float-fmt.h f77-fcn.h getopt.h \ + idx-vector.h lo-error.h lo-ieee.h lo-mappers.h lo-utils.h \ + oct-cmplx.h oct-glob.h oct-math.h oct-term.h pathsearch.h \ + prog-args.h statdefs.h str-vec.h sun-utils.h sysdir.h \ + $(MATRIX_INC) TEMPLATE_SRC := Array.cc MArray.cc @@ -60,9 +61,9 @@ Quad.cc Range.cc acosh.c asinh.c atanh.c cmd-hist.cc \ data-conv.cc dir-ops.cc erf.c erfc.c f77-fcn.c file-ops.cc \ filemode.c float-fmt.cc gamma.c getopt.c getopt1.c \ - idx-vector.cc lgamma.c mkdir.c oct-glob.cc oct-term.cc \ - pathsearch.cc prog-args.cc rename.c rmdir.c str-vec.cc \ - sun-utils.cc tempname.c tempnam.c \ + idx-vector.cc lgamma.c lo-ieee.cc lo-mappers.cc lo-utils.cc \ + mkdir.c oct-glob.cc oct-term.cc pathsearch.cc prog-args.cc \ + rename.c rmdir.c str-vec.cc sun-utils.cc tempname.c tempnam.c \ $(TEMPLATE_SRC) \ $(TI_SRC) \ $(MATRIX_SRC)
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -43,6 +43,7 @@ #include "dbleSVD.h" #include "f77-fcn.h" #include "lo-error.h" +#include "lo-utils.h" #include "mx-base.h" #include "mx-inlines.cc" #include "oct-cmplx.h" @@ -1831,6 +1832,58 @@ d[i] = f (d[i]); } +// Return nonzero if any element of M is not an integer. Also extract +// the largest and smallest values and return them in MAX_VAL and MIN_VAL. + +int +Matrix::all_integers (double& max_val, double& min_val) const +{ + int nr = rows (); + int nc = cols (); + + if (nr > 0 && nc > 0) + { + max_val = elem (0, 0); + min_val = elem (0, 0); + } + else + return 0; + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + double val = elem (i, j); + + if (val > max_val) + max_val = val; + + if (val < min_val) + min_val = val; + + if (D_NINT (val) != val) + return 0; + } + return 1; +} + +int +Matrix::too_large_for_float (void) const +{ + int nr = rows (); + int nc = columns (); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + double val = elem (i, j); + + if (val > FLT_MAX || val < FLT_MIN) + return 1; + } + + return 0; +} + // XXX FIXME XXX Do these really belong here? They should maybe be // cleaned up a bit, no? What about corresponding functions for the // Vectors?
--- a/liboctave/mach-info.h +++ b/liboctave/mach-info.h @@ -49,4 +49,3 @@ ;;; page-delimiter: "^/\\*" *** ;;; End: *** */ -
--- a/src/help.cc +++ b/src/help.cc @@ -682,7 +682,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "help"); + string_vector argv = args.make_argv ("help"); if (error_state) return retval; @@ -720,7 +720,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "type"); + string_vector argv = args.make_argv ("type"); if (error_state) return retval; @@ -862,7 +862,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "which"); + string_vector argv = args.make_argv ("which"); if (error_state) return retval;
--- a/src/input.cc +++ b/src/input.cc @@ -1137,7 +1137,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "echo"); + string_vector argv = args.make_argv ("echo"); if (error_state) return retval;
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -1380,7 +1380,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "load"); + string_vector argv = args.make_argv ("load"); if (error_state) return retval; @@ -2187,7 +2187,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "save"); + string_vector argv = args.make_argv ("save"); if (error_state) return retval;
--- a/src/mappers.h +++ b/src/mappers.h @@ -26,6 +26,7 @@ #include <string> +#include "lo-mappers.h" #include "oct-cmplx.h" typedef double (*d_d_Mapper)(double); @@ -70,36 +71,6 @@ string help_string; }; -extern double arg (double x); -extern double conj (double x); -extern double fix (double x); -extern double imag (double x); -extern double real (double x); -extern double round (double x); -extern double signum (double x); -extern double xisnan (double x); -extern double xfinite (double x); -extern double xisinf (double x); - -extern double xisnan (const Complex& x); -extern double xfinite (const Complex& x); -extern double xisinf (const Complex& x); - -extern Complex acos (const Complex& x); -extern Complex acosh (const Complex& x); -extern Complex asin (const Complex& x); -extern Complex asinh (const Complex& x); -extern Complex atan (const Complex& x); -extern Complex atanh (const Complex& x); -extern Complex ceil (const Complex& x); -extern Complex fix (const Complex& x); -extern Complex floor (const Complex& x); -extern Complex log10 (const Complex& x); -extern Complex round (const Complex& x); -extern Complex signum (const Complex& x); -extern Complex tan (const Complex& x); -extern Complex tanh (const Complex& x); - extern void install_mapper_functions (void); #endif
--- a/src/oct-hist.cc +++ b/src/oct-hist.cc @@ -523,7 +523,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "edit_history"); + string_vector argv = args.make_argv ("edit_history"); if (error_state) return retval; @@ -542,7 +542,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "history"); + string_vector argv = args.make_argv ("history"); if (error_state) return retval; @@ -561,7 +561,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "run_history"); + string_vector argv = args.make_argv ("run_history"); if (error_state) return retval;
--- a/src/oct-obj.cc +++ b/src/oct-obj.cc @@ -29,86 +29,39 @@ #include <config.h> #endif +#include "error.h" #include "oct-obj.h" -// XXX FIXME XXX -- these can probably go in oct-obj.h now. - -Octave_object::Octave_object (double d) - : Array<tree_constant> (1, tree_constant (d)) { } - -Octave_object::Octave_object (const Matrix& m) - : Array<tree_constant> (1, tree_constant (m)) { } - -Octave_object::Octave_object (const DiagMatrix& d) - : Array<tree_constant> (1, tree_constant (d)) { } - -Octave_object::Octave_object (const RowVector& v, int pcv) - : Array<tree_constant> (1, tree_constant (v, pcv)) { } - -Octave_object::Octave_object (const ColumnVector& v, int pcv) - : Array<tree_constant> (1, tree_constant (v, pcv)) { } - -Octave_object::Octave_object (const Complex& c) - : Array<tree_constant> (1, tree_constant (c)) { } - -Octave_object::Octave_object (const ComplexMatrix& m) - : Array<tree_constant> (1, tree_constant (m)) { } - -Octave_object::Octave_object (const ComplexDiagMatrix& d) - : Array<tree_constant> (1, tree_constant (d)) { } +int +Octave_object::all_strings (void) const +{ + int n = length (); -Octave_object::Octave_object (const ComplexRowVector& v, int pcv) - : Array<tree_constant> (1, tree_constant (v, pcv)) { } - -Octave_object::Octave_object (const ComplexColumnVector& v, int pcv) - : Array<tree_constant> (1, tree_constant (v, pcv)) { } - -Octave_object::Octave_object (const char *s) - : Array<tree_constant> (1, tree_constant (s)) { } - -Octave_object::Octave_object (const string& s) - : Array<tree_constant> (1, tree_constant (s)) { } + for (int i = 0; i < n; i++) + if (! elem(i).is_string ()) + return 0; -Octave_object::Octave_object (const string_vector& s) - : Array<tree_constant> (1, tree_constant (s)) { } - -Octave_object::Octave_object (double base, double limit, double inc) - : Array<tree_constant> (1, tree_constant (base, limit, inc)) { } - -Octave_object::Octave_object (const Range& r) - : Array<tree_constant> (1, tree_constant (r)) { } - -tree_constant& -Octave_object::operator () (int n) -{ - maybe_resize (n); - return Array<tree_constant>::operator () (n); + return 1; } -tree_constant -Octave_object::operator () (int n) const -{ - return Array<tree_constant>::operator () (n); -} - -tree_constant& -Octave_object::elem (int n) +string_vector +Octave_object::make_argv (const string& fcn_name) const { - maybe_resize (n); - return Array<tree_constant>::elem (n); -} + string_vector argv; + + if (all_strings ()) + { + int n = length (); + argv.resize (n+1); + argv[0] = fcn_name; -tree_constant -Octave_object::elem (int n) const -{ - return Array<tree_constant>::operator () (n); -} + for (int i = 0; i < n; i++) + argv[i+1] = elem(i).string_value (); + } + else + error ("%s: expecting all arguments to be strings", fcn_name.c_str ()); -void -Octave_object::maybe_resize (int n) -{ - if (n >= length ()) - resize (n + 1, Matrix ()); + return argv; } /*
--- a/src/oct-obj.h +++ b/src/oct-obj.h @@ -28,7 +28,10 @@ #pragma interface #endif +#include <string> + #include "Array.h" +#include "str-vec.h" // Including this is all we need because pt-const.h gives us // declarations for all the data types Octave knows about. @@ -40,44 +43,80 @@ { public: - Octave_object (void) : Array<tree_constant> () { } + Octave_object (void) + : Array<tree_constant> () { } + Octave_object (int n, const tree_constant& val) : Array<tree_constant> (n, val) { } - Octave_object (const tree_constant& tc) : Array<tree_constant> (1, tc) { } + Octave_object (const tree_constant& tc) + : Array<tree_constant> (1, tc) { } + + Octave_object (double d) + : Array<tree_constant> (1, tree_constant (d)) { } + + Octave_object (const Matrix& m) + : Array<tree_constant> (1, tree_constant (m)) { } + + Octave_object (const DiagMatrix& d) + : Array<tree_constant> (1, tree_constant (d)) { } - Octave_object (double d); - Octave_object (const Matrix& m); - Octave_object (const DiagMatrix& d); - Octave_object (const RowVector& v, int pcv = -1); - Octave_object (const ColumnVector& v, int pcv = -1); + Octave_object (const RowVector& v, int pcv) + : Array<tree_constant> (1, tree_constant (v, pcv)) { } + + Octave_object (const ColumnVector& v, int pcv) + : Array<tree_constant> (1, tree_constant (v, pcv)) { } + + Octave_object (const Complex& c) + : Array<tree_constant> (1, tree_constant (c)) { } + + Octave_object (const ComplexMatrix& m) + : Array<tree_constant> (1, tree_constant (m)) { } - Octave_object (const Complex& c); - Octave_object (const ComplexMatrix& m); - Octave_object (const ComplexDiagMatrix& d); - Octave_object (const ComplexRowVector& v, int pcv = -1); - Octave_object (const ComplexColumnVector& v, int pcv = -1); + Octave_object (const ComplexDiagMatrix& d) + : Array<tree_constant> (1, tree_constant (d)) { } + + Octave_object (const ComplexRowVector& v, int pcv) + : Array<tree_constant> (1, tree_constant (v, pcv)) { } + + Octave_object (const ComplexColumnVector& v, int pcv) + : Array<tree_constant> (1, tree_constant (v, pcv)) { } + + Octave_object (const char *s) + : Array<tree_constant> (1, tree_constant (s)) { } - Octave_object (const char *s); - Octave_object (const string& s); - Octave_object (const string_vector& s); + Octave_object (const string& s) + : Array<tree_constant> (1, tree_constant (s)) { } + + Octave_object (const string_vector& s) + : Array<tree_constant> (1, tree_constant (s)) { } - Octave_object (double base, double limit, double inc); - Octave_object (const Range& r); + Octave_object (double base, double limit, double inc) + : Array<tree_constant> (1, tree_constant (base, limit, inc)) { } - Octave_object (const Octave_object& obj) : Array<tree_constant> (obj) { } + Octave_object (const Range& r) + : Array<tree_constant> (1, tree_constant (r)) { } + + Octave_object (const Octave_object& obj) + : Array<tree_constant> (obj) { } Octave_object& operator = (const Octave_object& obj) { - Array<tree_constant>::operator = (obj); + if (this != &obj) + Array<tree_constant>::operator = (obj); + return *this; } // Assignment will resize on range errors. - tree_constant& operator () (int n); + tree_constant& operator () (int n) { return elem (n); } + + tree_constant operator () (int n) const { return elem (n); } - tree_constant operator () (int n) const; + int all_strings (void) const; + + string_vector make_argv (const string&) const; private: @@ -96,14 +135,27 @@ Octave_object (int n); - void maybe_resize (int n); + void maybe_resize (int n) + { + if (n >= length ()) + resize (n + 1, Matrix ()); + } - tree_constant& elem (int n); + tree_constant& elem (int n) + { + maybe_resize (n); + return Array<tree_constant>::elem (n); + } + tree_constant& checkelem (int n); tree_constant& xelem (int n); - tree_constant elem (int n) const; + tree_constant elem (int n) const + { + return Array<tree_constant>::operator () (n); + } + tree_constant checkelem (int n) const; };
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -1715,7 +1715,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "format"); + string_vector argv = args.make_argv ("format"); if (error_state) return retval;
--- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -1033,7 +1033,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "hold"); + string_vector argv = args.make_argv ("hold"); if (error_state) return retval; @@ -1086,7 +1086,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "set"); + string_vector argv = args.make_argv ("set"); if (error_state) return retval; @@ -1132,7 +1132,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "show"); + string_vector argv = args.make_argv ("show"); if (error_state) return retval;
--- a/src/utils.cc +++ b/src/utils.cc @@ -296,61 +296,6 @@ return retval; } -// Convert X to the nearest integer value. Should not pass NaN to -// this function. - -int -NINT (double x) -{ - if (x > INT_MAX) - return INT_MAX; - else if (x < INT_MIN) - return INT_MIN; - else - return (x > 0) ? ((int) (x + 0.5)) : ((int) (x - 0.5)); -} - -double -D_NINT (double x) -{ - if (xisinf (x) || xisnan (x)) - return x; - else - return floor (x + 0.5); -} - -// XXX FIXME XXX -- put these in some file, and make them extern. - -static int -all_strings (const Octave_object& args) -{ - int n = args.length (); - for (int i = 0; i < n; i++) - if (! args(i).is_string ()) - return 0; - return 1; -} - -string_vector -make_argv (const Octave_object& args, const string& fcn_name) -{ - string_vector argv; - - if (all_strings (args)) - { - int n = args.length (); - argv.resize (n+1); - argv[0] = fcn_name; - - for (int i = 0; i < n; i++) - argv[i+1] = args(i).string_value (); - } - else - error ("%s: expecting all arguments to be strings", fcn_name.c_str ()); - - return argv; -} - // Return non-zero if either NR or NC is zero. Return -1 if this // should be considered fatal; return 1 if this is ok. @@ -397,7 +342,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "file_in_path"); + string_vector argv = args.make_argv ("file_in_path"); if (error_state) return retval;
--- a/src/variables.cc +++ b/src/variables.cc @@ -1199,7 +1199,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "document"); + string_vector argv = args.make_argv ("document"); if (error_state) return retval; @@ -1342,7 +1342,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "who"); + string_vector argv = args.make_argv ("who"); if (error_state) return retval; @@ -1369,7 +1369,7 @@ int argc = tmp_args.length () + 1; - string_vector argv = make_argv (tmp_args, "whos"); + string_vector argv = args.make_argv ("whos"); if (error_state) return retval; @@ -1857,7 +1857,7 @@ int argc = args.length () + 1; - string_vector argv = make_argv (args, "clear"); + string_vector argv = args.make_argv ("clear"); if (error_state) return retval;