lib/standard/math: Added function is_even to Int
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 22 Sep 2014 15:31:29 +0000 (11:31 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 22 Sep 2014 20:16:11 +0000 (16:16 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/math.nit

index 7db6fa3..ba4db63 100644 (file)
@@ -51,6 +51,16 @@ redef class Int
                if self > o then return (self - o).rshift(1).gcd(o)
                return (o - self).rshift(1).gcd(self)
        end
+
+       # Is `self` even ?
+       #
+       #    assert 12.is_even
+       fun is_even: Bool do return self % 2 == 0
+
+       # Is `self` odd ?
+       #
+       #    assert not 13.is_even
+       fun is_odd: Bool do return not is_even
 end
 
 redef class Float