annotate scripts/miscellaneous/mustBeInteger.m @ 27962:3b8d21ff0ca6

New validator functions implementation (bug #57627). - NEWS: Announce new functions. - scripts/help/__unimplemented__.m: Remove new functions from list. - scripts/micellaneous/module.mk: Add new functions to build system. - scripts/micellaneous/mustBe*.m: Add validator function.
author Andrew Janke <andrew@apjanke.net>
date Sun, 19 Jan 2020 10:07:30 +0900
parents
children c9dd91b438fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27962
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
1 ########################################################################
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
2 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
3 ## Copyright (C) 2019-2020 The Octave Project Developers
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
4 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
7 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
8 ## This file is part of Octave.
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
9 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
13 ## (at your option) any later version.
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
14 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
18 ## GNU General Public License for more details.
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
19 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
22 ## <https://www.gnu.org/licenses/>.
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
23 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
24 ########################################################################
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
25
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
26 ## -*- texinfo -*-
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
27 ## @deftypefn {} {@var{x} =} mustBeInteger (@var{x})
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
28 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
29 ## Requires that input @var{x} is integer-valued (but not necessarily
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
30 ## integer-typed).
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
31 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
32 ## Raises an error if any element of the input @var{x} is not a finite,
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
33 ## real, integer-valued numeric value, as determined by various checks.
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
34 ##
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
35 ## @end deftypefn
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
36
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
37 function x = mustBeInteger (x)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
38 if isinteger (x) || islogical (x)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
39 return
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
40 endif
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
41 but = [];
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
42 if ! isnumeric (x)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
43 but = sprintf ("it was non-numeric (got a %s)", class (x));
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
44 elseif any (! isfinite (x))
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
45 but = "there were Inf values";
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
46 elseif ! isreal (x)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
47 but = "it was complex";
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
48 elseif ! all (floor (x) == x)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
49 but = "it had fractional values in some elements";
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
50 end
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
51 if ! isempty (but)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
52 label = inputname (1);
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
53 if isempty (label)
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
54 label = "input";
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
55 endif
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
56 error ("%s must be integer-valued; but %s", label, but);
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
57 endif
3b8d21ff0ca6 New validator functions implementation (bug #57627).
Andrew Janke <andrew@apjanke.net>
parents:
diff changeset
58 endfunction