MQL4编程参考文档

# MQL4数学和三角函数(一)

## MathAbs() – 求绝对值

`double MathAbs(double value)`

`value - 数值。`

```  double dx=-3.141593, dy;
// calc MathAbs
dy=MathAbs(dx);
Print("The absolute value of ",dx," is ",dy);
// 输入数据:  -3.141593的绝对值为3.141593```

## MathArccos() – 求反余弦

`double MathArccos(double x)`

MathArccos函数返回x在0~兀(用弧度)范围内的反余弦。如果x小于-1或超出1,  MathArccos返回NaN(值不确定)。

`x - 计算的数值在-1 到 1 之间。`

```  double x=0.32696, y;
y=MathArcsin(x);
Print("正弦",x," = ",y);
y=MathArccos(x);
Print("余弦 ",x," = ",y);
//输出: 反正弦 0.326960=0.333085
//输出: 反余弦 0.326960=1.237711```

## MathArcsin() – 求反正弦

`double MathArccos(double x)`

`x - 计算的数值。`

```  double x=0.32696, y;
y=MathArcsin(x);
Print("正弦",x," = ",y);
y=MathArccos(x);
Print("余弦 ",x," = ",y);
//输出: 反正弦 0.326960=0.333085
//输出: 反余弦 0.326960=1.237711```

## MathArctan() – 求反正切

`double MathArctan(double x)`

`x - 计算的数值。`

```   double x=-862.42, y;
y=MathArctan(x);
Print("反正切 ",x," is ",y);
//输出数据:反正切 -862.42 是 -1.5696```

## MathCeil() – 取最小整数

`double MathCeil(double x)`

MathCeil函数返回一个大于或等于x的最小整数。

`x - 计算的数值。`

```  double y;
y=MathCeil(2.8);
Print("上限 2.8 is ",y);
y=MathCeil(-2.8);
Print("上限 -2.8 is ",y);
/*输出数据:
2.8  的最小整数 3
-2.8 的最小整数 -2*/```

## MathCos() – 求余弦

`double MathCos(double x)`

`x - 用弧度表示的角度值。`

```  double pi=3.1415926535;
double x, y;
x=pi/2;
y=MathSin(x);
Print("正弦(",x,") = ",y);
y=MathCos(x);
Print("余弦(",x,") = ",y);
//输出数据: 正弦(1.5708)=1
//         余弦(1.5708)=0```

## MathExp() – 求e的幂

`double MathExp(double d)`

`d - 指定乘方的数值。`

```  double x=2.302585093,y;
y=MathExp(x);
Print("MathExp(",x,") = ",y);
//输出: MathExp(2.3026)=10```

## MathFloor() – 取最大整数

`double MathFloor(double x)`

MathFloor函数返回一个小于或等于x的最大整数。

`x - 计算的数值。`

```  double y;
y=MathFloor(2.8);
Print("下限 2.8 is ",y);
y=MathFloor(-2.8);
Print("下限 -2.8 is ",y);
/*输出数据:
下限2.8  为 2
下限 -2.8 为-3*/```

## MathLog() – 求自然对数

`double MathLog(double x)`

`x - 计算的数值。`

``` double x=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,") = ", y);
//输出数据: MathLog(9000)=9.10498```