MQL4 Reference

# MQL4 Math & Trig (1)

A set of mathematical and trigonometric functions.

## MathAbs()

`double MathAbs(double value)`

Returns the absolute value (modulus) of the specified numeric value.

Parameters:

`value - Numeric value. `

Sample:

```  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```

## MathArccos()

`double MathArccos(double x)`

The MathArccos function returns the arccosine of x within the range 0 to π (in radians). If x is less than -1 or exceeds 1, the MathArccos returns NaN (indeterminate value).

Parameters:

`x - Value between -1 and 1 the arccosine of which to be calculated. `

Sample:

```  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```

## MathArcsin()

`double MathArcsin(double x)`

The MathArcsin function returns the arcsine of x in the range -π/2 to π/2 radians. If x is less than -1 or exceeds 1, the arcsine returns NaN (indeterminate value).

Parameters:

`x - Value the arcsine of which to be calculated. `

Sample:

```  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```

## MathArctan()

`double MathArctan(double x)`

The MathArctan returns the arctangent of x. If x is 0, MathArctan returns 0. MathArctan returns a value within the range of -π/2 to π/2 radians.

Parameters:

`x - A number representing a tangent. `

Sample:

```  double x=-862.42, y;
y=MathArctan(x);
Print("Arctangent of ",x," is ",y);
//Output: Arctangent of -862.42 is -1.5696```

## MathCeil()

`double MathCeil(double x)`

The MathCeil function returns a numeric value representing the smallest integer that exceeds or equals to x.

Parameters:

`x - Numeric value. `

Sample:

```  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*/```

## MathCos()

`double MathCos(double value)`

Returns the cosine of the specified angle.

Parameters:

`value - An angle measured in radians. `

Sample:

```  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```

## MathExp()

`double MathExp(double d)`

Returns the value of e raised to the power of d. At overflow, the function returns INF (infinity), and it returns 0 at underflow.

Parameters:

`d - A number specifying the power. `

Sample:

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

## MathFloor()

`double MathFloor(double x)`

The MathFloor function returns a numeric value representing the largest integer that is less than or equal to x.

Parameters:

`x - Numeric value. `

Sample:

```  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*/```

## MathLog()

`double MathLog(double x)`

The MathLog function returns the natural logarithm of x if successful. If x is negative, these functions return NaN (indeterminate value). If x is 0, they return INF (infinity).

Parameters:

`x - Value logarithm of which to be found. `

Sample:

```  double x=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,") = ", y);
//Output: MathLog(9000)=9.10498```