Math Functions
  • 30 Jan 2024
  • PDF

Math Functions

  • PDF

Article summary

Abs Function

Returns the absolute value of a number.

Syntax: Abs(number)

Remarks: The absolute value of a number is its unsigned magnitude.  For example, ABS(-1) and ABS(1) both return 1. If the numeric expression results in a Null, Abs returns a Null.

Example: This example takes the difference between input tag 1 and input tag 2.  The result is a positive number representing the difference.

Result = Abs(GD(1) - GD(2))

Cos Function

Returns the cosine of an angle.

Syntax: Cos(angle)

Remarks: The argument angle is measured in radians. The Cos function takes an angle and returns the ratio of two sides of a right triangle.  The ratio is the length of the side adjacent to the angle divided by the length of the hypotenuse. The result lies in the range -1 to 1. To convert degrees to radians, multiply degrees by Pi/180.  To convert radians to degrees, multiply radians by 180/Pi.  Pi is approximately 3.141593.

Example: This example uses Cos to calculate the cosine of an angle with a user-specified number of degrees. The number of degrees must be converted to radians before calculating the cosine.

Degrees = 60

Radians = Degrees * (3.14/ 180)

Result = Cos(Radians)                                                      

Exp Function

Returns e (the base of natural logarithms) raised to a power.

Syntax: Exp(number)

Remarks: If the value of number exceeds 709.782712893, an Overflow error occurs.  The constant e is approximately 2.718282.

Example: This example uses Exp to calculate the value of eExp(1) is e raised to the power of 1.

ValueOfE = Exp(1)            

Int, Fix Functions

Return the integer portion of a number.

Syntax: Int(number)

Fix(number)

Remarks: Both Int and Fix remove the fractional part of number and return the resulting integer value. If the numeric expression results in a Null, Int and Fix return a Null. The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number.  For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8. Fix(number) is equivalent to: Sgn(number) * Int(Abs(number))

Example: This example illustrates the difference between Int and Fix.

ResultInt = Int(-99.8)          ‘ Result is -100

ResultFix =  Fix(-99.8)       ‘ Result is -99

Log Function

Returns the natural logarithm of a number.

Syntax: Log(number)

Remarks: The natural logarithm is the logarithm to the base e.  The constant e is approximately 2.718282.

Example: This example calculates the value of e, then uses the Log function to calculate the natural logarithm of e to the first, second, and third powers. 

Result1 = Log(Exp(1))

Result2 = Log(Exp(2))

Result3 = Log(Exp(3))

Sin Function

Returns the sine of an angle.

Syntax: Sin(angle)

Remarks: The argument angle is measured in radians. The Sin function takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side opposite the angle divided by the length of the hypotenuse. The result lies in the range -1 to 1. To convert degrees to radians, multiply degrees by Pi/180.  To convert radians to degrees, multiply radians by 180/Pi.  Pi is approximately 3.141593.

Example: This example uses Sin to calculate the sine of an angle with a user-specified number of degrees.

Radians = 75 * (3.14 / 180)    ' Convert 75 degrees to radians

Result = Sin(Radians)

Sqr Function

Returns the square root of a number.

Syntax: Sqr(number)

Remarks: The argument number can be any number greater than or equal to 0.

Sqr Function Example: This example uses Sqr to calculate the square root of 3.5.

Result = Sqr(3.5)

Tan Function

Returns the tangent of an angle.

Syntax: Tan(angle)

Remarks: Tan takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side opposite an angle divided by the length of the side adjacent to the angle. If the return value is too large, an Overflow error occurs. To convert degrees to radians, multiply degrees by Pi/180.  To convert radians to degrees, multiply radians by 180/Pi.  Pi is approximately 3.141593.

Example: This example uses Tan to calculate the tangent of an angle 0f 85 degrees.

Result = Tan(Radians) & "."


Was this article helpful?