RosettaCodeData/Task/Exponentiation-operator/Seed7/exponentiation-operator-1.seed7
2023-07-01 13:44:08 -04:00

22 lines
527 B
Text

const func integer: intPow (in var integer: base, in var integer: exponent) is func
result
var integer: result is 0;
begin
if exponent < 0 then
raise(NUMERIC_ERROR);
else
if odd(exponent) then
result := base;
else
result := 1;
end if;
exponent := exponent div 2;
while exponent <> 0 do
base *:= base;
if odd(exponent) then
result *:= base;
end if;
exponent := exponent div 2;
end while;
end if;
end func;