From bc6acf9a05d6e6acc6c1d0c802e783fbc45b3bb1 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 14 Sep 2012 19:44:26 -0400 Subject: [PATCH] Add even/odd Octave functions. --- even.m | 14 ++++++++++++++ odd.m | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 even.m create mode 100644 odd.m diff --git a/even.m b/even.m new file mode 100644 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 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 -- 2.44.2