User login

  

Math & Trigonometric Functions

The following lists alphabetically built-in PTL functions available for basic mathematic computations.

These functions are placed in Math package.

  • The trig functions used radians, not degrees. The radian is a unit of plane angle, equal to 180/Ï€ degrees or about 57.2958 degrees.

List of available functions:

MathAbsMathCotanMathMaxMathSign
MathArccosMathExpMathMinMathSin
MathArcsinMathFractMathModMathSinh
MathArctanMathIntMathNormalizeMathSqr
MathCeilMathLnMathPowMathSqrt
MathCosMathLgMathRandMathTan
MathCoshMathLogMathRoundMathTan

 

MathAbs

Returns the absolute value of the number specified.

Syntax

double MathAbs( double value)

double MathAbs( int value)

Parameters

  • value - Any numeric float-point or integer value.

Example

double f1;

double f2;

f1 = MathAbs(-5.5);    // f1 <- 5.5

f2 = MathAbs(8.2);   // f2 <- 8.2

 

MathArccos

Returns the radian value of the angle whose cosine is specified.

Syntax

double MathArccos( double value)

double MathArccos( int value)

Parameters

  • value - Numeric value between –1 and 1.

Example

double f1;

double f2;

f1 = MathArccos(-0.2);    // f1 <- 1.77215424758523

f2 = MathArccos(0.9872);   // f2 <- 0.160171160067318

 

MathArcsin

Returns the radian value of the angle whose sine is specified.

Syntax

double MathArcsin(int value)

Parameters

  • value - Numeric value between –1 and 1.

 

MathArctan

Returns the radian value of the angle whose tangent is specified.

Syntax

double MathArctan( double value)

double MathArctan( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathArctan(-0.2);    // f1 <- -0.197395559849881

f2 = MathArctan(0.9872);   // f2 <- 0.778957028643464

 

MathCeil

Returns the smallest whole number greater than or equal to the value specified (rounds up).

Syntax

double MathCeil( double value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathCeil(-1.2);    // f1 <- -1.0

f2 = MathCeil(5.12);   // f2 <- 5.0

 

MathCos

Returns the cosine of the angle (in radians) specified.

Syntax

double MathCos( double value)

double MathCos( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathCos(456.0);    // f1 <- -0.891991243357829

f2 = MathCos(-0.2);   // f2 <- 0.890066577841242

 

MathCosh

Returns the hyperbolic cosine of the angle (in radians) specified.

Syntax

double MathCosh( double value)

double MathCosh( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathCosh(4.0);    // f1 <- 27.3082328360165

f2 = MathCosh(-0.2);   // f2 <- -1.02006675561908

 

MathCotan

Returns the cotangent of the angle (in radians) specified.

Syntax

double MathCosh( double value)

double MathCosh( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathCotan(4.0);    // f1 <- 0.863691154450617

f2 = MathCotan(-0.2);   // f2 <- -4.93315487558689

 

MathExp

Returns the exponent of the number specified.

Syntax

double MathExp( double value)

double MathExp( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathExp(4.0);    // f1 <- 54.5981500331442

f2 = MathExp(-0.2);   // f2 <- 0.818730753077982

 

MathFract

Returns the fractional part of a specified value

Syntax

double MathFract( double value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathFract(4.8);    // f1 <- 0.8

f2 = MathFract(-0.2);   // f2 <- 0.2

 

MathInt

Calculate the integer part of a specified number.

Syntax

double MathInt( double num)

Parameters

  • num - Any numeric value.

 

MathLn

Returns the natural logarithm (base e) of the number specified or NaN.

Syntax

double MathLn( double value)

double MathLn( int value)

Parameters

  • value - Positive numeric value.

Example

double f1;

double f2;

f1 = MathLn(4.8);    // f1 <- 1.56861591791385

f2 = MathLn(0.2);   // f2 <- -1.6094379124341

 

MathLg

Returns the common logarithm (base 10) of the number specified or NaN.

Syntax

double MathLg( double value)

double MathLg( int value)

Parameters

  • value - Positive numeric value.

Example

double f1;

double f2;

f1 = MathLg(4.8);    // f1 <- 0.681241237375587

f2 = MathLg(0.2);   // f2 <- -0.698970004336019

 

MathLog

Returns the logarithm of the specified number to the specified base or NaN.

Syntax

double MathLog( double value, int base)

double MathLog( int value, double base)

double MathLog( int value, int base)

Parameters

  • value - Positive numeric value.
  • base - Positive numeric value other than 1.

 

MathMax

Returns the larger of the two numbers specified.

Syntax

double MathMax( double value1, double value2)

double MathMax( int value1, int value2)

double MathMax( double value1, int value2)

double MathMax( int value1, double value2)

Parameters

  • value1 - Any numeric value.
  • value2 - Any numeric value.

Example

double f1;

double f2;

f1 = MathMax(4.8, 1.2);    // f1 <- 4.8

f2 = MathMax(25.1, 0.5);   // f2 <- 25.1

 

MathMin

Returns the smaller of the two numbers specified.

Syntax

double MathMin( double value1, double value2)

double MathMin( double value1, int value2)

double MathMin( int value1, double value2)

double MathMin( int value1, int value2)

Parameters

  • value1 - Any numeric value.
  • value2 - Any numeric value.

Example

double f1;

double f2;

f1 = MathMin(2.2, 5.0);    // f1 <- 2.2

f2 = MathMin(0.2, -1.5);   // f2 <- -1.5

 

MathMod

Returns the remainder of division. A result value such that (a/b)*b+(a%b) is equal to a.

Syntax

double MathMod( double value1, int value2)

double MathMod( int value1, double value2)

double MathMod( int value1, int value2)

Parameters

  • value1, value2 - Any numeric value

 

MathNormalize

Returns the number closest to the specified number, divisible by the specified sampling interval. For example, normalizing the value of 1.3 at the sampling interval of 0.25 would return 1.25.

Syntax

double MathNormalize( double value, double interval)

double MathNormalize( double value, int interval)

double MathNormalize( int value, double interval)

double MathNormalize( int value, int interval)

Parameters

  • value - Any numeric value.
  • interval - Positive numeric value specifying the sampling interval.

Remarks

MathNormalize is usually used to sample continuous price data at specified intervals.

Example

double f1;

double f2;

f1 = MathNormalize(15.68, 1.25);    // f1 <- 16.25

f2 = MathNormalize(90.8, 2.0);   // f2 <- 90.0

 

 

MathPow

Returns the result of the specified number raised to the specified power.

Syntax

double MathPow( double value, int power)

double MathPow( int value, double power)

double MathPow( int value, int power)

Parameters

  • value - Any numeric value.
  • power - Any numeric value.

 

MathRand

Returns a random number less than the specified maximum or random number between the two specified numbers.

Syntax

int MathRand( double max)

double MathRand( double value1, int value2)

double MathRand( int value1, double value2)

double MathRand( int value1, int value2)

Parameters

  • max, - Any numeric value.
  • value1, value2 - Any numeric value specifying the minimum possible value of a random number.

Example

double f1;

f1 = MathRand(3200.2);    

 

MathRound

Rounds a decimal to nearest number

Syntax

int MathRound( double value)

Parameters

  • value - Any numeric value.

Example

int f1;

f1 = MathRound(10.12584, 3);   // 10

 

MathSign

Returns the sign of the value specified (signum function).

Syntax

double MathSign( double value)

double MathSign( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

f1 = MathSign(12);   // 1

 

 

MathSin

Returns the sine of the angle (in radians) specified.

Syntax

double MathSin( int value)

Parameters

  • value - Any numeric value.

 

MathSinh

Returns the hyperbolic sine of the angle (in radians) specified.

Syntax

double MathSinh( double value)

double MathSinh( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathSinh(5.8);    // f1 <- 165.148266177452

f2 = MathSinh(0);      // f2 <- 0

 

 

MathSqr

Returns the squared value specified.

Syntax

double MathSqr( double value)

double MathSqr( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathSqr(4);    // f1 <- 16

f2 = MathSqr(-9);   // f2 <- 81

 

MathSqrt

Returns the square root of the value specified.

Syntax

double MathSqrt( double value)

double MathSqrt( int value)

Parameters

  • value - Positive numeric value.

Example

double f1;

double f2;

f1 = MathSqrt(4);    // f1 <- 2

f2 = MathSqrt(15.2);   // f2 <- 3.89871773792359

 

 

MathTan

Returns the tangent of the angle (in radians) specified.

Syntax

double MathTan( double value)

double MathTan( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathTan(-5.5);    // f1 <- 0.995584052213885

f2 = MathTan(8.2);   // f2 <- -2.77374929538342

 

MathTanh

Returns the hyperbolic tangent of the angle (in radians) specified.

Syntax

double MathTanh( double value)

double MathTanh( int value)

Parameters

  • value - Any numeric value.

Example

double f1;

double f2;

f1 = MathTanh(-5.5);    // f1 <- -0.999966597156304

f2 = MathTanh(8.2);   // f2 <- 0.999999849130844

12345