[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 14:38:20 -0700 |
Thought I just didn't see the test.
I've already checked the variable to see if it is complex.
I like your idea...
if (mod(abs(n),1)==0)
message="n is an integer"
endif
is my 2nd test, but...
if (floor(x)==abs(x))
message="x is a positive real integer"
endif
...does all 3 tests in a single line, thanks.
What is the advantage of using a built-in function?
Does a built-in function make it faster?
- Robert -
On Sun, 15 May 2005 13:39:03 -0700
Keith Goodman <address@hidden> wrote:
> I don't know of a built-in isint function.
>
> But you can make your own. I'd use floor(x)==x since
> floor is a
> built-in function but mod isn't. Plus it won't crash on
> complex
> numbers. Either way I don't think you need abs.
>
> On 5/15/05, Robert A. Macy <address@hidden> wrote:
> > Group,
> >
> > Is there a direct test for integer?
> >
> > I've been using
> >
> > if (abs(mod(n,1))==0)
> > msg="n is an integer"
> > endif
> >
> > which works great.
> >
> > I looked through the octave manual and didn't recognize
> an
> > "integer" test.
> >
> > - Robert -
> >
-------------------------------------------------------------
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
-------------------------------------------------------------