lib: add Int::** for power
authorJean Privat <jean@pryen.org>
Sat, 8 Nov 2014 01:34:43 +0000 (20:34 -0500)
committerJean Privat <jean@pryen.org>
Sat, 8 Nov 2014 03:58:09 +0000 (22:58 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/math.nit

index a2e0966..f6f5397 100644 (file)
@@ -83,6 +83,14 @@ redef class Int
        #
        #    assert not 13.is_even
        fun is_odd: Bool do return not is_even
+
+       # Returns the `self` raised to the power of `e`.
+       #
+       #    assert 2 ** 3 == 8
+       fun **(e: Int): Int
+       do
+               return self.to_f.pow(e.to_f).to_i
+       end
 end
 
 redef class Float