langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,22 @@
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;

View file

@ -0,0 +1,44 @@
const func float: fltIPow (in var float: base, in var integer: exponent) is func
result
var float: result is 0.0;
local
var boolean: neg_exp is FALSE;
begin
if base = 0.0 then
if exponent < 0 then
result := Infinity;
elsif exponent = 0 then
result := 1.0;
else
result := 0.0;
end if;
else
if exponent < 0 then
exponent := -exponent;
neg_exp := TRUE;
end if;
# In the twos complement representation the most
# negative number is the only one where both the
# number and its negation are negative. When the
# exponent is proven to be to the most negative
# number fltIPow returns 0.0 .
if exponent >= 0 then
if odd(exponent) then
result := base;
else
result := 1.0;
end if;
exponent >>:= 1;
while exponent <> 0 do
base *:= base;
if odd(exponent) then
result *:= base;
end if;
exponent >>:= 1;
end while;
if neg_exp then
result := 1.0 / result;
end if;
end if;
end if;
end func;

View file

@ -0,0 +1,7 @@
$ syntax expr: .(). ^* .() is <- 4;
const func integer: (in var integer: base) ^* (in var integer: exponent) is
return intPow(base, exponent);
const func float: (in var float: base) ^* (in var integer: exponent) is
return fltIPow(base, exponent);