nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
52c0673
)
lib/standard/math: Added function is_even to Int
author
Lucas Bajolet
<r4pass@hotmail.com>
Mon, 22 Sep 2014 15:31:29 +0000
(11:31 -0400)
committer
Lucas 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
patch
|
blob
|
history
diff --git
a/lib/standard/math.nit
b/lib/standard/math.nit
index
7db6fa3
..
ba4db63
100644
(file)
--- a/
lib/standard/math.nit
+++ b/
lib/standard/math.nit
@@
-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