Mercurial > hg > octave-lyh
changeset 330:fe6e790846f5
[project @ 1994-02-04 04:54:47 by jwe]
author | jwe |
---|---|
date | Fri, 04 Feb 1994 04:54:47 +0000 |
parents | a6be506559ec |
children | ee2dbf1eb16c |
files | src/builtins.cc src/builtins.h src/pt-const.cc src/variables.cc |
diffstat | 4 files changed, 69 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/builtins.cc +++ b/src/builtins.cc @@ -53,99 +53,99 @@ static builtin_mapper_functions mapper_functions[] = { - { "abs", 2, 1, 0, fabs, abs, NULL, + { "abs", 0, 0.0, 0.0, fabs, abs, NULL, "abs (X): compute abs (X) for each element of X", }, - { "acos", 2, 1, 0, acos, NULL, acos, + { "acos", 1, -1.0, 1.0, acos, NULL, acos, "acos (X): compute acos (X) for each element of X", }, - { "acosh", 2, 1, 0, acosh, NULL, acosh, + { "acosh", 1, 1.0, DBL_MAX, acosh, NULL, acosh, "acosh (X): compute acosh (X) for each element of X", }, - { "angle", 2, 1, 0, arg, arg, NULL, + { "angle", 0, 0.0, 0.0, arg, arg, NULL, "angle (X): compute arg (X) for each element of X", }, - { "arg", 2, 1, 0, arg, arg, NULL, + { "arg", 0, 0.0, 0.0, arg, arg, NULL, "arg (X): compute arg (X) for each element of X", }, - { "asin", 2, 1, 0, asin, NULL, asin, + { "asin", 1, -1.0, 1.0, asin, NULL, asin, "asin (X): compute asin (X) for each element of X", }, - { "asinh", 2, 1, 0, asinh, NULL, asinh, + { "asinh", 0, 0.0, 0.0, asinh, NULL, asinh, "asinh (X): compute asinh (X) for each element of X", }, - { "atan", 2, 1, 0, atan, NULL, atan, + { "atan", 0, 0.0, 0.0, atan, NULL, atan, "atan (X): compute atan (X) for each element of X", }, - { "atanh", 2, 1, 0, atanh, NULL, atanh, + { "atanh", 1, -1.0, 1.0, atanh, NULL, atanh, "atanh (X): compute atanh (X) for each element of X", }, - { "ceil", 2, 1, 0, ceil, NULL, ceil, + { "ceil", 0, 0.0, 0.0, ceil, NULL, ceil, "ceil (X): round elements of X toward +Inf", }, - { "conj", 2, 1, 0, conj, NULL, conj, + { "conj", 0, 0.0, 0.0, conj, NULL, conj, "conj (X): compute complex conjugate for each element of X", }, - { "cos", 2, 1, 0, cos, NULL, cos, + { "cos", 0, 0.0, 0.0, cos, NULL, cos, "cos (X): compute cos (X) for each element of X", }, - { "cosh", 2, 1, 0, cosh, NULL, cosh, + { "cosh", 0, 0.0, 0.0, cosh, NULL, cosh, "cosh (X): compute cosh (X) for each element of X", }, - { "exp", 2, 1, 0, exp, NULL, exp, + { "exp", 0, 0.0, 0.0, exp, NULL, exp, "exp (X): compute exp (X) for each element of X", }, - { "finite", 2, 1, 0, xfinite, xfinite, NULL, + { "finite", 0, 0.0, 0.0, xfinite, xfinite, NULL, "finite (X): return 1 for finite elements of X", }, - { "fix", 2, 1, 0, fix, NULL, fix, + { "fix", 0, 0.0, 0.0, fix, NULL, fix, "fix (X): round elements of X toward zero", }, - { "floor", 2, 1, 0, floor, NULL, floor, + { "floor", 0, 0.0, 0.0, floor, NULL, floor, "floor (X): round elements of X toward -Inf", }, - { "isinf", 2, 1, 0, xisinf, xisinf, NULL, + { "isinf", 0, 0.0, 0.0, xisinf, xisinf, NULL, "isinf (X): return 1 for elements of X infinite", }, - { "imag", 2, 1, 0, imag, imag, NULL, + { "imag", 0, 0.0, 0.0, imag, imag, NULL, "imag (X): return imaginary part for each elements of X", }, #ifdef HAVE_ISNAN - { "isnan", 2, 1, 0, xisnan, xisnan, NULL, + { "isnan", 0, 0.0, 0.0, xisnan, xisnan, NULL, "isnan (X): return 1 where elements of X are NaNs", }, #endif - { "log", 2, 1, 1, log, NULL, log, + { "log", 1, 0.0, DBL_MAX, log, NULL, log, "log (X): compute log (X) for each element of X", }, - { "log10", 2, 1, 1, log10, NULL, log10, + { "log10", 1, 0.0, DBL_MAX, log10, NULL, log10, "log10 (X): compute log10 (X) for each element of X", }, - { "real", 2, 1, 0, real, real, NULL, + { "real", 0, 0.0, 0.0, real, real, NULL, "real (X): return real part for each element of X", }, - { "round", 2, 1, 0, round, NULL, round, + { "round", 0, 0.0, 0.0, round, NULL, round, "round (X): round elements of X to nearest integer", }, - { "sign", 2, 1, 0, signum, NULL, signum, + { "sign", 0, 0.0, 0.0, signum, NULL, signum, "sign (X): apply signum function to elements of X", }, - { "sin", 2, 1, 0, sin, NULL, sin, + { "sin", 0, 0.0, 0.0, sin, NULL, sin, "sin (X): compute sin (X) for each element of X", }, - { "sinh", 2, 1, 0, sinh, NULL, sinh, + { "sinh", 0, 0.0, 0.0, sinh, NULL, sinh, "sinh (X): compute sinh (X) for each element of X", }, - { "sqrt", 2, 1, 1, sqrt, NULL, sqrt, + { "sqrt", 1, 0.0, DBL_MAX, sqrt, NULL, sqrt, "sqrt (X): compute sqrt (X) for each element of X", }, - { "tan", 2, 1, 0, tan, NULL, tan, + { "tan", 0, 0.0, 0.0, tan, NULL, tan, "tan (X): compute tan (X) for each element of X", }, - { "tanh", 2, 1, 0, tanh, NULL, tanh, + { "tanh", 0, 0.0, 0.0, tanh, NULL, tanh, "tanh (X): compute tanh (X) for each element of X", }, - { NULL, -1, -1, -1, NULL, NULL, NULL, NULL, }, + { NULL, -1, 0.0, 0.0, NULL, NULL, NULL, NULL, }, }; static builtin_text_functions text_functions[] =
--- a/src/builtins.h +++ b/src/builtins.h @@ -37,9 +37,19 @@ #endif +// If can_return_complex_for_real_arg is 1, lower_limit and +// upper_limit specify the range of values for which a real arg +// returns a real value. Outside that range, we have to convert args +// to complex, and call the complex valued function. +// +// If can_return_complex_for_real_arg is 0, lower_limit and +// upper_limit are ignored. + struct Mapper_fcn { - int neg_arg_complex; + int can_return_complex_for_real_arg; + double lower_limit; + double upper_limit; d_d_Mapper d_d_mapper; d_c_Mapper d_c_mapper; c_c_Mapper c_c_mapper; @@ -48,9 +58,9 @@ struct builtin_mapper_functions { char *name; - int nargin_max; - int nargout_max; - int neg_arg_complex; + int can_return_complex_for_real_arg; + double lower_limit; + double upper_limit; d_d_Mapper d_d_mapper; d_c_Mapper d_c_mapper; c_c_Mapper c_c_mapper;
--- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -45,13 +45,25 @@ // A couple of handy helper functions. static int -any_element_is_negative (const Matrix& a) +any_element_less_than (const Matrix& a, double val) { int nr = a.rows (); int nc = a.columns (); for (int j = 0; j < nc; j++) for (int i = 0; i < nr; i++) - if (a.elem (i, j) < 0.0) + if (a.elem (i, j) < val) + return 1; + return 0; +} + +static int +any_element_greater_than (const Matrix& a, double val) +{ + int nr = a.rows (); + int nc = a.columns (); + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + if (a.elem (i, j) > val) return 1; return 0; } @@ -2348,7 +2360,9 @@ switch (type_tag) { case scalar_constant: - if (m_fcn.neg_arg_complex && scalar < 0.0) + if (m_fcn.can_return_complex_for_real_arg + && (scalar < m_fcn.lower_limit + || scalar > m_fcn.upper_limit)) { if (m_fcn.c_c_mapper != NULL) { @@ -2370,7 +2384,9 @@ } break; case matrix_constant: - if (m_fcn.neg_arg_complex && any_element_is_negative (*matrix)) + if (m_fcn.can_return_complex_for_real_arg + && (any_element_less_than (*matrix, m_fcn.lower_limit) + || any_element_greater_than (*matrix, m_fcn.upper_limit))) { if (m_fcn.c_c_mapper != NULL) {
--- a/src/variables.cc +++ b/src/variables.cc @@ -126,14 +126,14 @@ sym_rec->unprotect (); Mapper_fcn mfcn; - mfcn.neg_arg_complex = mf->neg_arg_complex; + mfcn.can_return_complex_for_real_arg = mf->can_return_complex_for_real_arg; + mfcn.lower_limit = mf->lower_limit; + mfcn.upper_limit = mf->upper_limit; mfcn.d_d_mapper = mf->d_d_mapper; mfcn.d_c_mapper = mf->d_c_mapper; mfcn.c_c_mapper = mf->c_c_mapper; - tree_builtin *def = new tree_builtin (mf->nargin_max, - mf->nargout_max, mfcn, - mf->name); + tree_builtin *def = new tree_builtin (2, 1, mfcn, mf->name); sym_rec->define (def);