Mercurial > hg > octave-nkf
changeset 15487:ecf5be238b4a
provide signbit mapper for real values
* mappers.cc (Fsignbit): New function and tests.
* ov-base.cc (octave_base_value::get_umap_name): Include signbit in
the list.
* ov-base.h (octave_base_value::unary_mapper_t): Include umap_xsignbit
in the list.
* ov-float.cc (octave_float_scalar::map): Handle xsignbit.
* ov-scalar.cc (octave_scalar::map): Handle xsignbit.
* ov-re-mat.cc (octave_matrix::map): Handle xsignbit.
* ov-flt-re-mat.cc (octave_float_matrix::map): Handle xsignbit.
* lo-mappers.h (xsignbit): New template function.
* arith.txi: Document signbit.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 04 Oct 2012 09:48:07 -0400 |
parents | afc002de3ade |
children | 481417a57a2d |
files | doc/interpreter/arith.txi libinterp/corefcn/mappers.cc libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-base.h libinterp/octave-value/ov-float.cc libinterp/octave-value/ov-flt-re-mat.cc libinterp/octave-value/ov-re-mat.cc libinterp/octave-value/ov-scalar.cc libinterp/octave-value/ov.h liboctave/numeric/lo-mappers.h |
diffstat | 10 files changed, 50 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/arith.txi +++ b/doc/interpreter/arith.txi @@ -262,6 +262,8 @@ @DOCSTRING(sign) +@DOCSTRING(signbit) + @node Special Functions @section Special Functions
--- a/libinterp/corefcn/mappers.cc +++ b/libinterp/corefcn/mappers.cc @@ -1780,6 +1780,40 @@ %!error sign (1, 2) */ +DEFUNX ("signbit", Fsignbit, args, , + "-*- texinfo -*-\n\ +@deftypefn {Mapping Function} {} signbit (@var{x})\n\ +Return a nonzero value if the value of @var{x} has its sign bit set.\n\ +\n\ +This is not the same as @code{x < 0.0}, because IEEE 754 floating point\n\ +allows zero to be signed. The comparison @code{-0.0 < 0.0} is false,\n\ +but @code{signbit (-0.0)} will return a nonzero value.\n\ +@end deftypefn") +{ + octave_value retval; + if (args.length () == 1) + retval = args(0).xsignbit (); + else + print_usage (); + + return retval; +} + +/* +%!assert (signbit (1) == 0) +%!assert (signbit (-2) != 0) +%!assert (signbit (0) == 0) +%!assert (signbit (-0) != 0) + +%!assert (signbit (single (1)) == 0) +%!assert (signbit (single (-2)) != 0) +%!assert (signbit (single (0)) == 0) +%!assert (signbit (single (-0)) != 0) + +%!error sign () +%!error sign (1, 2) +*/ + DEFUN (sin, args, , "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} sin (@var{x})\n\
--- a/libinterp/octave-value/ov-base.cc +++ b/libinterp/octave-value/ov-base.cc @@ -1229,6 +1229,7 @@ "isspace", "isupper", "isxdigit", + "signbit", "toascii", "tolower", "toupper"
--- a/libinterp/octave-value/ov-base.h +++ b/libinterp/octave-value/ov-base.h @@ -725,6 +725,7 @@ umap_xisspace, umap_xisupper, umap_xisxdigit, + umap_xsignbit, umap_xtoascii, umap_xtolower, umap_xtoupper,
--- a/libinterp/octave-value/ov-float.cc +++ b/libinterp/octave-value/ov-float.cc @@ -321,6 +321,7 @@ SCALAR_MAPPER (isinf, xisinf); SCALAR_MAPPER (isna, octave_is_NA); SCALAR_MAPPER (isnan, xisnan); + SCALAR_MAPPER (xsignbit, xsignbit); default: return octave_base_value::map (umap);
--- a/libinterp/octave-value/ov-flt-re-mat.cc +++ b/libinterp/octave-value/ov-flt-re-mat.cc @@ -806,6 +806,7 @@ ARRAY_MAPPER (tan, float, ::tanf); ARRAY_MAPPER (tanh, float, ::tanhf); ARRAY_MAPPER (isna, bool, octave_is_NA); + ARRAY_MAPPER (xsignbit, float, xsignbit); default: return octave_base_value::map (umap);
--- a/libinterp/octave-value/ov-re-mat.cc +++ b/libinterp/octave-value/ov-re-mat.cc @@ -929,6 +929,7 @@ ARRAY_MAPPER (tan, double, ::tan); ARRAY_MAPPER (tanh, double, ::tanh); ARRAY_MAPPER (isna, bool, octave_is_NA); + ARRAY_MAPPER (xsignbit, double, xsignbit); default: if (umap >= umap_xisalnum && umap <= umap_xtoupper)
--- a/libinterp/octave-value/ov-scalar.cc +++ b/libinterp/octave-value/ov-scalar.cc @@ -337,6 +337,7 @@ SCALAR_MAPPER (isinf, xisinf); SCALAR_MAPPER (isna, octave_is_NA); SCALAR_MAPPER (isnan, xisnan); + SCALAR_MAPPER (xsignbit, xsignbit); default: if (umap >= umap_xisalnum && umap <= umap_xtoupper)