Add even/odd Octave functions.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 14 Sep 2012 23:44:26 +0000 (19:44 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 14 Sep 2012 23:44:26 +0000 (19:44 -0400)
even.m [new file with mode: 0644]
odd.m [new file with mode: 0644]

diff --git a/even.m b/even.m
new file mode 100644 (file)
index 0000000..f4f3767
--- /dev/null
+++ b/even.m
@@ -0,0 +1,14 @@
+function even = even(integer_n)
+  ## Returns true if its argument is even; false otherwise.
+  ##
+  ## INPUTS:
+  ##
+  ##   * ``integer_n`` - The integer whose parity you're determining.
+  ##
+  ##
+  ## OUTPUTS:
+  ##
+  ##   * ``even`` - True if `integer_n` is even, false otherwise.
+  ##
+  even = rem(integer_n, 2) == 0;
+end
diff --git a/odd.m b/odd.m
new file mode 100644 (file)
index 0000000..b0bc626
--- /dev/null
+++ b/odd.m
@@ -0,0 +1,15 @@
+function odd = odd(integer_n)
+  ## Returns true if its argument is odd; false otherwise.
+  ##
+  ## INPUTS:
+  ##
+  ##   * ``integer_n`` - The integer whose parity you're determining.
+  ##
+  ##
+  ## OUTPUTS:
+  ##
+  ##   * ``odd`` - True if `integer_n` is odd, false otherwise.
+  ##
+  
+  odd = !even(integer_n);
+end