* math.power/intpower(0,0) return 1, this is as recommended in IEEE 754

as well as compatible with other programming languages and delphi

git-svn-id: trunk@14873 -
This commit is contained in:
florian 2010-02-06 23:10:03 +00:00
parent 879e487ee8
commit 0c153a46df
3 changed files with 29 additions and 18 deletions

1
.gitattributes vendored
View File

@ -9398,6 +9398,7 @@ tests/test/units/math/tmask.inc svneol=native#text/plain
tests/test/units/math/tmask.pp svneol=native#text/plain
tests/test/units/math/tmask2.pp svneol=native#text/plain
tests/test/units/math/tnaninf.pp svneol=native#text/plain
tests/test/units/math/tpower.pp svneol=native#text/pascal
tests/test/units/math/ttrig1.pp svneol=native#text/plain
tests/test/units/objects/testobj.pp svneol=native#text/plain
tests/test/units/objects/testobj1.pp svneol=native#text/plain

View File

@ -102,7 +102,7 @@ interface
tpaymenttime = (ptendofperiod,ptstartofperiod);
einvalidargument = class(ematherror);
EInvalidArgument = class(ematherror);
TValueRelationship = -1..1;
@ -875,10 +875,7 @@ function power(base,exponent : float) : float;
begin
if Exponent=0.0 then
if base <> 0.0 then
result:=1.0
else
InvalidArgument
result:=1.0
else if (base=0.0) and (exponent>0.0) then
result:=0.0
else if (abs(exponent)<=maxint) and (frac(exponent)=0.0) then
@ -896,21 +893,24 @@ function intpower(base : float;const exponent : Integer) : float;
begin
if (base = 0.0) and (exponent = 0) then
InvalidArgument;
i:=abs(exponent);
intpower:=1.0;
while i>0 do
result:=1
else
begin
while (i and 1)=0 do
begin
i:=i shr 1;
base:=sqr(base);
end;
i:=i-1;
intpower:=intpower*base;
i:=abs(exponent);
intpower:=1.0;
while i>0 do
begin
while (i and 1)=0 do
begin
i:=i shr 1;
base:=sqr(base);
end;
i:=i-1;
intpower:=intpower*base;
end;
if exponent<0 then
intpower:=1.0/intpower;
end;
if exponent<0 then
intpower:=1.0/intpower;
end;

View File

@ -0,0 +1,10 @@
uses
math;
begin
if power(0,0)<>1 then
halt(1);
if intpower(0,0)<>1 then
halt(1);
writeln('ok');
end.