i already got it working… dan cardin's way helped me out, it wasn't what i asked, but his way was the solution.
but now i got another prob:PXD
its al working… but at some point it sometimes does a exponential of 100 or bigger:P(i think)
and then il get the error: floating point overflow
how to solve this?
this is my pow function:
function Power2(Base, Exponent : Double) : Double;
{ raises the base to the exponent }
CONST
cTiny = 1e-15;
VAR
Power : Double; { Value before sign correction }
BEGIN
Power := 0;
{ Deal with the near zero special cases }
IF (Abs(Base) < cTiny) THEN BEGIN
Base := 0.0;
END; { IF }
IF (Abs(Exponent) < cTiny) THEN BEGIN
Exponent := 0.0;
END; { IF }
{ Deal with the exactly zero cases }
IF (Base = 0.0) THEN BEGIN
Power := 0.0;
END; { IF }
IF (Exponent = 0.0) THEN BEGIN
Power := 1.0;
END; { IF }
{ Cover everything else }
IF ((Base < 0) AND (Exponent < 0)) THEN
Power := 1/Exp(-Exponent*Ln(-Base))
ELSE IF ((Base < 0) AND (Exponent >= 0)) THEN
Power := Exp(Exponent*Ln(-Base))
ELSE IF ((Base > 0) AND (Exponent < 0)) THEN
Power := 1/Exp(-Exponent*Ln(Base))
ELSE IF ((Base > 0) AND (Exponent >= 0)) THEN
Power := Exp(Exponent*Ln(Base));
{ Correct the sign }
IF ((Base < 0) AND (Frac(Exponent/2.0) <> 0.0)) THEN
Result := -Power
ELSE
Result := Power;
END; { FUNCTION Pow }
pow function i don't use anymore:
Function Pow(Base, Exponent: double): double;
Begin
//ShowMessage(inttostr(base)+'ss'+inttostr(Exponent));
if Exponent = 0 then
result := 1
else
if(Exponent > 0) then
begin
result := Base * Pow(Base, Exponent - 1);
end;
if(Exponent < 0) then
begin
result := Base * Pow(Base, Exponent + 1);
end;
End;
//edit
nobody knows the answer?
i searched on google, but then i find something about math.pow or system.math.pow.. these don't exsist at my delphi 6..:(
so i had to add a source of pow.. but it just isn't fail safe.
so my question is, does anyone know a fail safe pow source or the function of delphi to do it..