Mercurial > hg > octave-terminal
changeset 4100:ed0090ecf80f
[project @ 2002-10-11 16:37:45 by jwe]
author | jwe |
---|---|
date | Fri, 11 Oct 2002 16:37:45 +0000 |
parents | 3add04256a60 |
children | ea537559ab07 |
files | src/ChangeLog src/defun-int.h src/defun.h src/mappers.cc src/mkbuiltins src/mkgendoc src/octave.cc src/ov-mapper.cc src/ov-mapper.h src/ov-re-mat.cc src/ov-scalar.cc |
diffstat | 11 files changed, 153 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,29 @@ +2002-10-11 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov-re-mat.cc (octave_matrix::convert_to_str): Warn for out of + range conversions. For negative values, set to 0. + * ov-scalar.cc (octave_scalar:convert_to_str): Likewise. + + * mappers.cc (xabs): New static function. + (install_mapper_functions): Use it for abs for character matrices. + Handle ch_map_flag separately from can_ret_cmplx_for_real in + all uses of DEFUN_MAPPER. + * defun.h (DEFUN_MAPPER): Handle ch_map_flag separately from + can_ret_cmplx_for_real. + * defun-int.h (DEFUN_MAPPER_INTERNAL): Likewise. + * mkbuiltins: Likewise. + * mkgendoc: Likewise. + * ov-mapper.cc (octave_mapper::apply): Use ch_map_flag and + can_ret_cmplx_for_real instead of flag. + * ov-mapper.h (octave_mapper::ch_map_flag): Rename from flag. + (octave_mapper::can_ret_cmplx_for_real): New data member. + (octave_mapper::octave_mapper): Handle it here. + 2002-10-10 John W. Eaton <jwe@bevo.che.wisc.edu> + * octave.cc (execute_startup_files): Don't forget directory + separator for local initfile. + * move-if-change: Delete. * Makefile.in (DISTFILES): Delete it from the list.
--- a/src/defun-int.h +++ b/src/defun-int.h @@ -146,11 +146,11 @@ #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ d_c_map, c_c_map, lo, hi, \ - can_ret_cmplx_for_real, doc) \ + ch_map_flag, can_ret_cmplx_for_real, doc) \ BEGIN_INSTALL_BUILTIN \ XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ d_c_map, c_c_map, lo, hi, \ - can_ret_cmplx_for_real, doc) \ + ch_map_flag, can_ret_cmplx_for_real, doc) \ END_INSTALL_BUILTIN #else /* ! MAKE_BUILTINS */ @@ -193,7 +193,7 @@ #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ d_c_map, c_c_map, lo, hi, \ - can_ret_cmplx_for_real, doc) \ + ch_map_flag, can_ret_cmplx_for_real, doc) \ install_builtin_mapper \ (new octave_mapper \ (X_CAST (octave_mapper::ch_mapper, ch_map), \ @@ -202,7 +202,7 @@ X_CAST (octave_mapper::d_d_mapper, d_d_map), \ X_CAST (octave_mapper::d_c_mapper, d_c_map), \ X_CAST (octave_mapper::c_c_mapper, c_c_map), \ - lo, hi, can_ret_cmplx_for_real, #name)) + lo, hi, ch_map_flag, can_ret_cmplx_for_real, #name)) #endif /* ! MAKE_BUILTINS */
--- a/src/defun.h +++ b/src/defun.h @@ -126,16 +126,24 @@ // hi is the upper bound of the range for which real arguments can // become complex. (e.g., hi == 0 for sqrt). // +// ch_map_flag has the following meanings for the ch_map function: +// +// 0 => this function returns a matrix of ones and zeros +// 1 => this function returns a numeric matrix (any values) +// 2 => this function returns a std::string array +// // can_ret_cmplx_for_real is a flag that says whether this function // can create a complex number given a real-valued argument // (e.g., sqrt (-1)). // // doc is the simple help text for the function. -#define DEFUN_MAPPER(name, ch_map, d_b_map, c_b_map, d_d_map, d_c_map, \ - c_c_map, lo, hi, can_ret_cmplx_for_real, doc) \ - DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, d_c_map, \ - c_c_map, lo, hi, can_ret_cmplx_for_real, doc) +#define DEFUN_MAPPER(name, ch_map, d_b_map, c_b_map, d_d_map, \ + d_c_map, c_c_map, lo, hi, ch_map_flag, \ + can_ret_cmplx_for_real, doc) \ + DEFUN_MAPPER_INTERNAL (name, ch_map, d_b_map, c_b_map, d_d_map, \ + d_c_map, c_c_map, lo, hi, ch_map_flag, \ + can_ret_cmplx_for_real, doc) // Make alias another name for the existing function name. This macro // must be used in the same file where name is defined, after the
--- a/src/mappers.cc +++ b/src/mappers.cc @@ -39,6 +39,12 @@ // whether the is* functions are actually functions or just macros. static int +xabs (int c) +{ + return static_cast<unsigned char> (c); +} + +static int xisalnum (int c) { return isalnum (c); @@ -113,7 +119,7 @@ static int xtoascii (int c) { - return toascii (c); + return toascii ((int) ((unsigned char) c)); } static int @@ -155,7 +161,7 @@ void install_mapper_functions (void) { - DEFUN_MAPPER (abs, 0, 0, 0, std::fabs, abs, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (abs, xabs, 0, 0, std::fabs, abs, 0, 0.0, 0.0, 1, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} abs (@var{z})\n\ Compute the magnitude of @var{z}, defined as\n\ @@ -178,25 +184,25 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (acos, 0, 0, 0, std::acos, 0, acos, -1.0, 1.0, 1, + DEFUN_MAPPER (acos, 0, 0, 0, std::acos, 0, acos, -1.0, 1.0, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} acos (@var{x})\n\ Compute the inverse cosine of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (acosh, 0, 0, 0, acosh, 0, acosh, 1.0, DBL_MAX, 1, + DEFUN_MAPPER (acosh, 0, 0, 0, acosh, 0, acosh, 1.0, DBL_MAX, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} acosh (@var{x})\n\ Compute the inverse hyperbolic cosine of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (angle, 0, 0, 0, arg, arg, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (angle, 0, 0, 0, arg, arg, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} angle (@var{z})\n\ See arg.\n\ @end deftypefn"); - DEFUN_MAPPER (arg, 0, 0, 0, arg, arg, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (arg, 0, 0, 0, arg, arg, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} arg (@var{z})\n\ @deftypefnx {Mapping Function} {} angle (@var{z})\n\ @@ -223,38 +229,38 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (asin, 0, 0, 0, std::asin, 0, asin, -1.0, 1.0, 1, + DEFUN_MAPPER (asin, 0, 0, 0, std::asin, 0, asin, -1.0, 1.0, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} asin (@var{x})\n\ Compute the inverse sine of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (asinh, 0, 0, 0, asinh, 0, asinh, 0.0, 0.0, 0, + DEFUN_MAPPER (asinh, 0, 0, 0, asinh, 0, asinh, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} asinh (@var{x})\n\ Ompute the inverse hyperbolic sine of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (atan, 0, 0, 0, std::atan, 0, atan, 0.0, 0.0, 0, + DEFUN_MAPPER (atan, 0, 0, 0, std::atan, 0, atan, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} atan (@var{x})\n\ Compute the inverse tangent of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (atanh, 0, 0, 0, atanh, 0, atanh, -1.0, 1.0, 1, + DEFUN_MAPPER (atanh, 0, 0, 0, atanh, 0, atanh, -1.0, 1.0, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} atanh (@var{x})\n\ Compute the inverse hyperbolic tanget of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (ceil, 0, 0, 0, std::ceil, 0, ceil, 0.0, 0.0, 0, + DEFUN_MAPPER (ceil, 0, 0, 0, std::ceil, 0, ceil, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} ceil (@var{x})\n\ Return the smallest integer not less than @var{x}. If @var{x} is\n\ complex, return @code{ceil (real (@var{x})) + ceil (imag (@var{x})) * I}.\n\ @end deftypefn"); - DEFUN_MAPPER (conj, 0, 0, 0, xconj, 0, xconj, 0.0, 0.0, 0, + DEFUN_MAPPER (conj, 0, 0, 0, xconj, 0, xconj, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} conj (@var{z})\n\ Return the complex conjugate of @var{z}, defined as\n\ @@ -269,19 +275,19 @@ @end deftypefn\n\ @seealso{real and imag}"); - DEFUN_MAPPER (cos, 0, 0, 0, std::cos, 0, cos, 0.0, 0.0, 0, + DEFUN_MAPPER (cos, 0, 0, 0, std::cos, 0, cos, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} cos (@var{x})\n\ Compute the cosine of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (cosh, 0, 0, 0, std::cosh, 0, cosh, 0.0, 0.0, 0, + DEFUN_MAPPER (cosh, 0, 0, 0, std::cosh, 0, cosh, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} cosh (@var{x})\n\ Compute the hyperbolic cosine of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (erf, 0, 0, 0, erf, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (erf, 0, 0, 0, erf, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} erf (@var{z})\n\ Computes the error function,\n\ @@ -305,7 +311,7 @@ @end deftypefn\n\ @seealso{erfc and erfinv}"); - DEFUN_MAPPER (erfc, 0, 0, 0, erfc, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (erfc, 0, 0, 0, erfc, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} erfc (@var{z})\n\ Computes the complementary error function,\n\ @@ -321,14 +327,14 @@ \n\ @seealso{erf and erfinv}"); - DEFUN_MAPPER (exp, 0, 0, 0, std::exp, 0, exp, 0.0, 0.0, 0, + DEFUN_MAPPER (exp, 0, 0, 0, std::exp, 0, exp, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} exp (@var{x})\n\ Compute the exponential of @var{x}. To compute the matrix exponential,\n\ see @ref{Linear Algebra}.\n\ @end deftypefn"); - DEFUN_MAPPER (finite, 0, xfinite, xfinite, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (finite, 0, xfinite, xfinite, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} finite (@var{x})\n\ Return 1 for elements of @var{x} that are finite values and zero\n\ @@ -342,21 +348,21 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (fix, 0, 0, 0, fix, 0, fix, 0.0, 0.0, 0, + DEFUN_MAPPER (fix, 0, 0, 0, fix, 0, fix, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} fix (@var{x})\n\ Truncate @var{x} toward zero. If @var{x} is complex, return\n\ @code{fix (real (@var{x})) + fix (imag (@var{x})) * I}.\n\ @end deftypefn"); - DEFUN_MAPPER (floor, 0, 0, 0, std::floor, 0, floor, 0.0, 0.0, 0, + DEFUN_MAPPER (floor, 0, 0, 0, std::floor, 0, floor, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} floor (@var{x})\n\ Return the largest integer not greater than @var{x}. If @var{x} is\n\ complex, return @code{floor (real (@var{x})) + floor (imag (@var{x})) * I}.\n\ @end deftypefn"); - DEFUN_MAPPER (gamma, 0, 0, 0, xgamma, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (gamma, 0, 0, 0, xgamma, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} gamma (@var{z})\n\ Computes the Gamma function,\n\ @@ -381,7 +387,7 @@ \n\ @seealso{gammai and lgamma}"); - DEFUN_MAPPER (imag, 0, 0, 0, imag, ximag, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (imag, 0, 0, 0, imag, ximag, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} imag (@var{z})\n\ Return the imaginary part of @var{z} as a real number.\n\ @@ -389,39 +395,39 @@ \n\ @seealso{real and conj}"); - DEFUN_MAPPER (isalnum, xisalnum, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isalnum, xisalnum, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isalnum (@var{s})\n\ Return 1 for characters that are letters or digits (@code{isalpha\n\ (@var{a})} or @code{isdigit (@var{a})} is true).\n\ @end deftypefn"); - DEFUN_MAPPER (isalpha, xisalpha, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isalpha, xisalpha, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isalpha (@var{s})\n\ Return true for characters that are letters (@code{isupper (@var{a})}\n\ or @code{islower (@var{})} is true).\n\ @end deftypefn"); - DEFUN_MAPPER (isascii, xisascii, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isascii, xisascii, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isascii (@var{s})\n\ Return 1 for characters that are ASCII (in the range 0 to 127 decimal).\n\ @end deftypefn"); - DEFUN_MAPPER (iscntrl, xiscntrl, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (iscntrl, xiscntrl, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} iscntrl (@var{s})\n\ Return 1 for control characters.\n\ @end deftypefn"); - DEFUN_MAPPER (isdigit, xisdigit, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isdigit, xisdigit, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isdigit (@var{s})\n\ Return 1 for characters that are decimal digits.\n\ @end deftypefn"); - DEFUN_MAPPER (isinf, 0, xisinf, xisinf, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isinf, 0, xisinf, xisinf, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isinf (@var{x})\n\ Return 1 for elements of @var{x} that are infinite and zero\n\ @@ -435,19 +441,19 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (isgraph, xisgraph, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isgraph, xisgraph, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isgraph (@var{s})\n\ Return 1 for printable characters (but not the space character).\n\ @end deftypefn"); - DEFUN_MAPPER (islower, xislower, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (islower, xislower, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} islower (@var{s})\n\ Return 1 for characters that are lower case letters.\n\ @end deftypefn"); - DEFUN_MAPPER (isna, 0, octave_is_NA, octave_is_NA, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isna, 0, octave_is_NA, octave_is_NA, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isna (@var{x})\n\ Return 1 for elements of @var{x} that are NA (missing) values and zero\n\ @@ -462,7 +468,7 @@ @end deftypefn"); DEFUN_MAPPER (is_nan_or_na, 0, octave_is_NaN_or_NA, - octave_is_NaN_or_NA, 0, 0, 0, 0.0, 0.0, 0, + octave_is_NaN_or_NA, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} is_nan_or_na (@var{x})\n\ Return 1 for elements of @var{x} that are NaN or NA (missing) values\n\ @@ -476,7 +482,7 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (isnan, 0, xisnan, xisnan, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isnan, 0, xisnan, xisnan, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isnan (@var{x})\n\ Return 1 for elements of @var{x} that are NaN values and zero\n\ @@ -490,38 +496,38 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (isprint, xisprint, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isprint, xisprint, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isprint (@var{s})\n\ Return 1 for printable characters (including the space character).\n\ @end deftypefn"); - DEFUN_MAPPER (ispunct, xispunct, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (ispunct, xispunct, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} ispunct (@var{s})\n\ Return 1 for punctuation characters.\n\ @end deftypefn"); - DEFUN_MAPPER (isspace, xisspace, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isspace, xisspace, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isspace (@var{s})\n\ Return 1 for whitespace characters (space, formfeed, newline,\n\ carriage return, tab, and vertical tab).\n\ @end deftypefn"); - DEFUN_MAPPER (isupper, xisupper, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isupper, xisupper, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isupper (@var{s})\n\ Return 1 for upper case letters.\n\ @end deftypefn"); - DEFUN_MAPPER (isxdigit, xisxdigit, 0, 0, 0, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (isxdigit, xisxdigit, 0, 0, 0, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} isxdigit (@var{s})\n\ Return 1 for characters that are hexadecimal digits.\n\ @end deftypefn"); - DEFUN_MAPPER (lgamma, 0, 0, 0, xlgamma, 0, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (lgamma, 0, 0, 0, xlgamma, 0, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} lgamma (@var{a}, @var{x})\n\ @deftypefnx {Mapping Function} {} gammaln (@var{a}, @var{x})\n\ @@ -529,7 +535,7 @@ @end deftypefn\n\ @seealso{gamma and gammai}"); - DEFUN_MAPPER (log, 0, 0, 0, std::log, 0, log, 0.0, DBL_MAX, 1, + DEFUN_MAPPER (log, 0, 0, 0, std::log, 0, log, 0.0, DBL_MAX, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} log (@var{x})\n\ Compute the natural logarithm for each element of @var{x}. To compute the\n\ @@ -537,21 +543,21 @@ @end deftypefn\n\ @seealso{log2, log10, logspace, and exp}"); - DEFUN_MAPPER (log10, 0, 0, 0, std::log10, 0, log10, 0.0, DBL_MAX, 1, + DEFUN_MAPPER (log10, 0, 0, 0, std::log10, 0, log10, 0.0, DBL_MAX, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} log10 (@var{x})\n\ Compute the base-10 logarithm for each element of @var{x}.\n\ @end deftypefn\n\ @seealso{log, log2, logspace, and exp}"); - DEFUN_MAPPER (real, 0, 0, 0, real, xreal, 0, 0.0, 0.0, 0, + DEFUN_MAPPER (real, 0, 0, 0, real, xreal, 0, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} real (@var{z})\n\ Return the real part of @var{z}.\n\ @end deftypefn\n\ @seealso{imag and conj}"); - DEFUN_MAPPER (round, 0, 0, 0, round, 0, round, 0.0, 0.0, 0, + DEFUN_MAPPER (round, 0, 0, 0, round, 0, round, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} round (@var{x})\n\ Return the integer nearest to @var{x}. If @var{x} is complex, return\n\ @@ -559,7 +565,7 @@ @end deftypefn\n\ @seealso{rem}"); - DEFUN_MAPPER (sign, 0, 0, 0, signum, 0, signum, 0.0, 0.0, 0, + DEFUN_MAPPER (sign, 0, 0, 0, signum, 0, signum, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} sign (@var{x})\n\ Compute the @dfn{signum} function, which is defined as\n\ @@ -582,19 +588,19 @@ For complex arguments, @code{sign} returns @code{x ./ abs (@var{x})}.\n\ @end deftypefn"); - DEFUN_MAPPER (sin, 0, 0, 0, std::sin, 0, sin, 0.0, 0.0, 0, + DEFUN_MAPPER (sin, 0, 0, 0, std::sin, 0, sin, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} sin (@var{x})\n\ Compute the sin of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (sinh, 0, 0, 0, std::sinh, 0, sinh, 0.0, 0.0, 0, + DEFUN_MAPPER (sinh, 0, 0, 0, std::sinh, 0, sinh, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} sinh (@var{x})\n\ Compute the inverse hyperbolic sin of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (sqrt, 0, 0, 0, std::sqrt, 0, sqrt, 0.0, DBL_MAX, 1, + DEFUN_MAPPER (sqrt, 0, 0, 0, std::sqrt, 0, sqrt, 0.0, DBL_MAX, 0, 1, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} sqrt (@var{x})\n\ Compute the square root of @var{x}. If @var{x} is negative, a complex\n\ @@ -602,19 +608,19 @@ @ref{Linear Algebra}.\n\ @end deftypefn"); - DEFUN_MAPPER (tan, 0, 0, 0, std::tan, 0, tan, 0.0, 0.0, 0, + DEFUN_MAPPER (tan, 0, 0, 0, std::tan, 0, tan, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} tan (@var{z})\n\ Compute tanget of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (tanh, 0, 0, 0, std::tanh, 0, tanh, 0.0, 0.0, 0, + DEFUN_MAPPER (tanh, 0, 0, 0, std::tanh, 0, tanh, 0.0, 0.0, 0, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} tanh (@var{x})\n\ Compute hyperbolic tangent of each element of @var{x}.\n\ @end deftypefn"); - DEFUN_MAPPER (toascii, xtoascii, 0, 0, 0, 0, 0, 0.0, 0.0, 1, + DEFUN_MAPPER (toascii, xtoascii, 0, 0, 0, 0, 0, 0.0, 0.0, 1, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} toascii (@var{s})\n\ Return ASCII representation of @var{s} in a matrix. For example,\n\ @@ -628,7 +634,7 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (tolower, xtolower, 0, 0, 0, 0, 0, 0.0, 0.0, 2, + DEFUN_MAPPER (tolower, xtolower, 0, 0, 0, 0, 0, 0.0, 0.0, 2, 0, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} tolower (@var{s})\n\ Return a copy of the string @var{s}, with each upper-case character\n\ @@ -641,7 +647,7 @@ @end example\n\ @end deftypefn"); - DEFUN_MAPPER (toupper, xtoupper, 0, 0, 0, 0, 0, 0.0, 0.0, 2, + DEFUN_MAPPER (toupper, xtoupper, 0, 0, 0, 0, 0, 0.0, 0.0, 2, 0, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} toupper (@var{s})\n\ Return a copy of the string @var{s}, with each lower-case character\n\
--- a/src/mkbuiltins +++ b/src/mkbuiltins @@ -58,7 +58,7 @@ #define XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ d_c_map, c_c_map, lo, hi, \ - can_ret_cmplx_for_real, doc) + ch_map_flag, can_ret_cmplx_for_real, doc) EOF
--- a/src/mkgendoc +++ b/src/mkgendoc @@ -38,7 +38,7 @@ #define XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ d_c_map, c_c_map, lo, hi, \ - can_ret_cmplx_for_real, doc) \ + ch_map_flag, can_ret_cmplx_for_real, doc) \ print_doc_string (#name, doc); static void
--- a/src/octave.cc +++ b/src/octave.cc @@ -243,7 +243,8 @@ std::string home_dir = octave_env::get_home_directory (); std::string home_rc = home_dir + OCTAVE_DIR_SEP_STR + initfile; - std::string local_rc = octave_env::getcwd () + initfile; + std::string local_rc + = octave_env::getcwd () + OCTAVE_DIR_SEP_STR + initfile; if (! home_dir.empty ()) {
--- a/src/ov-mapper.cc +++ b/src/ov-mapper.cc @@ -117,7 +117,7 @@ if (! error_state) { - switch (flag) + switch (ch_map_flag) { case 0: MAPPER_LOOP_1 (boolMatrix, ch_map_fcn, chm, bool); @@ -147,7 +147,7 @@ { double d = arg.double_value (); - if (flag && (d < lower_limit || d > upper_limit)) + if (can_ret_cmplx_for_real && (d < lower_limit || d > upper_limit)) { if (c_c_map_fcn) retval = c_c_map_fcn (Complex (d)); @@ -170,7 +170,7 @@ if (error_state) return retval; - if (flag + if (can_ret_cmplx_for_real && (any_element_less_than (m, lower_limit) || any_element_greater_than (m, upper_limit))) {
--- a/src/ov-mapper.h +++ b/src/ov-mapper.h @@ -52,13 +52,15 @@ octave_mapper (ch_mapper ch, d_b_mapper db, c_b_mapper cb, d_d_mapper dd, d_c_mapper dc, - c_c_mapper cc, double ll, double ul, int f, + c_c_mapper cc, double ll, double ul, + int cmf, bool crcfr, const std::string& nm = std::string (), const std::string& ds = std::string ()) : octave_function (nm, ds), ch_map_fcn (ch), d_b_map_fcn (db), c_b_map_fcn (cb), d_d_map_fcn (dd), d_c_map_fcn (dc), c_c_map_fcn (cc), - lower_limit (ll), upper_limit (ul), flag (f) { } + lower_limit (ll), upper_limit (ul), ch_map_flag (cmf), + can_ret_cmplx_for_real (crcfr) { } ~octave_mapper (void) { } @@ -96,16 +98,19 @@ double lower_limit; double upper_limit; - // For ch_map_fcn, flag has the following meanings: + // ch_map_flag has the following meanings: // // 0 => this function returns a matrix of ones and zeros // 1 => this function returns a numeric matrix (any values) // 2 => this function returns a std::string array - // - // For other mappers, nonzero means that this function can return a - // complex value for some real arguments. + + int ch_map_flag; - int flag; + // can_ret_cmplx_for_real is a flag that says whether this function + // can create a complex number given a real-valued argument + // (e.g., sqrt (-1)). + + bool can_ret_cmplx_for_real; DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <climits> + #include <iostream> #include "lo-ieee.h" @@ -46,6 +48,10 @@ #include "pr-output.h" #include "variables.h" +#if ! defined (UCHAR_MAX) +#define UCHAR_MAX 255 +#endif + template class octave_base_matrix<Matrix>; DEFINE_OCTAVE_ALLOCATOR (octave_matrix); @@ -125,6 +131,8 @@ else { charMatrix chm (nr, nc); + + bool warned = false; for (int j = 0; j < nc; j++) { @@ -139,11 +147,23 @@ } else { - // XXX FIXME XXX -- warn about out of range - // conversions? + int ival = NINT (d); + + if (ival < 0 || ival > UCHAR_MAX) + { + // XXX FIXME XXX -- is there something + // better we could do? + + ival = 0; - int ival = NINT (d); - chm (i, j) = (char) ival; + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; + } + } + + chm (i, j) = static_cast<char> (ival); } } }
--- a/src/ov-scalar.cc +++ b/src/ov-scalar.cc @@ -85,9 +85,18 @@ ::error ("invalid conversion from NaN to character"); else { - // XXX FIXME XXX -- warn about out of range conversions? - - retval = octave_value (std::string (1, char (NINT (scalar)))); + int ival = NINT (scalar); + + if (ival < 0 || ival > UCHAR_MAX) + { + // XXX FIXME XXX -- is there something better we could do? + + ival = 0; + + ::warning ("range error for conversion to character value"); + } + + retval = octave_value (std::string (1, static_cast<char> (ival))); } return retval;