# HG changeset patch # User Mike Miller # Date 1378675685 14400 # Node ID 4bcd301754cefc2c3c22394ee08a851b2b03d8b7 # Parent dbdff94bf9777ec588fadba4fd340dc7ce15538c Add Matlab-compatible flintmax function * bitfcns.cc (Fflintmax): New function based on bitmax. (Fbitmax, Fintmax, Fintmin): Update seealso to refer to flintmax. * numbers.txi: Include flintmax docstring. diff -r dbdff94bf977 -r 4bcd301754ce doc/interpreter/numbers.txi --- a/doc/interpreter/numbers.txi Sun Sep 08 12:16:44 2013 -0400 +++ b/doc/interpreter/numbers.txi Sun Sep 08 17:28:05 2013 -0400 @@ -546,6 +546,8 @@ @DOCSTRING(intmin) +@DOCSTRING(flintmax) + @menu * Integer Arithmetic:: @end menu @@ -614,7 +616,6 @@ for bit manipulation, particularly when forming masks, Octave supplies the function @code{bitmax}. -@anchor{XREFflintmax} @DOCSTRING(bitmax) This is the double precision version of the function @code{intmax}, diff -r dbdff94bf977 -r 4bcd301754ce libinterp/corefcn/bitfcns.cc --- a/libinterp/corefcn/bitfcns.cc Sun Sep 08 12:16:44 2013 -0400 +++ b/libinterp/corefcn/bitfcns.cc Sun Sep 08 17:28:05 2013 -0400 @@ -575,16 +575,12 @@ @deftypefn {Built-in Function} {} bitmax ()\n\ @deftypefnx {Built-in Function} {} bitmax (\"double\")\n\ @deftypefnx {Built-in Function} {} bitmax (\"single\")\n\ -@deftypefnx {Built-in Function} {} flintmax (@dots{})\n\ Return the largest integer that can be represented within a floating point\n\ value. The default class is @qcode{\"double\"}, but @qcode{\"single\"} is a\n\ valid option. On IEEE-754 compatible systems, @code{bitmax} is\n\ @w{@math{2^{53} - 1}} for @qcode{\"double\"} and @w{@math{2^{24} -1}} for\n\ @qcode{\"single\"}.\n\ -\n\ -@code{flintmax} for FLoating point INTeger MAXimum is an alias for\n\ -@code{bitmax}.\n\ -@seealso{intmax, realmax, realmin}\n\ +@seealso{flintmax, intmax, realmax, realmin}\n\ @end deftypefn") { octave_value retval; @@ -609,7 +605,39 @@ return retval; } -DEFALIAS(flintmax, bitmax) +DEFUN (flintmax, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} flintmax ()\n\ +@deftypefnx {Built-in Function} {} flintmax (\"double\")\n\ +@deftypefnx {Built-in Function} {} flintmax (\"single\")\n\ +Return the largest integer that can be represented consecutively in a\n\ +floating point value. The default class is @qcode{\"double\"}, but @qcode{\"single\"}\n\ +is a valid option. On IEEE-754 compatible systems, @code{flintmax} is @w{@math{2^53}}\n\ +for @qcode{\"double\"} and @w{@math{2^24}} for @qcode{\"single\"}.\n\ +@seealso{bitmax, intmax, realmax, realmin}\n\ +@end deftypefn") +{ + octave_value retval; + 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 (max_mantissa_value () + 1)); + else if (cname == "single") + retval = (static_cast (max_mantissa_value () + 1)); + else + error ("flintmax: not defined for class '%s'", cname.c_str ()); + + return retval; +} DEFUN (intmax, args, , "-*- texinfo -*-\n\ @@ -644,7 +672,7 @@ @end table\n\ \n\ The default for @var{type} is @code{uint32}.\n\ -@seealso{intmin, bitmax}\n\ +@seealso{intmin, flintmax, bitmax}\n\ @end deftypefn") { octave_value retval; @@ -714,7 +742,7 @@ @end table\n\ \n\ The default for @var{type} is @code{uint32}.\n\ -@seealso{intmax, bitmax}\n\ +@seealso{intmax, flintmax, bitmax}\n\ @end deftypefn") { octave_value retval;