diff --git a/appendix/basic_commands.tex b/appendix/basic_commands.tex index 60bd446..7567805 100644 --- a/appendix/basic_commands.tex +++ b/appendix/basic_commands.tex @@ -2907,7 +2907,49 @@ \subsection{USR} \subsection{VAL} - +The {\ttfamily VAL} function returns a numeric value representing the characters in a string argument. Often a string +variable is passed to the function, but a literal string is also valid (eg. " -540.15 "). Blank characters ("spaces") +in the string are ignored. If the first non-blank character of the string is not a plus sign (+), minus sign (-), +dollar sign (\$), percentage sign (\%) or a digit the conversion ends with a value of zero (0). These initial special +characters signify the type of number to follow - Positive (+); Negative (-); Hexadecimal (\$), which then validates +the letters A,B,C,D,E \& F; Binary Literal (\%) eg. "010101"; and +Numbers (0123456789). Subsequent valid characters are additional digits (or the first decimal +point or E/e for Exponent). The function ends at the end of the string, or the next non-digit character for that numberic +type and returns the converted result. Subsequent digits after any non-valid characters are disregarded. +Other mathematical terms and arithmetic operations are ignored.\\ + +The valid range of possible numbers is from -1e+38 to 1e+38. Outside of this range the error "?OVERFLOW ERROR IN " +is shown and the program stops. When the argument isn't a string, the error "?TYPE MISMATCH ERROR IN " would +result and stop the program. When the argument is absent, the error "?SYNTAX ERROR IN " is returned and stops +the program.\\ + +\codeblock{ + 10 READ A\$\\ + 20 DATA " - 120 . 64 "\\ + 30 PRINT VAL(A\$)\\ +RUN\\ +-120.64\\ +} + +Examples:\\ + +Leading letters are invalid, but don't cause an error.\newline +\codeblock{ +PRINT VAL("ABC 123")\\ +0\\ +} + +The binary literal string is converted to decimal number.\newline +\codeblock{ +PRINT VAL("\%010101")\\ +21\\ +} + +The exponential notation string is returned as a simplified number.\newline +\codeblock{ +PRINT VAL("+352 .25 E-3 Units")\\ +0.35225\\ +} \subsection{VPEEK}