The user of BASIC can either use the predefined mathematical or string functions or can define special functions which the program will use. Specific HELP on functions may be obtained by typing HELP BASIC FUNCTION keyword where keyword is one of DEFINE User defined functions MATH Predefined BASIC mathematical Expressions STRING USEFUL Useful expressions for extending the Mathematical Function set. 3 DEFINE Basic has a limited number of built in mathematical functions Those which do not exist directly can easily be defined using the DEFINE FUNCTION statement of BASIC. DEFINE FUNCTION STATEMENT DEF FN (list) = expression DEF FN%(list) = expression DEF FN$(list) = expression where: IS AN ALPHABETIC CHARACTER (A-Z) THAT BECOMES PART OF THE FUNCTION NAME. % INDICATES THE FUNCTION RETURNS AN INTEGER VALUE. $ INDICATES THAT THE FUNCTION RETURNS A STRING VALUE (list) Contains from 1-5 dumy variables (var1,var2,var3,var4,var5) expression is evaluated each time the function is used. It may contain any of the dumy variables or any other variables in the program. 3 MATH SIN(expression) expression is an angle in radians COS(expression) ATN(expression) PI Returns the value of PI (3.14159) SQR(expression) Returns the square root EXP(expression) Returns the exponential function. LOG(exp) LOG10(exp) Returns the natural and base 10 logarithm. INT(exp) Returns the integer part of the expression. ABS(exp) Returns the absolute value the expression. SGN(exp) Returns +1 if the expression is positive, -1 if negative. RND Gives a pseudo random number from 0 to 1 each time it is used. The pseudo random numbers generated are randomized further by executing a RANDOMIZE statement within the program. If this were not done the random numbers generated each time the program is run would be the same. 3 USEFUL USEFUL EXPRESSIONS (where E is any expression) TAN(E) = SIN(E)/COS(E) SEC(E) = 1/COS(E) CSC(E) = 1/SIN(E) COT(E) = COS(E)/SIN(E) ASIN(E) = ATN(E/SQR(1-E*E)) ACOS(E) = ATN(SQR(1-E*E)/E) ASEC(E) = ATN(SQR(E*E-1)) ACSC(E) = ATN(1/SQR(E*E-1)) ACTN(E) = ATN(1/E) SINH(E) = (EEP(E)-EEP(-E))/2 COSH(E) = (EEP(E)+EEP(-E))/2 TANH(E) = (EEP(E)-EEP(-E))/(EEP(E)+EEP(-E)) ASINH(E) =LOG(E+SQR(E*E+1)) ACOSH(E) = LOG(E+SQR(E*E-1)) ATANH(E) = (LOG(1+E) - LOG(1-E))/2 3 STRING X% = LEN(A$) ; X% = length of string A$ B$ = TRM$(A$) ; trim trailing blanks off of string X% = POS(A$,B$,e) ; get the location X% in string A$ where ; string B$ occurs starting at the character ; position given by expression 'e'. B$ = SEG$(A$,e1,e2) ; copy the segment of A$ into B$ starting with ; character position given by expression 'e1' ; and ending with position 'e2' X% = ASC(A$) ; X% = decimal ASCII code for 1 character ; string A$. A$ = CHR$(X%) ; A$ = ASCII character given by decimal code X%. X = VAL(A$) ; X = number given by string expression A$ A$ = STR$(X) ; Convert number X to string A$. X% = BIN(A$) ; convert string A$(form "1010001" etc.) to a decimal ; number. X% = OCT(A$) ; convert octal string A$ to a decimal number.