From: William P. Y. H <wil...@ya...> - 2005-11-07 17:27:12
|
--- Andy Adler <ad...@nc...> wrote: > > Are you happy with the way this function will handle large > exponents where the interger part is lost? For example > > octave:6> isinteger(1e10/3) > ans = 0 > octave:7> isinteger(1e20/3) > ans = 1 > > Andy > Well... I'm not. But I can't think of a better way... Btw, actually 1e20/3 should be treated as an integer anyway (or a floating point with zero behind the decimal point) because Octave can't handle it. I meant to use this function to check for integer count arguments passed to functions, and I think most people would do the same thing, so... In the meantime, I've modified it a bit (thanks Paul): function retval = isinteger(A) ## -*- texinfo -*- ## @deftypefn {Function File} {} isinteger (@var{A}) ## Return 1 if @var{A} is an integer array. Otherwise, return 0. ## @end deftypefn ## ## @seealso{isa, isnumeric, isfloat} if (nargin ~= 1) usage("isinteger(A)"); end retval = ismatrix(A) && all((round(A) == A)(:)); And now I also have an isfloat function: function retval = isfloat(A) ## -*- texinfo -*- ## @deftypefn {Function File} {} isfloat (@var{A}) ## Return 1 if @var{A} is a floating point array. Otherwise, return 0. ## @end deftypefn ## ## @seealso{isa, isinteger, isnumeric} if (nargin ~= 1) usage("isfloat(A)"); end retval = ismatrix(A) && ~all((round(A) == A)(:)); William Poetra Yoga Hadisoeseno __________________________________ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs |