BCX Run-time Math Functions

The following functions return double floating point values and expect double floating point values for their arguments. All trigonometric functions use radian values for their arguments. The inverse trigonometric functions return radian values.

To convert a degree value angle to a radian value angle multiply degrees times PI divided by 180.0.

To convert a radian value angle to a degree value angle multiply radians times 180.0 divided by PI.

Example :


 DIM PI#
 DIM DegToRad#
 DIM RadToDeg#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM SineOfAngle#
 DIM TheAnswer$
 
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees.
 
 RadToDeg# = (180.0 / PI#)
 
 DegToRad# = (PI# / 180.0)
 
 DegreeAngle# = 45.0
 
 RadianAngle# = DegreeAngle# * DegToRad#
 
 SineOfAngle# = SIN(RadianAngle#)
 
 SPRINT TheAnswer$, "The sine of 45 degrees is", SineOfAngle#
 
 PRINT TheAnswer$
 
 RadianAngle# = ASIN(SineOfAngle#)
 
 DegreeAngle# = RadianAngle# * RadToDeg# 
 
 SPRINT TheAnswer$, "The degree value of the inverse sine of", SineOfAngle#, " is", DegreeAngle#, " degrees."
 
 PRINT TheAnswer$

Result:


 The sine of 45 degrees is 0.707106781186548
 The degree value of the inverse sine of 0.707106781186548 is 45 degrees.

Trigonometric functions

Trigonometric functions are used to obtain an angle's trigonometric ratio from an angle.

SIN function

Purpose: SIN returns the sine trigonometric ratio of a radian value angle.

🔗 See Remarks section below for SINL, the long double precision equivalent of SIN.


Syntax:

 SineOfAngle# = SIN(RadianAngle#)

Parameters:

  • RadianAngle# An angle expressed as a double floating point radian value.

Return Value:

  • SineOfAngle# The sine of RadianAngle# expressed as a double floating point value.

Example:


 DIM PI#
 DIM DegToRad#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM SineOfAngle#
 DIM TheAnswer$
  
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees. 

 DegToRad# = (PI# / 180.0)
  
 DegreeAngle# = 36.0
  
 RadianAngle# = DegreeAngle# * DegToRad#
  
 SineOfAngle# = SIN(RadianAngle#)
  
 SPRINT TheAnswer$, "The sine of", STR$(DegreeAngle#), " degrees is", SineOfAngle#
  
 PRINT TheAnswer$
  

Result:


 The sine of 36 degrees is 0.587785252292473

Remarks:

SINL returns, as an LDOUBLE, the sine trigonometric ratio of a radian value angle. Please note the required cast to LDOUBLE as shown in the example below.

Example:


 CONST PI = (4.0 * ATN(1.0))
 CONST TR = (180.0 / PI)
 PRINT SIN(45.0 / TR)
 PRINT SINL((LDOUBLE)45.0 / TR)

Result:


 0.707106781186548
 0.7071067811865475727

COS function

Purpose: COS returns the cosine trigonometric ratio of a radian value angle.

🔗 See Remarks section below for COSL, the long double precision equivalent of COS.


Syntax:

 CosineOfAngle# = COS(RadianAngle#)

Parameters:

  • RadianAngle# An angle expressed as a double floating point radian value.

Return Value:

  • CosineOfAngle# The cosine of RadianAngle# expressed as a double floating point value.

Example:


 DIM PI#
 DIM DegToRad#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM CosineOfAngle#
 DIM TheAnswer$
  
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees. 

 DegToRad# = (PI# / 180.0)
  
 DegreeAngle# = 36.0
  
 RadianAngle# = DegreeAngle# * DegToRad#
  
 CosineOfAngle# = COS(RadianAngle#)
  
 SPRINT TheAnswer$, "The cosine of", STR$(DegreeAngle#), " degrees is", CosineOfAngle#
  
 PRINT TheAnswer$

Result:


 The cosine of 36 degrees is 0.809016994374947

Remarks:

COSL returns, as an LDOUBLE, the cosine trigonometric ratio of a radian value angle.

Example:



Result:



TAN function

Purpose: TAN returns the tangent trigonometric ratio of a radian value angle.

🔗 See Remarks section below for TANL, the long double precision equivalent of TAN.


Syntax:

 TangentOfAngle# = TAN(RadianAngle#)

Parameters:

  • RadianAngle# An angle expressed as a double floating point radian value.

Return Value:

  • TangentOfAngle# The cosine of RadianAngle# expressed as a double floating point value.

Example:


 DIM PI#
 DIM DegToRad#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM TangentOfAngle#
 DIM TheAnswer$
   
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees.  

 DegToRad# = (PI# / 180.0)
   
 DegreeAngle# = 36.0
   
 RadianAngle# = DegreeAngle# * DegToRad#
   
 TangentOfAngle# = TAN(RadianAngle#)
   
 SPRINT TheAnswer$, "The tangent of", STR$(DegreeAngle#), " degrees is", TangentOfAngle#
   
 PRINT TheAnswer$
 

Result:


 The tangent of 36 degrees is 0.726542528005361

Remarks:

TANL returns, as an LDOUBLE, the tangent trigonometric ratio of a radian value angle.

Example:



Result:



Inverse Trigonometric functions

Inverse trigonometric functions are used to obtain an angle from an angle's trigonometric ratio.

ASIN function

Purpose: ASIN returns the radian value angle of a sine trigonometric ratio.

🔗 See Remarks section below for ASINL, the long double precision equivalent of ASIN.


Syntax:

 RadianAngle# = ASIN(SineOfAngle#)

Parameters:

  • SineOfAngle# The sine of RadianAngle# expressed as a double floating point value.

Return Value:

  • RadianAngle# An angle expressed as a double floating point radian value.

Example:


 DIM PI#
 DIM DegToRad#
 DIM RadToDeg#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM SineOfAngle#
 DIM TheAnswer$
 
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees.

 RadToDeg# = (180.0 / PI#)
 
 DegToRad# = (PI# / 180.0)
 
 DegreeAngle# = 36.0
 
 RadianAngle# = DegreeAngle# * DegToRad#
 
 SineOfAngle# = SIN(RadianAngle#)
 
 SPRINT TheAnswer$, "The angle of", STR$(DegreeAngle#), " degrees has a sine trigonometric ratio of", SineOfAngle#
 
 PRINT TheAnswer$
 
 RadianAngle# = ASIN(SineOfAngle#)
 
 DegreeAngle# = RadianAngle# * RadToDeg#
 
 SPRINT TheAnswer$, "The sine trigonometric ratio of", SineOfAngle#, " corresponds to an angle of", DegreeAngle#, " degrees."
 
 PRINT TheAnswer$

Result:


 The angle of 36 degrees has a sine trigonometric ratio of 0.587785252292473
 The sine trigonometric ratio of 0.587785252292473 corresponds to an angle of 36 degrees.

Remarks:

ASINL returns, as an LDOUBLE, the radian value angle of a sine trigonometric ratio..

Example:



Result:



ACOS function

Purpose: ACOS returns the radian value angle of a cosine trigonometric ratio.

🔗 See Remarks section below for ACOSL, the long double precision equivalent of ACOS.


Syntax:

 RadianAngle# = ACOS(CosineOfAngle#)

Parameters:

  • CosineOfAngle# The cosine of RadianAngle# expressed as a double floating point value.

Return Value:

  • RadianAngle# An angle expressed as a double floating point radian value.

Example:


 DIM PI#
 DIM DegToRad#
 DIM RadToDeg#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM CosineOfAngle#
 DIM TheAnswer$
 
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees.

 RadToDeg# = (180.0 / PI#)
 
 DegToRad# = (PI# / 180.0)
 
 DegreeAngle# = 36.0
 
 RadianAngle# = DegreeAngle# * DegToRad#
 
 CosineOfAngle# = COS(RadianAngle#)
 
 SPRINT TheAnswer$, "The angle of", STR$(DegreeAngle#), " degrees has a cosine trigonometric ratio of", CosineOfAngle#
 
 PRINT TheAnswer$
 
 RadianAngle# = ACOS(CosineOfAngle#)
 
 DegreeAngle# = RadianAngle# * RadToDeg#
 
 SPRINT TheAnswer$, "The cosine trigonometric ratio of", CosineOfAngle#, " corresponds to an angle of", DegreeAngle#, " degrees."
 
 PRINT TheAnswer$

Result:


 The angle of 36 degrees has a cosine trigonometric ratio of 0.809016994374947 
The cosine trigonometric ratio of 0.809016994374947 corresponds to an angle of 36 degrees.

Remarks:

ACOSL returns, as an LDOUBLE, the radian value angle of a cosine trigonometric ratio..

Example:



Result:



ATN function

Purpose: ATN returns the radian value angle of a tangent trigonometric ratio.

🔗 See Remarks section below for ATNL, the long double precision equivalent of ATN.


Syntax:

 RadianAngle# = ATN(TangentOfAngle#)

Parameters:

  • TangentOfAngle# The cosine of RadianAngle# expressed as a double floating point value.

Return Value:

  • RadianAngle# An angle expressed as a double floating point radian value.

Example:


 DIM PI#
 DIM DegToRad#
 DIM RadToDeg#
 DIM DegreeAngle#
 DIM RadianAngle#
 DIM TangentOfAngle#
 DIM TheAnswer$
 
 PI# = (4.0 * ATN(1.0)) ' 1.0 is radians not degrees.

 RadToDeg# = (180.0 / PI#)
 
 DegToRad# = (PI# / 180.0)
 
 DegreeAngle# = 36.0
 
 RadianAngle# = DegreeAngle# * DegToRad#
 
 TangentOfAngle# = TAN(RadianAngle#)
 
 SPRINT TheAnswer$, "The angle of", STR$(DegreeAngle#), " degrees has a tangent trigonometric ratio of", TangentOfAngle#
 
 PRINT TheAnswer$
 
 RadianAngle# = ATN(TangentOfAngle#)
 
 DegreeAngle# = RadianAngle# * RadToDeg#
 
 SPRINT TheAnswer$, "The tangent trigonometric ratio of", TangentOfAngle#, " corresponds to an angle of", DegreeAngle#, " degrees."
 
 PRINT TheAnswer$

Result:


 The angle of 36 degrees has a tangent trigonometric ratio of 0.726542528005361 
The tangent trigonometric ratio of 0.726542528005361 corresponds to an angle of 36 degrees.

Remarks:

ATNL returns, as an LDOUBLE, the radian value angle of a tangent trigonometric ratio..

Example:



Result:



Hyperbolic Trigonometric functions


 A# = SINH(B)    'A = Hyperbolic Sine of B

 A# = COSH(B)    'A = Hyperbolic Cosine of B

 A# = TANH(B)    'A = Hyperbolic Tangent of B

Inverse Hyperbolic Trigonometric functions


 A# = ASINH(B)   'A = Hyperbolic Arc Sine of B

 A# = ACOSH(B)   'A = Hyperbolic Arc Cosine of B

 A# = ATANH(B)   'A = Hyperbolic Arc Tangent of B

Miscellaneous Math functions

LOG function

Purpose: LOG returns the natural logarithmic value of a number.

🔗 See Remarks section below for LOGL, the long double precision equivalent of LOG.


Syntax:

 NatLogNum# = LOG(TheNumber#)

Parameters:

  • TheNumber# A number expressed as a double floating point value.

Return Value:

  • NatLogNum# The natural logarithmic value of TheNumber, that is, the exponent to which the base 2.718281828459 is raised to evaluate to TheNumber.

Example:


 DIM Number#
 DIM LengthOfNumber#
 
 Number# = 1234567890
 LengthOfNumber# = INT(LOG(Number#) / LOG(10)) + 1
 PRINT LengthOfNumber#

Result:


 10

Remarks:

LOGL returns, as an LDOUBLE, returns the natural logarithmic value of a number.

Example:



Result:



LOG10 function

Purpose: LOG10 returns the common logarithmic value of a number.

🔗 See Remarks section below for LOG10L, the long double precision equivalent of LOG10.


Syntax:

 ComLogNum# = LOG10(TheNumber#)

Parameters:

  • TheNumber# A number expressed as a double floating point value.

Return Value:

  • ComLogNum# The common logarithmic value of TheNumber, that is, the exponent to which the base 10 is raised to evaluate to TheNumber.

Example:


 DIM Number#
 DIM LengthOfNumber#
 
 Number# = 1234567890
 LengthOfNumber# = INT(LOG10(Number#) / LOG10(10)) + 1
 PRINT LengthOfNumber#

Result:


 10

Remarks:

LOG10L returns, as an LDOUBLE, returns natural logarithmic value of a number.

Example:



Result:




 A# = SQR(B)     'A = Square Root of B

 A# = SQRT(B)    'A = Square Root of B

 A# = HYPOT(B,C) 'A = Hypotenuse of a right triangle

 A# = MOD(B,C)   'A = MODulo(B / C)(floating point)

 A% = IMOD(B,C)  'A = MODulo(B / C)(integer)

 A# = EXP(B)     'A = e(2.718281828459045) raised to power of B

 A# = POW(B,C)   'A = B raised to the power of C

C modulus operator %

The C modulus operator % , functionally, is equivalent to the BCX FRACL function. BCX accepts % in BASIC expressions.

When using the modulus operator %, a space must be to the left and right of of the % symbol.


CORRECT: WHILE a % b

INCORRECT: WHILE a%b