help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to test for "integer"?


From: Robert A. Macy
Subject: Re: How to test for "integer"?
Date: Sun, 15 May 2005 19:59:25 -0700

Luckily n is used in a for loop so there is no damage...

for i=1:n
  ;
endfor


However, I like the idea of testing to see if n >= 1

if ( floor(n-1)==abs(n-1) )
  message="n is a real positive integer"
else
  message="n must be a real positive integer at least 1"
endif


...that should be complete enough.


                - Robert -


On Sun, 15 May 2005 20:10:27 -0500 (CDT)
 Mike Miller <address@hidden> wrote:
> On Sun, 15 May 2005, Robert A. Macy wrote:
> 
> > if (floor(x)==abs(x))
> >  message="x is a positive real integer"
> > endif
> 
> If x is zero, it is not positive, but it is still
> non-negative.
> 
> 
> > What is the advantage of using a built-in function?
> > Does a built-in function make it faster?
> 
> Yes.
> 
> Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]