RosettaCodeData/Task/Metaprogramming/Nim/metaprogramming-1.nim

12 lines
212 B
Nim
Raw Permalink Normal View History

2018-06-22 20:57:24 +00:00
proc `^`*[T: SomeInteger](base, exp: T): T =
2016-12-05 23:44:36 +01:00
var (base, exp) = (base, exp)
result = 1
while exp != 0:
if (exp and 1) != 0:
result *= base
exp = exp shr 1
base *= base
echo 2 ^ 10 # 1024