'===========================================================================
' Subject: ADDITIONAL MATH FUNCTIONS          Date: 08-17-00 (17:56)       
'  Author: Bruno Schaefer                     Code: RAPIDQ                 
'  Origin: bup.schaefer@planet-interkom.de  Packet: RAPIDQ.ABC
'===========================================================================
'>>>>>>   rq_math.inc   Version 1.0 (08-2000)<<<<<<<<<<<<<<<<<<<<
'##################################################
'##   Rapid-Q Mathematics                        ##
'##   written by Bruno Schäfer                   ##
'##   <bup.schaefer@planet-interkom.de>          ##
'##################################################
'   !!!!    All angles are in radiant !!!  (BUT NOT THE FUNCTION DEG2RAD)
'   If an ERROR occurs there will be a Messagebox
'   and the returned value is ZERO !!!!!
' Rapid-Q - http://www.basicguru.com/abc/rapidq/
'                 http://www.egroups.com/group/rapidq
' This .inc.-file  contains additional commonly used mathematical functions
' and utilities (in addition to the standard mathematical functions
' supported in William Yu's Rapid-Q)
' This is a work in progress, so don't expect too much.
' Try the functions you need for your work, accept them or throw them away...
' ...but many thanks for ideas and remarks:
' send an e-mail to (bup.schaefer@planet-interkom.de) or the rapidq-egroup.
' planned functions perhaps  in next versions:' different round methods,
' complex functions, vectoroperations, derivation, integral-functions,
' statistical functions( in own $includes ???)...,
CONST rqPI = 3.141592654 '(This is PI)
CONST rqE = 2.718281828  '(This is e)
'>>> declaration of the functions <<<
'.....
'###############################################################################
'   ACOSH() returns the hyperbolic areacosine of x
'###############################################################################
Function ACOSH(value AS DOUBLE) AS DOUBLE
  SELECT CASE value
   CASE IS < 1
    MessageBox("Invalid Argument !!!", "ACOSH - Error", 0) 
   CASE IS >= 1
    ACOSH =  ( LOG (value + SQR( value ^ 2 - 1 )))
  END SELECT
End Function
'###############################################################################
'   ACOT() returns the arccotangent of x
'###############################################################################
Function ACOT(value AS DOUBLE) AS DOUBLE
 ACOT = ((rqPI / 2) - ATAN (value))
End Function
'###############################################################################
'   ACOTH() returns the hyperbolic areacotangent of x
'###############################################################################
Function ACOTH(value AS DOUBLE) AS DOUBLE
 SELECT CASE ABS (value)
  CASE IS > 1
   ACOTH =  (LOG((value + 1) / (value - 1)) * 0.5)
  CASE ELSE        
   MessageBox("ERROR: Invalid Argument !!!", "ACOTH - Error", 0)     
 END SELECT
End Function
'###############################################################################
'   ACOSEC() returns the arccosecans of x
'###############################################################################
Function ACOSEC(value AS DOUBLE) AS DOUBLE
 SELECT CASE ABS (value)
  CASE IS < 1
   MessageBox("Invalid Argument !!!", "ACOSEC - Error", 0) 
  CASE ELSE          
   ACOSEC =  (ASIN(1/value))
  END SELECT 
End Function
'###############################################################################
'   ACOSECH() returns the hyperbolic arccosecans of x
'###############################################################################
Function ACOSECH(value AS DOUBLE) AS DOUBLE
 SELECT CASE ABS(value)
  CASE = 0
   MessageBox("Invalid Argument !!!", "ACOSECH - Error", 0) 
  CASE ELSE          
   ACOSECH =  (ASINH(1 / value))
 END SELECT 
End Function
'###############################################################################
'   ASINH() returns the hyperbolic areasine of x
'###############################################################################
Function ASINH(value AS DOUBLE) AS DOUBLE
 ASINH = LOG (value + (SQR(value * value + 1)))
End Function
'###############################################################################
'   ASEC() returns the arccosecans of x
'###############################################################################
Function ASEC(value AS DOUBLE) AS DOUBLE
 SELECT CASE ABS (value)
  CASE IS < 1
    MessageBox("ERROR:Invalid Argument !!!", "ASEC - Error", 0)
  CASE ELSE          
   ASEC =  (rqPI / 2 - ASIN( 1 / value))
 END SELECT 
End Function
'###############################################################################
'   ASECH() returns the hyperbolic arccosecans of x
'###############################################################################
Function ASECH(value AS DOUBLE) AS DOUBLE
 SELECT CASE ABS (value)
  CASE IS > 1
   MessageBox("ERROR:Invalid Argument !!!", "ASECH - Error", 0) 
  CASE IS <= 0
   MessageBox("ERROR:Invalid Argument !!!", "ASECH - Error", 0) 
  CASE ELSE          
   ASECH = (ACOSH(1 / value))
 END SELECT 
End Function
'###############################################################################
'   ATANH() returns the hyperbolic areatangent of x
'###############################################################################
Function ATANH(value AS DOUBLE) AS DOUBLE
 SELECT CASE ABS(value)
  CASE IS < 1
   ATANH = (LOG((1 + value) / (1 - value)) * 0.5)
  CASE 0
   COSH = 1
  CASE ELSE
   MessageBox("ERROR:Invalid Argument !!!", "ATANH - Error", 0) 
 END SELECT
End Function    
'###############################################################################
'   COSEC() returns the cosecans of x
'###############################################################################
Function COSEC(value AS DOUBLE) AS DOUBLE
 COSEC = 1 / SIN(value)
End Function
'###############################################################################
'   COSECH() returns the hyperbolic cosecans of x
'###############################################################################
Function COSECH(value AS DOUBLE) AS DOUBLE
 COSECH = (2 / (EXP(value) - EXP(value * -1)))
End Function
'###############################################################################
'   COSH() returns the hyperbolic cosine of x
'###############################################################################
Function COSH(value AS DOUBLE) AS DOUBLE
 COSH = (0.5 * (EXP(value) + EXP(value * -1)))
 IF value = 0 THEN COSH = 1
End Function
'###############################################################################
'   COT() returns the cotangent of x
'###############################################################################
Function COT(value AS DOUBLE) AS DOUBLE
 COT = 1 / TAN(value)
End Function
'###############################################################################
'   COTH() returns the hyperbolic cotangent of x
'###############################################################################
Function COTH(value AS DOUBLE) AS DOUBLE
 SELECT CASE value
  CASE 0
   MessageBox("ERROR: Invalid Argument !!!", "COTH - Error", 0) 
  CASE ELSE
   COTH = COSH(value) / SINH(value)
  END SELECT 
End Function
'###############################################################################
'   DEG2RAD() returns radians instead of degrees
'###############################################################################
Function DEG2RAD(value AS DOUBLE) AS DOUBLE
 DEG2RAD = value * 0.017453
End Function
'###############################################################################
'   FAC() returns the factorial of the integer x
'###############################################################################
Function FAC(value AS LONG) AS LONG
 SELECT CASE value
  CASE IS < 13  
   N = value      
   value = 1 
    For I = 1 to N
     value = value * I
    NEXT I 
   FAC = value
  CASE IS > 12
   MessageBox("ERROR: Invalid Argument !!! Argument must <= 12!", "FAC - Error", 0)
 END SELECT  
End Function
'###############################################################################
'   LOG10() returns the base 10 log of x
'###############################################################################
 Function LOG10(value AS DOUBLE) AS DOUBLE
  LOG10 = (LOG (value) * LOG(10 * rqE))
 End Function
'###############################################################################
'   RAD2DEG() returns degrees instead of radians
'###############################################################################
Function RAD2DEG(value AS DOUBLE) AS DOUBLE
 RAD2DEG = value / 0.017453
End Function
'###############################################################################
'   SEC() returns the secans of x
'###############################################################################
Function SEC(value AS DOUBLE) AS DOUBLE
 SEC = 1 / COS(value)
End Function
'###############################################################################
'   SECH() returns the hyperbolic secans of x
'###############################################################################
Function SECH(value AS DOUBLE) AS DOUBLE
 SECH = (2 / (EXP(value) + EXP(value * -1)))
' SECH = 1/ COSH (value)
End Function
'###############################################################################
'   SINH() returns the hyperbolic sine of x
'###############################################################################
Function SINH(value AS DOUBLE) AS DOUBLE
 SINH = (0.5 * (EXP(value) - EXP(value * -1)))
  IF value = 0 THEN SINH = 0
End Function 
'###############################################################################
'   TANH() returns the hyperbolic tangent of x
'###############################################################################
Function TANH(value AS DOUBLE) AS DOUBLE
  TANH = SINH(value) / COSH(value)
   IF value = 0 THEN SINH = 0
End Function
'###############################################################################
'>>>>> reserved words  <<<<<<
'RQPI,RQE,ACOSH,ACOT, ACOSEC, ACOSECH, ASEC, ASECH, ATANH, COSEC, COSECH, COSH, COT, COTH, 
'FAC, LOG10, SEC, SECH, SINH, TANH, DEG2RAD, RAD2DEG
