0 Members and 1 Guest are viewing this topic.

const epsilon = 1e-6; // accuracy, number of decimal places (ie 1e-6 -> 6 decimal places accuracy)function Power(Base: double; Exponent: integer): double;var i: integer;begin Result:=1; if Exponent = 0 then exit; for i:=1 to round(Abs(Exponent)) do Result:=Result*Base; if Exponent < 0 then Result:=1/Result;end;function Root(Base: double; Exponent: integer): double;var r: double; neg_exp: boolean;begin if Base < 0 then if Exponent mod 2 = 0 then exit; if Exponent < 0 then begin neg_exp:=true; Exponent:=-Exponent; end; Result:=1; repeat r:=Result; Result:=(Result*(Exponent-1)+Base/Power(Result,Exponent-1))/Exponent; until Abs(r-Result) < epsilon; if neg_exp then Result:=1/Result;end;function Cbrt(Base: double): double;var r: double;begin Result:=1; repeat r:=Result; Result:=(Result*2+Base/(Result*Result))/3; until Abs(r-Result) < epsilon;end;

const e = 2.71828182846; // value of e, don't touch epsilon = 1e-6; // accuracy, number of decimal places (ie 1e-6 -> 6 decimal places accuracy)function Exp(X: double): double;var m, n: integer; r, fac, pow: double;begin m:=Round(Abs(X/10)); if m >= 2 then X:=X/m; Result:=1+X; fac:=1; pow:=X; n:=2; r:=1; while r>epsilon do begin fac:=fac*n; pow:=pow*X; n:=n+1; r:=pow/fac; Result:=Result+r; end; if m >= 2 then begin pow:=Result; for n:=2 to m do Result:=Result*pow; end;end;function Ln(X: double): double;begin Result:=LogN(e,X);end;function Log(X: double): double;begin Result:=LogN(10,X);end;function Power(Base: double; Exponent: double): double;begin Result:=Exp(LogN(e, Base)*Exponent);end;function Root(Base: double; Exponent: double): double;begin Result:=Exp(LogN(e, Base)/Exponent);end;

Logarithmic and Exponential functions:

Since now.

What is more, Logn is not on any list with scriptcore functions.

Hey tk, what's your next script? Where will you use these functions? =)

Can't you guys just load an unit to SC3? http://www.freepascal.org/docs-html/rtl/math/index-5.html