第十五节 数学运算函数.docx
- 文档编号:26702616
- 上传时间:2023-06-21
- 格式:DOCX
- 页数:15
- 大小:18.26KB
第十五节 数学运算函数.docx
《第十五节 数学运算函数.docx》由会员分享,可在线阅读,更多相关《第十五节 数学运算函数.docx(15页珍藏版)》请在冰豆网上搜索。
第十五节数学运算函数
Math&Trig
MathAbs()
MathArccos()
MathArcsin()
MathArctan()
MathCeil()
MathCos()
MathExp()
MathFloor()
MathLog()
MathMax()
MathMin()
MathMod()
MathPow()
MathRand()
MathRound()
MathSin()
MathSqrt()
MathSrand()
MathTan()
doubleMathAbs(
double value)
Returnstheabsolutevalue(modulus)ofthespecifiednumericvalue.
Parameters
value
-
Numericvalue.
Sample
doubledx=-3.141593,dy;
//calcMathAbs
dy=MathAbs(dx);
Print("Theabsolutevalueof",dx,"is",dy);
//Output:
Theabsolutevalueof-3.141593is3.141593
doubleMathArccos(
double x)
TheMathArccosfunctionreturnsthearccosineofxintherange0toπradians.Ifxislessthan-1orgreaterthan1,MathArccosreturnsanindefinite(sameasaquietNaN).
Parameters
x
-
Valuebetween-1and1whosearccosineistobecalculated.
Sample
doublex=0.32696,y;
y=asin(x);
Print("Arcsineof",x,"=",y);
y=acos(x);
Print("Arccosineof",x,"=",y);
//Output:
Arcsineof0.326960=0.333085
//Output:
Arccosineof0.326960=1.237711
doubleMathArcsin(
double x)
TheMathArcsinfunctionreturnsthearcsineofxintherange-π/2toπ/2radians.Ifxislessthan-1orgreaterthan1,asinreturnsanindefinite(sameasaquietNaN).
Parameters
x
-
Valuewhosearcsineistobecalculated
Sample
doublex=0.32696,y;
y=MathArcsin(x);
Print("Arcsineof",x,"=",y);
y=acos(x);
Print("Arccosineof",x,"=",y);
//Output:
Arcsineof0.326960=0.333085
//Output:
Arccosineof0.326960=1.237711
doubleMathArctan(
double x)
TheMathArctanreturnsthearctangentofx.Ifxis0,MathArctanreturns0.MathArctanreturnsavalueintherange-π/2toπ/2radians.
Parameters
x
-
Anumberrepresentingatangent.
Sample
doublex=-862.42,y;
y=MathArctan(x);
Print("Arctangentof",x,"is",y);
//Output:
Arctangentof-862.42is-1.5696
doubleMathCeil(
double x)
TheMathCeilfunctionreturnsanumericvaluerepresentingthesmallestintegerthatisgreaterthanorequaltox.
Parameters
x
-
Numericvalue.
Sample
doubley;
y=MathCeil(2.8);
Print("Theceilof2.8is",y);
y=MathCeil(-2.8);
Print("Theceilof-2.8is",y);
/*Output:
Theceilof2.8is3
Theceilof-2.8is-2*/
doubleMathCos(
double value)
Returnsthecosineofthespecifiedangle.
Parameters
value
-
Anangle,measuredinradians.
Sample
doublepi=3.1415926535;
doublex,y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")=",y);
y=MathCos(x);
Print("MathCos(",x,")=",y);
//Output:
MathSin(1.5708)=1
//MathCos(1.5708)=0
doubleMathExp(
double d)
Returnsvaluethenumbereraisedtothepowerd.Onoverflow,thefunctionreturnsINF(infinite)andonunderflow,MathExpreturns0.
Parameters
d
-
Anumberspecifyingapower.
Sample
doublex=2.302585093,y;
y=MathExp(x);
Print("MathExp(",x,")=",y);
//Output:
MathExp(2.3026)=10
doubleMathFloor(
double x)
TheMathFloorfunctionreturnsanumericvaluerepresentingthelargestintegerthatislessthanorequaltox.
Parameters
x
-
Numericvalue.
Sample
doubley;
y=MathFloor(2.8);
Print("Thefloorof2.8is",y);
y=MathFloor(-2.8);
Print("Thefloorof-2.8is",y);
/*Output:
Thefloorof2.8is2
Thefloorof-2.8is-3*/
doubleMathLog(
double x)
TheMathLogfunctionsreturnthelogarithmofxifsuccessful.Ifxisnegative,thesefunctionsreturnanindefinite(sameasaquietNaN).Ifxis0,theyreturnINF(infinite).
Parameters
x
-
Valuewhoselogarithmistobefound.
Sample
doublex=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,")=",y);
//Output:
MathLog(9000)=9.10498
doubleMathMax(
double value1,double value2)
Returnsmaximumvalueoftwonumericsvalues.
Parameters
value1
-
Firstnumericvalue.
value2
-
Secondnumericvalue.
Sample
doubleresult;
result=MathMax(1.08,Bid);
doubleMathMin(
double value1,double value2)
Returnsminimumvalueoftwonumericvalues.
Parameters
value1
-
Firstnumericvalue.
value2
-
Secondnumericvalue.
Sample
doubleresult;
result=MathMin(1.08,Ask);
doubleMathMod(
double value,double value2)
Dividestwonumbersandreturnsonlytheremainder.
Parameters
value
-
Dividendvalue.
value2
-
Dividervalue.
Sample
doublex=-10.0,y=3.0,z;
z=MathMod(x,y);
Print("Theremainderof",x,"/",y,"is",z);
//Output:
Theremainderof-10/3is-1
doubleMathPow(
double base,double exponent)
Returnsthevalueofabaseexpressiontakentoaspecifiedpower.
Parameters
base
-
Basevalue.
exponent
-
Exponentvalue.
Sample
doublex=2.0,y=3.0,z;
z=MathPow(x,y);
Printf(x,"tothepowerof",y,"is",z);
//Output:
2tothepowerof3is8
intMathRand(
)
TheMathRandfunctionreturnsapseudorandomintegerintherange0to0x7fff(32767).UsetheMathSrandfunctiontoseedthepseudorandom-numbergeneratorbeforecallingrand.
Sample
MathSrand(LocalTime());
//Display10numbers.
for(inti=0;i<10;i++)
Print("randomvalue",MathRand());
doubleMathRound(
double value)
Returnsvalueroundedtothenearestintegerofthespecifiednumericvalue.
Parameters
value
-
Numericvaluetoround.
Sample
doubley;
y=MathRound(2.8);
Print("Theroundof2.8is",y);
y=MathRound(2.4);
Print("Theroundof-2.4is",y);
//Output:
Theroundof2.8is3
//Theroundof2.4is2
doubleMathSin(
double value)
Returnsthesineofthespecifiedangle.
Parameters
value
-
Anangle,measuredinradians.
Sample
doublepi=3.1415926535;
doublex,y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")=",y);
y=MathCos(x);
Print("MathCos(",x,")=",y);
//Output:
MathSin(1.5708)=1
//MathCos(1.5708)=0
doubleMathSqrt(
double x)
TheMathSqrtfunctionreturnsthesquare-rootofx.Ifxisnegative,MathSqrtreturnsanindefinite(sameasaquietNaN).
Parameters
x
-
Positivenumericvalue.
Sample
doublequestion=45.35,answer;
answer=sqrt(question);
if(question<0)
Print("Error:
MathSqrtreturns",answer,"answer");
else
Print("Thesquarerootof",question,"is",answer);
//Output:
Thesquarerootof45.35is6.73
voidMathSrand(
int seed)
TheMathSrand()functionsetsthestartingpointforgeneratingaseriesofpseudorandomintegers.Toreinitializethegenerator,use1astheseedargument.Anyothervalueforseedsetsthegeneratortoarandomstartingpoint.MathRandretrievesthepseudorandomnumbersthataregenerated.CallingmathRandbeforeanycalltoMathSrandgeneratesthesamesequenceascallingMathSrandwithseedpassedas1.
Parameters
seed
-
Seedforrandom-numbergeneration.
Sample
MathSrand(LocalTime());
//Display10numbers.
for(inti=0;i<10;i++)
Print("randomvalue",MathRand());
doubleMathTan(
double x)
MathTanreturnsthetangentofx.Ifxisgreaterthanorequalto263,orlessthanorequalto-263,alossofsignificanceintheresultoccurs,inwhichcasethefunctionreturnsanindefinite(sameasaquietNaN).
Parameters
x
-
Angleinradians.
Sample
doublepi=3.1415926535;
doublex,y;
x=MathTan(pi/4);
Print("MathTan(",pi/4,"=",x);
//Output:
MathTan(0.7856)=1
数学运算函数[Math&Trig]
doubleMathAbs(doublevalue)
返回数字的绝对值
:
:
输入参数
value-要处理的数字
示例:
doubledx=-3.141593,dy;
//calcMathAbs
dy=MathAbs(dx);
Print("Theabsolutevalueof",dx,"is",dy);
//Output:
Theabsolutevalueof-3.141593is3.141593
doubleMathArccos(doublex)
计算反余弦值
:
:
输入参数
value-要处理的数字,范围-1到1
示例:
doublex=0.32696,y;
y=asin(x);
Print("Arcsineof",x,"=",y);
y=acos(x);
Print("Arccosineof",x,"=",y);
//Output:
Arcsineof0.326960=0.333085
//Output:
Arccosineof0.326960=1.237711
doubleMathArcsin(doublex)
计算反正弦值
:
:
输入参数
x-要处理的值
示例:
doublex=0.32696,y;
y=MathArcsin(x);
Print("Arcsineof",x,"=",y);
y=acos(x);
Print("Arccosineof",x,"=",y);
//Output:
Arcsineof0.326960=0.333085
//Output:
Arccosineof0.326960=1.237711
doubleMathArctan(doublex)
计算反正切值
:
:
输入参数
x-要处理的值
示例:
doublex=-862.42,y;
y=MathArctan(x);
Print("Arctangentof",x,"is",y);
//Output:
Arctangentof-862.42is-1.5696
doubleMathCeil(doublex)
返回向前进位后的值
:
:
输入参数
x-要处理的值
示例:
doubley;
y=MathCeil(2.8);
Print("Theceilof2.8is",y);
y=MathCeil(-2.8);
Print("Theceilof-2.8is",y);
/*Output:
Theceilof2.8is3
Theceilof-2.8is-2*/
doubleMathCos(doublevalue)
计算余弦值
:
:
输入参数
value-要处理的值
示例:
doublepi=3.1415926535;
doublex,y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")=",y);
y=MathCos(x);
Print("MathCos(",x,")=",y);
//Output:
MathSin(1.5708)=1
//MathCos(1.5708)=0
doubleMathExp(doubled)
Returnsvaluethenumbereraisedtothepowerd.Onoverflow,thefunctionreturnsINF(infinite)andonunderflow,MathExpreturns0.
:
:
输入参数
d-Anumberspecifyingapower.
示例:
doublex=2.302585093,y;
y=MathExp(x);
Print("MathExp(",x,")=",y);
//Output:
MathExp(2.3026)=10
doubleMathFloor(doublex)
返回向后进位后的值
:
:
输入参数
x-要处理的值
示例:
doubley;
y=MathFloor(2.8);
Print("Thefloorof2.8is",y);
y=MathFloor(-2.8);
Print("Thefloorof-2.8is",y);
/*Output:
Thefloorof2.8is2
Thefloorof-2.8is-3*/
doubleMathLog(doublex)
计算对数
:
:
输入参数
x-要处理的值
示例:
doublex=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,")=",y);
//Output:
MathLog(9000)=9.10498
doubleMathMax(doublevalue1,doublevalue2)
计算两个值中的最大值
:
:
输入参数
value1-第一个值
value2-第二个值
示例:
doubleresult=MathMax(1.08,Bid);
doubleMathMin(doublevalue1,doublevalue2)
计算两个值中的最小值
:
:
输入参数
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 第十五节 数学运算函数 第十 五节 数学 运算 函数