您的位置:首页 > 编程语言 > Delphi

Delphi中的算术运算函数

2002-09-10 13:38 585 查看
Delphi中的算术运算函数
以下内容为编编程网站诸网友共同翻译的结果,如需转载,请注明出处:http://www.togetherdev.com,如果您对翻译Delphi的函数有兴趣,可登录编编程网站,如果对翻译的内容有什么看法,可以在回帖或在编编程网站中提出。
AbsCeilExpFloorfrac
FrexpintintpowerLdexpmax
minpipolypowerround
sqrttruncsqr
函数名ABS
简要介绍:Returnsanabsolutevalue.(取绝对值)
所属单元:System
定义:functionAbs(X);
详细解释:
Absreturnstheabsolutevalueoftheargument,X.
Xisaninteger-typeorreal-typeexpression.
(Abs函数用于返回变量X的绝对值,X可以是一个整形的变量或实数型的变量)
返回
函数名ceil
简要介绍:Roundsvariablesuptowardpositiveinfinity.
所属单元:Math
定义:functionCeil(X:Extended):Integer
详细解释:CallCeiltoobtainthelowestintegergreaterthanorequaltoX.TheabsolutevalueofXmustbelessthanMaxInt.Forexample:
Ceil(-2.8)=-2
Ceil(2.8)=3
Ceil(-1.0)=-1
(调用ceil函数,返回大于或等于x的最小整数值。X的绝对值一定要小于最大整数值。例如:
Ceil(-2.8)=-2

Ceil(2.8)=3

Ceil(-1.0)=-1)
返回
函数名Exp
简要介绍:ReturnstheexponentialofX.(Exp函数返回自然对数基底E的X次幂。)
所属单元:System
定义:functionExp(X:Real):Real;
详细解释:ExpreturnsthevalueoferaisedtothepowerofX,whereeisthebaseofthenaturallogarithms.
(Exp返回e的X次幂的值,其中e是一个自然对数基底。)
范例:
var
e:real;
S:string;
begin
e:=Exp(1.0);
Str(ln(e):3:2,S);
S:='e='+FloatToStr(e)+';ln(e)='+S;
Canvas.TextOut(10,10,S);
end;
返回
函数名Floor
简要介绍:Roundsvariablestowardnegativeinfinity.(取小于给定值的最大整数)
所属单元:Math
定义:functionFloor(X:Extended):Integer;
详细解释:CallFloortoobtainthehighestintegerlessthanorequaltoX.Forexample:

Floor(-2.8)=-3

Floor(2.8)=2

Floor(-1.0)=-1

Note:TheabsolutevalueofXmustbelessthanMaxInt.
(使用Floor函数以取得小于等于X的最大的整数,如:
Floor(-2.8)=-3

Floor(2.8)=2

Floor(-1.0)=-1

注意:X的绝对值必须小于整形数的最大值)
返回
函数名Frac
简要介绍:Returnsthefractionalpartofarealnumber(返回一个实数的小数部分)
所属单元:System
定义:functionFrac(X:Extended):Extended;
详细解释:TheFracfunctionreturnsthefractionalpartoftheargumentX.

Xisareal-typeexpression.TheresultisthefractionalpartofX;thatis,Frac(X)=X-Int(X).
(Frac函数返回参数X的小数部分,X是一个实型数,该函数的作用等价于Frac(X)=X-Int(X)。)
范例:
var
a,b:Real;
begin
a:=1.54;
b:=frac(a);
end;
此时,a=1.54,b=0.54
返回
函数名Frexp
简要介绍:SeparatestheMantissaandExponentofX(分解开X的尾数和指数。)
所属单元:Math
定义:procedureFrexp(X:Extended;varMantissa:Extended;varExponent:Integer)register;
详细解释:FrexpreturnsthemantissaofXasMantissaandtheexponentasExponent.(Frexp函数返回X的尾数用变量Mantissa和指数用变量Exponent)。
返回
函数名int
简要介绍:Returnstheintegerpartofarealnumber.(返回一个实数类型的整数部分)
所属单元:System
定义:functionInt(X:Extended):Extended;
详细解释:IntreturnstheintegerpartofX;thatis,Xroundedtowardzero.Xisareal-typeexpression.(Int函数返回参数X的整数部分,X为实数类型,函数结果为X经过负向舍入(向0舍入)实数。)

范例:
var

R:Real;
begin
R:=Int(123.456);{123.0}
R:=Int(-123.456);{-123.0}
end;
返回
函数名Intpower
简要介绍:Calculatestheintegralpowerofabasevalue.(计算基数的整数幂。)
所属单元:Math
定义:functionIntPower(Base:Extended;Exponent:Integer):Extendedregister;
详细解释:IntPowerraisesBasetothepowerspecifiedbyExponent
(计算基数的整数幂。base为基数,Exponent为指数)
范例:
返回
函数名Ldexp
简要介绍:CalculatesX*(2**P)
所属单元:Math
定义:functionLdexp(X:Extended;P:Integer):Extendedregister;
详细解释:LdexpreturnsXtimes(2tothepowerofP).
(Ldexp计算X*(2**P),返回X的(2的P次幂)次幂。)
返回
函数名Max
简要介绍:Returnsthegreateroftwonumericvalues.(取两个数中的最大值)
所属单元:Math
定义:
functionMax(A,B:Integer):Integer;overload;
functionMax(A,B:Int64):Int64;overload;
functionMax(A,B:Single):Single;overload;
functionMax(A,B:Double):Double;overload;
functionMax(A,B:Extended):Extended;overload;
详细解释:CallMaxtocomparetwonumericvalues.Maxreturnsthegreatervalueofthetwo.
(返回两个数值中的最大值。调用Max比较两个数值。它返回二者中较大的一个值。)
返回
函数名Min
简要介绍:Returnsthelesseroftwonumericvalues.(取两个数的最小值)
所属单元:Math
定义:functionMin(A,B:Integer):Integer;overload;
functionMin(A,B:Int64):Int64;overload;
functionMin(A,B:Single):Single;overload;
functionMin(A,B:Double):Double;overload;
functionMin(A,B:Extended):Extended;overload;
详细解释:CallMintocomparetwonumericvalues.Minreturnsthesmallervalueofthetwo.
(返回两个数值中的最小值。调用Max比较两个数值,它返回二者中较小的一个值。)
返回
函数名pi
简要介绍:Returns3.1415926535897932385.(返回3.1415926535897932385.)
所属单元:System
定义:functionPi:Extended;
详细解释:UsePiinmathematicalcalculationsthatrequirepi,theratioofacircle'scircumferencetoitsdiameter.Piisapproximatedas3.1415926535897932385.
(使用Pi函数精确计算返回圆周率Pi,圆周率是一个圆的周长除以它的直径。Pi的值近似于3.1415926535897932385.)
返回
函数名poly(本条翻译无把握)
简要介绍:EvaluatesauniformpolynomialofonevariableatthevalueX.
所属单元:Math
定义:functionPoly(X:Extended;constCoefficients:arrayofDouble):Extended;
详细解释:CallPolytoevaluatethepolynomialrepresentedbytheCoefficientsparameteratthepointwherethevariableequalsthevalueoftheXparameter.ThecoefficientsareorderedinincreasingpowersofX:

Coefficients[0]+Coefficients[1]*X+...+Coefficients
*(X**N)
(Poly估计一个变量在同一多项式的X值。调用Poly评估由Coefficients参数表达的多项式在一位置的值等同于X参数的值。参数是顺序的以X的幂增加:Coefficients[0]+
coefficients[1]*X+…..+Cofficients
*[X**N])
返回
函数名power
简要介绍:RaisesBasetoanypower.(取一个实数的幂)
所属单元:Math
定义:functionPower(Base,Exponent:Extended):Extended;
详细解释:PowerraisesBasetoanypower.ForfractionalexponentsorexponentsgreaterthanMaxInt,Basemustbegreaterthan0.
(返回一个实数的幂。当指数Exponent为小数或大于MaxInt时,底数Base必须大于0.)
返回
函数名Round
简要介绍:ReturnsthevalueofXroundedtothenearestwholenumber.(对一个实数进行四舍五入)
所属单元:System
定义:functionRound(X:Extended):Int64;
详细解释:TheRoundfunctionroundsareal-typevaluetoaninteger-typevalue.

Xisareal-typeexpression.RoundreturnsanInt64valuethatisthevalueofXroundedtothenearestwholenumber.IfXisexactlyhalfwaybetweentwowholenumbers,theresultisalwaystheevennumber.

IftheroundedvalueofXisnotwithintheInt64range,arun-timeerrorisgenerated,whichcanbehandledusingtheEInvalidOpexception.

(Round返回X向最近整数值的舍入。
函数将一个实型值舍入为一个整型值。X是一个实型表达式。Round返回一个长整型值,是离X最近的整数值。如果X是两个整数值的正中间,结果是绝对值最大的一个。如果X的舍入值不是在长整型范围内,一个运行时间错误将产生,可以使用EinvalidOp异常来处理)
范例:
var

S,T:string;

begin

Str(1.4:2:1,T);
S:=T+'roundsto'+IntToStr(Round(1.4))+#13#10;
Str(1.5:2:1,T);
S:=S+T+'roundsto'+IntToStr(Round(1.5))+#13#10;
Str(-1.4:2:1,T);
S:=S+T+'roundsto'+IntToStr(Round(-1.4))+#13#10;
Str(-1.5:2:1,T);
S:=S+T+'roundsto'+IntToStr(Round(-1.5));
MessageDlg(S,mtInformation,[mbOk],0);
end;


返回
函数名Sqr
简要介绍:Returnsthesquareofanumber.(取给定值的平方)
所属单元:System
定义:functionSqr(X:Extended):Extended;
详细解释:TheSqrfunctionreturnsthesquareoftheargument.

Xisafloating-pointexpression.Theresult,ofthesametypeasX,isthesquareofX,orX*X.
(Sqr返回X得平方值,X是一个浮点型的数,返回值的类型与X相同,值为X*X)
范例:var
S,Temp:string;
begin
Str(Sqr(5.0):3:1,Temp);
S:='5squaredis'+Temp+#13#10;
Str(Sqrt(2.0):5:4,Temp);
S:=S+'Thesquarerootof2is'+Temp;
MessageDlg(S,mtInformation,[mbOk],0);
end;
返回
函数名sqrt
简要介绍:ReturnsthesquarerootofX.
所属单元:System
定义:functionSqrt(X:Extended):Extended;
详细解释:Xisafloating-pointexpression.TheresultisthesquarerootofX.
(取X的平方根,X是一个浮点数,返回值也是个浮点数)
范例:var
S,Temp:string;
begin
Str(Sqr(5.0):3:1,Temp);
S:='5squaredis'+Temp+#13#10;
Str(Sqrt(2.0):5:4,Temp);
S:=S+'Thesquarerootof2is'+Temp;
MessageDlg(S,mtInformation,[mbOk],0);
end;
返回
函数名Trunc
简要介绍:Truncatesarealnumbertoaninteger.(截取一个实数的整数部分)
所属单元:System
定义:functionTrunc(X:Extended):Int64;
详细解释:TheTruncfunctiontruncatesareal-typevaluetoaninteger-typevalue.Xisareal-typeexpression.TruncreturnsanInt64valuethatisthevalueofXroundedtowardzero.

IfthetruncatedvalueofXisnotwithintheInt64range,anEInvalidOpexceptionisraised.
范例:var
S,T:string;
begin
Str(1.4:2:1,T);
S:=T+'Truncsto'+IntToStr(Trunc(1.4))+#13#10;
Str(1.5:2:1,T);
S:=S+T+'Truncsto'+IntToStr(Trunc(1.5))+#13#10;
Str(-1.4:2:1,T);
S:=S+T+'Truncsto'+IntToStr(Trunc(-1.4))+#13#10;
Str(-1.5:2:1,T);
S:=S+T+'Truncsto'+IntToStr(Trunc(-1.5));
MessageDlg(S,mtInformation,[mbOk],0);
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: