数学运算函数 [Math & Trig]
<-- begin content -->由 帝国程序员 在 周二, 2005-10-25 17:51 提交
double MathArccos( double x)
计算反余弦值
double MathArcsin( double x)
计算反正弦值
double MathArctan( double x)
计算反正切值
double MathCeil( double x)
返回向前进位后的值
double MathCos( double value)
计算余弦值
double MathExp( double d)
Returns value the number e raised to the power d. On overflow, the function returns INF (infinite) and on underflow, MathExp returns 0.
double MathFloor( double x)
返回向后进位后的值
double MathLog( double x)
计算对数
double MathMax( double value1, double value2)
计算两个值中的最大值
double MathMin( double value1, double value2)
计算两个值中的最小值
double MathMod( double value, double value2)
计算两个值相除的余数
double MathPow( double base, double exponent)
计算指数
int MathRand( )
取随机数
示例:
double MathRound( double value)
取四舍五入的值
double MathSin( double value)
计算正弦数
double MathSqrt( double x)
计算平方根
void MathSrand( int seed)
通过Seed产生随机数
double MathTan( double x)
计算正切值
double MathAbs( double value)
返回数字的绝对值
示例:
double dx=-3.141593, dy;
// calc MathAbs
dy=MathAbs(dx);
Print("The absolute value of ",dx," is ",dy);
// Output: The absolute value of -3.141593 is 3.141593
// calc MathAbs
dy=MathAbs(dx);
Print("The absolute value of ",dx," is ",dy);
// Output: The absolute value of -3.141593 is 3.141593
double MathArccos( double x)
计算反余弦值
示例:
double x=0.32696, y;
y=asin(x);
Print("Arcsine of ",x," = ",y);
y=acos(x);
Print("Arccosine of ",x," = ",y);
//Output: Arcsine of 0.326960=0.333085
//Output: Arccosine of 0.326960=1.237711
y=asin(x);
Print("Arcsine of ",x," = ",y);
y=acos(x);
Print("Arccosine of ",x," = ",y);
//Output: Arcsine of 0.326960=0.333085
//Output: Arccosine of 0.326960=1.237711
double MathArcsin( double x)
计算反正弦值
示例:
double x=0.32696, y;
y=MathArcsin(x);
Print("Arcsine of ",x," = ",y);
y=acos(x);
Print("Arccosine of ",x," = ",y);
//Output: Arcsine of 0.326960=0.333085
//Output: Arccosine of 0.326960=1.237711
y=MathArcsin(x);
Print("Arcsine of ",x," = ",y);
y=acos(x);
Print("Arccosine of ",x," = ",y);
//Output: Arcsine of 0.326960=0.333085
//Output: Arccosine of 0.326960=1.237711
double MathArctan( double x)
计算反正切值
示例:
double x=-862.42, y;
y=MathArctan(x);
Print("Arctangent of ",x," is ",y);
//Output: Arctangent of -862.42 is -1.5696
y=MathArctan(x);
Print("Arctangent of ",x," is ",y);
//Output: Arctangent of -862.42 is -1.5696
double MathCeil( double x)
返回向前进位后的值
示例:
double y;
y=MathCeil(2.8);
Print("The ceil of 2.8 is ",y);
y=MathCeil(-2.8);
Print("The ceil of -2.8 is ",y);
/*Output:
The ceil of 2.8 is 3
The ceil of -2.8 is -2*/
y=MathCeil(2.8);
Print("The ceil of 2.8 is ",y);
y=MathCeil(-2.8);
Print("The ceil of -2.8 is ",y);
/*Output:
The ceil of 2.8 is 3
The ceil of -2.8 is -2*/
double MathCos( double value)
计算余弦值
示例:
double pi=3.1415926535;
double x, 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
double x, 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
double MathExp( double d)
Returns value the number e raised to the power d. On overflow, the function returns INF (infinite) and on underflow, MathExp returns 0.
示例:
double x=2.302585093,y;
y=MathExp(x);
Print("MathExp(",x,") = ",y);
//Output: MathExp(2.3026)=10
y=MathExp(x);
Print("MathExp(",x,") = ",y);
//Output: MathExp(2.3026)=10
double MathFloor( double x)
返回向后进位后的值
示例:
double y;
y=MathFloor(2.8);
Print("The floor of 2.8 is ",y);
y=MathFloor(-2.8);
Print("The floor of -2.8 is ",y);
/*Output:
The floor of 2.8 is 2
The floor of -2.8 is -3*/
y=MathFloor(2.8);
Print("The floor of 2.8 is ",y);
y=MathFloor(-2.8);
Print("The floor of -2.8 is ",y);
/*Output:
The floor of 2.8 is 2
The floor of -2.8 is -3*/
double MathLog( double x)
计算对数
示例:
double x=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,") = ", y);
//Output: MathLog(9000)=9.10498
y=MathLog(x);
Print("MathLog(",x,") = ", y);
//Output: MathLog(9000)=9.10498
double MathMax( double value1, double value2)
计算两个值中的最大值
示例:
double result=MathMax(1.08,Bid);
double MathMin( double value1, double value2)
计算两个值中的最小值
示例:
double result=MathMin(1.08,Ask);
double MathMod( double value, double value2)
计算两个值相除的余数
示例:
double x=-10.0,y=3.0,z;
z=MathMod(x,y);
Print("The remainder of ",x," / ",y," is ",z);
//Output: The remainder of -10 / 3 is -1
z=MathMod(x,y);
Print("The remainder of ",x," / ",y," is ",z);
//Output: The remainder of -10 / 3 is -1
double MathPow( double base, double exponent)
计算指数
示例:
double x=2.0,y=3.0,z;
z=MathPow(x,y);
Printf(x," to the power of ",y," is ", z);
//Output: 2 to the power of 3 is 8
z=MathPow(x,y);
Printf(x," to the power of ",y," is ", z);
//Output: 2 to the power of 3 is 8
int MathRand( )
取随机数
示例:
MathSrand(LocalTime());
// Display 10 numbers.
for(int i=0;i<10;i++ )
Print("random value ", MathRand());
// Display 10 numbers.
for(int i=0;i<10;i++ )
Print("random value ", MathRand());
double MathRound( double value)
取四舍五入的值
示例:
double y=MathRound(2.8);
Print("The round of 2.8 is ",y);
y=MathRound(2.4);
Print("The round of -2.4 is ",y);
//Output: The round of 2.8 is 3
// The round of -2.4 is -2
Print("The round of 2.8 is ",y);
y=MathRound(2.4);
Print("The round of -2.4 is ",y);
//Output: The round of 2.8 is 3
// The round of -2.4 is -2
double MathSin( double value)
计算正弦数
示例:
double pi=3.1415926535;
double x, 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
double x, 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
double MathSqrt( double x)
计算平方根
示例:
double question=45.35, answer;
answer=MathSqrt(question);
if(question<0)
Print("Error: MathSqrt returns ",answer," answer");
else
Print("The square root of ",question," is ", answer);
//Output: The square root of 45.35 is 6.73
answer=MathSqrt(question);
if(question<0)
Print("Error: MathSqrt returns ",answer," answer");
else
Print("The square root of ",question," is ", answer);
//Output: The square root of 45.35 is 6.73
void MathSrand( int seed)
通过Seed产生随机数
示例:
MathSrand(LocalTime());
// Display 10 numbers.
for(int i=0;i<10;i++ )
Print("random value ", MathRand());
// Display 10 numbers.
for(int i=0;i<10;i++ )
Print("random value ", MathRand());
double MathTan( double x)
计算正切值
示例:
double pi=3.1415926535;
double x,y;
x=MathTan(pi/4);
Print("MathTan(",pi/4," = ",x);
//Output: MathTan(0.7856)=1
double x,y;
x=MathTan(pi/4);
Print("MathTan(",pi/4," = ",x);
//Output: MathTan(0.7856)=1
