Mercurial > hg > octave-terminal
changeset 10897:dbec9d590756
Add CLASS argument to bitmax
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 17 Aug 2010 17:43:37 -0700 |
parents | f7c3364947dd |
children | 4a2dabfb078b |
files | src/ChangeLog src/bitfcns.cc |
diffstat | 2 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-08-17 Rik <octave@nomad.inbox5.com> + + * bitfcns.cc (bitmax): Add additional calling argument, class, and + additional return value for bitmax("single"). + 2010-08-17 Rik <octave@nomad.inbox5.com> * bitfcns.cc (sizemax): Improve documentation string.
--- a/src/bitfcns.cc +++ b/src/bitfcns.cc @@ -514,16 +514,33 @@ DEFUN (bitmax, args, , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} bitmax ()\n\ -Return the largest integer that can be represented as a floating point\n\ -value. On IEEE-754 compatible systems, @code{bitmax} is @code{2^53 - 1}.\n\ +@deftypefn {Built-in Function} {} bitmax ()\n\ +@deftypefnx {Built-in Function} {} bitmax (\"double\")\n\ +@deftypefnx {Built-in Function} {} bitmax (\"single\")\n\ +Return the largest integer that can be represented within a floating point\n\ +value. The default class is \"double\", but \"single\" is a valid option. \n\ +On IEEE-754 compatible systems, @code{bitmax} is @w{@math{2^{53} - 1}}.\n\ @end deftypefn") { octave_value retval; - if (args.length () != 0) - print_usage (); + std::string cname = "double"; + int nargin = args.length (); + + if (nargin == 1 && args(0).is_string ()) + cname = args(0).string_value (); + else if (nargin != 0) + { + print_usage (); + return retval; + } + + if (cname == "double") + retval = (static_cast<double> (0x1FFFFFFFFFFFFFLL)); + else if (cname == "single") + retval = (static_cast<double> (0xFFFFFFL)); else - retval = (static_cast<double> (0x1FFFFFFFFFFFFFLL)); + error ("bitmax: not defined for class '%s'", cname.c_str ()); + return retval; }