]> Creatis software - CreaPhase.git/blob - octave_packages/nnet-0.1.13/isposint.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nnet-0.1.13 / isposint.m
1 ## Copyright (C) 2005 Michel D. Schmid  <michaelschmid@users.sourceforge.net>
2 ##
3 ##
4 ## This program is free software; you can redistribute it and/or modify it
5 ## under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
7 ## any later version.
8 ##
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ## General Public License for more details.
13 ##
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; see the file COPYING.  If not, see
16 ## <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {} @var{f} = isposint(@var{n})
20 ## @code{isposint} returns true for positive integer values.
21 ## 
22 ## @example
23 ##   isposint(1)   # this returns TRUE
24 ##   isposint(0.5) # this returns FALSE
25 ##   isposint(0)   # this also return FALSE
26 ##   isposint(-1)  # this also returns FALSE
27 ## @end example
28 ##
29 ## 
30 ## @end deftypefn
31
32 ## Author: Michel D. Schmid 
33
34 function f = isposint(n)
35
36   ## check range of input arguments
37   error(nargchk(1,1,nargin))
38   
39   ## check input arg
40   if (length(n)>1)
41     error("Input argument must not be a vector, only scalars are allowed!")
42   endif
43
44   f = 1;
45   if ( (!isreal(n)) || (n<=0) || (round(n) != n) )
46     f = 0;
47   endif
48
49
50 endfunction
51
52 %!shared
53 %! disp("testing isposint")
54 %!assert(isposint(1)) # this should pass
55 %!assert(isposint(0.5),0) # should return zero
56 %!assert(isposint(-1),0) # should return zero
57 %!assert(isposint(-1.5),0) # should return zero
58 %!assert(isposint(0),0) # should return zero
59 %!fail("isposint([0 0])","Input argument must not be a vector, only scalars are allowed!")
60 %!fail("isposint('testString')","Input argument must not be a vector, only scalars are allowed!")
61