VPCalc - Variable Precision floating decimal calculator Version 2.30, last revised: 1993-10-15, 1600 hours Copyright (c) 1981-1993 by author: Harry J. Smith, 19628 Via Monte Dr., Saratoga, CA 95070. All rights reserved. This is a Variable Precision floating decimal Calculator. It can compute with numbers of up to 114639 decimal digit each. At the Command: prompt, type a number, a primitive op code, an equation like: A = (12,345 + 2 * B * (C + D) / Sin(E + F)) ^ 2, or an If statement like: If A = B Then C = D Else C = E. Code files may contain Labels:, GoTo Label, and GoUpTo Label. Status: 1001 <- Max decimal digits allowed in mantissa 49 <- Current max decimal digits in mantissa 7 <- Decimal digits to truncate in display 42 <- Max decimal digits in display 1 <- Input lines (1, 2, 3, or 4) On <- Rounding mode On <- Degree Trig mode On <- Save Top Off <- Echo screen to printer Off <- Diagnostic mode MemAvail = 392664 **** PRESS ANY KEY TO CONTINUE OR F1 FOR HELP **** _ Running code file "AutoExec.VPC" Full name = A:\AUTOEXEC.VPC X = 0.0 (False) File "AutoExec.VPC" closed X = 0.0 (False) Command: _____________________________________________________________________ _ ------------------------------------------------------------------------------ - The "MemAvail = 392664" is an example output and refers to the amount of memory in 8-bit bytes that is available to dynamically- allocate space to store the variables as they are created and as they change in their number of significant digits. Numbers are stored in memory in decimal, actually they are stored in base 10,000,000, as an array of super-digits. Each super-digit is stored as a single precision floating point number between 0 and 9,999,999. As variables change in value, memory is dynamically reallocated so no more memory is used than is needed to represent their current precision. At any given time there is a current max decimal digits that will be computed for a mantissa and a max decimal digits to ever allow in a mantissa. These values are initialized to 56 and 1001 respectively and can be changed after the program is running. At the "Command:" prompt, commands may be entered one at a time each followed by a return, or several on a line separated by one or more spaces or semicolons. A separator is never needed between primitive op codes and is only needed otherwise to prevent ambiguity of meaning. Commands are not case sensitive, upper and lower case letters are always interpreted the same. There are four basic types of commands: 1) Enter a number, 2) Execute a primitive op code, 3) Evaluate an equation, and 4) Do a procedure. The calculator contains a list of named numbers or variables. Initially the list contains only the item X = 0.0. Its name is X and its value is 0.0. Items can be added to the list by evaluating an equation. Equations are assignment statements like = . A is a name of a variable and an is an expression of terms, factors, functions variables, constants, and s. Item names are limited to 250 characters with all characters significant but not case sensitive. Parentheses can be nested to any level in expressions. Any number of closing parentheses can be replaced with a single semi-colon or an end-of-line. Thus x = (a / (b * (c + d; is a legal assignment statement and is interpreted as (a / (b * (c + d))). Any time a variable is referenced that is not currently on the list, it is added to the list with a value of 0.0. At any given time, one item on the list is the active item. This is referred as the item on top of the list. Initially item X is the active item. When an expression is evaluated, the variable being assigned a value becomes the active item. If the part of an assignment statement is left blank, the referenced variable becomes the active item without changing its value. When a number is entered, it replaces the value of the active item. Numbers (constants) may have a leading sign and embedded commas. An example of a constant is -12,345.678,9E+1,234. The commas, plus signs, decimal point, and the E power of 10 factor are optional. The numbers 1.0E+1,50323,85525 is at the upper end of the dynamic range of the calculator. Because commas are allowed in input constants to make them readable, commas are not used to separate arguments in functions calls. An example of this is: X = Atan2(12,345' 78,901). A tic mark separates the two arguments instead of a comma as is normally done. If the program is executed from the DOS prompt with one or more parameters, the initial help menu is not displayed and the parameters are taken as an initial VPCalc command line. This allows you to control the execution of VPCalc from batch files and VPCalc code files with no operator intervention. The VPCalc code file AutoExec.VPC is always run first, even before the DOS command line commands. Special handling is given to the first parameter on the DOS command line. If it ends in .VPC, it is changed to Run("... .VPC") so this VPCalc code file will be run. If it ends in .VPN, it is changed to ReadN("... .VPN") so this VPCalc number file will be read and added to the list of items. This allows VPCalc to be run by shell programs, such as DosShell or XTree, by associating the file VPCalc.Exe with the extensions VPC and VPN, and then opening a file with one of these extensions. Primitives - Primitives that act on a number, acts on the currently active item. In the following description of primitives, the currently active item is called x for convenience. ? => General Help: This causes the help screens to be displayed. The first is the same as the screen displayed when you enter the program, but the values currently set by the D, E, H, M, T, U, V, and @ commands and set by the Diag(X), InputLines(X), SetD(X), and SetMax(X) proce- dures are displayed. The other 4 screens are as follows: ------------------------------------------------------------------------------ - The primitive op codes are: A => Auto Display on/off | T => Set digits to truncate B => Display learn line | U => Set rounding mode C => Change sign of x | V => Set non-rounding mode D => Set degree trig mode | W => Write number to file E => Set radian trig mode | X => Learn, Execute F => ! => Factorial | Y => Delete (Yank) number from list G => Set Digits/Group | Z => Output list H => Echo screen to printer/Log file | @ => Substitute Log file for printer I => Input number from file | " => Start/Stop file name or comment J => Run VPCalc code from file | % => Set FMB = x, FMB on list K => Execute learn line x times | / => x = x Mod FMB, FMB on list L => Reduce precision of x | $ => Restart M => Set digits in Mantissa | > => Write configuration: Config.VPC N => Generate a random number | < => Read configuration: Config.VPC O => x = 1 / x | ] => Write entry history: Hist.VPT P => Compute Pi | [ => Read entry history: Hist.VPT Q => Quit to end the program | ? => General Help R => Square root of x | F1 => Hot Help S => Square x | ESC => Interrupt a long process **** PRESS ANY KEY TO CONTINUE HELP OR PRESS ESCAPE **** _ ------------------------------------------------------------------------------ - The infix operators are: +, -, *, /, ^, @, #, %, \, &, |, <, =, >, <=, <>, >= A = X + Y => Set A to X plus Y A = X - Y => Set A to X minus Y A = X * Y => Set A to X times Y A = X / Y => Set A to X divided by Y A = X ^ Y => Set A to X to the power Y A = Y @ X => Set A to Atan2(Y over X) A = X # Y => Set A to Mag(X' Y) = SqRt(Sq(X) + Sq(Y)) A = X % Y => Set A to Mod(X' Y) = X Modulo Y A = X \ Y => Set A to GCD(X' Y) = Greatest Common Divisor A = X & Y => Set A to 1 if X and Y are not 0, else set A to 0 A = X | Y => Set A to 1 if X or Y, is not 0, else set A to 0 A = X < Y => Set A to 1 if X < Y, else set A to 0 A = X = Y => Set A to 1 if X = Y, else set A to 0 A = X > Y => Set A to 1 if X > Y, else set A to 0 A = X <= Y => Set A to 1 if X <= Y, else set A to 0 A = X <> Y => Set A to 1 if X <> Y, else set A to 0 A = X >= Y => Set A to 1 if X >= Y, else set A to 0 **** PRESS ANY KEY TO CONTINUE HELP OR PRESS ESCAPE **** _ ------------------------------------------------------------------------------ - ------------------------------------------------------------------------------ - The procedures supported are: AutoDisplay(X) => Set Auto display on if X <> 0, else off ClearHist => Clear history of previous operator entries Diag(X) => Set diagnostic mode on or off EchoScreen(X) => Echo screen to printer/Log file, on or off InputLines(X) => Set number of input lines (1, 2, 3, or 4) LogFile(X) => Substitute Log file for printer, on or off LX => LT => Restore LastTop to top of the list Next => Move to next item on the list (no argument) ReadN(F) => Read file F = "ccc...c", F is optional Restore/Save => Restore or Save Configuration, History, & List Run(F) => Run VPCalc code from file F, F is optional SaveTop(X) => Set "save top value in LastTop" on or off ScientificN(X) => Force scientific notation on iff X <> 0 SetD(X) => Set max decimal digits in display SetMax(X) => Set max decimal digits allowed in mantissa VPCIn(F) => Enter file name F = "ccc...c" for J command VPLOut(F) => Enter file name F = "ccc...c" for @ command VPNIn(F) => Enter file name F = "ccc...c" for I command VPNOut(F) => Enter file name F = "ccc...c" for W command Write(X) => Output X, (X may be "ccc...c", X is optional) WriteLn(X) => Write(X) and a line feed WriteN(F) => Write X to file F = "ccc...c", F is optional **** PRESS ANY KEY TO CONTINUE HELP OR PRESS ESCAPE **** _ ------------------------------------------------------------------------------ - The functions supported are: Abs(X) = AbsoluteValue(X) | LnL(X) = NaturalLog(X + 1) Acos(X) = ArcCoSine(X) | Log(X) = LogBase10(X) Acosh(X) = ArcHyperbolicCoSine(X) | Lop(X) = ReducePrecision(X) Asin(X) = ArcSin(X) | Mag(X' Y) = SqRt(Sq(X), Sq(Y)) Asinh(X) = ArcHyperbolicSine(X) | Mod(X' Y) = X - (Int(X/Y) * Y) Atan(X) = ArcTangent(X) | PowM(X' Y) = (X to the Y) Mod FMB Atan2(Y' X) = ArcTangent(Y over X) | RN(X) = RandomNumber(Seed=X) Atanh(X) = ArcHyperbolicTangent(X) | Sin(X) = Sine(X) Cos(X) = CoSine(X) | SinH(X) = HyperbolicSine(X) CosH(X) = HyperbolicCoSine(X) | Sq(X) = X Squared Exp(X) = eToThePower(X) | SqRt(X) = SquareRoot(X) ExpL(X) = Etothepower(X) - 1 | Tan(X) = Tangent(X) Fac(X) = Factorial of Int(X) | TanH(X) = HyperbolicTangent(X) Frac(X) = FractionalPart(X) | ToDeg(X) = RadiansToDegrees(X) GCD(X' Y) = Greatest Common Divisor | ToRad(X) = DegreesToRadians(X) Int(X) = IntegerPart(X) | -X = Negative of X, 0 - X Inv(X) = 1 / X | +X = Positive of X, 0 + X Ln(X) = NaturalLog(X) | !X = Not X, 0 -> 1 else 0 **** PRESS ANY KEY TO ENTER CALCULATOR MODE **** _ ------------------------------------------------------------------------------ - A => Auto Display on/off: Normally, after each command line is executed, the name and decimal value of the currently active item on the list is displayed. When computing with numbers with many significant digits, the time spent in producing this display can be excessively large. It is desirable then to be able to prevent this automatic display. Each time the A command is given the selection status of this option is reversed. A word about the displayed value is in order. As an example, if the first command line you enter after starting the program is 3O, the response will be: X = 3.33333,33333,33333,33...333,33333,33333,3 E-1 (42) [49] The E-1 means that X = 3.3... times 10 to the minus one, the 42 in parentheses means there are 42 decimal digits displayed, and the 49 in brackets means that X is stored in memory with 49 decimal digits of precision. The number in brackets is always a multiple of seven since an item's value is stored in memory in an array of super- digits of seven decimal digits each. B => Display learn line: The calculator contains a learned line, see the X primitive to enter and execute the learned line. The B command displays the current contents of the learned line. After the B command is executed, the F3 and F4 keys will restore the input line to the contents of the learned line instead of the previously typed command line. C => Change sign of x: This is the same as multiplying x by minus one. Negative numbers can be entered by preceding them with a minus sign. The x referenced here is the current active item on the list of vari- ables. D => Set degree trig mode (nominal): The trigonometric functions, Sin(X), Cos(X), Asin(X), Acos(X), Tan(X), Atan(X), and Atan2(Y' X), normally assume the angle involved in either the input or output is expressed in degrees. If radians are desired, use the E command. When degrees are desired, use the D command. The degree trig mode stays selected until changed by the E command. E => Set radian trig mode: The trigonometric functions, Sin(X), Cos(X), Asin(X), Acos(X), Tan(X), Atan(X), and ATan2(Y' X), normally assume the angle involved in either the input or output is expressed in degrees. If radians are desired, use the E command. When degrees are desired, use the D command. The radian trig mode stays selected until changed by the D command. F => ! => Factorial: Replaces x with the factorial of x = 1 * 2 * 3 * ... * x. Only the integer portion of x is used in the calculation. G => Set Digits/Group: The G command will set the number of digits per group to the current value of x. If this is set to 3, numbers will be displayed with a comma after every 3rd digit like 1.234,567,89 E+34,457. If this is set to less than 1, no commas will be displayed. H => Echo screen to printer/Log file: The H command causes all output to the screen to be echoed to the printer or to a disk file. See the @ primitive command for opening a file for this purpose. Each time the H command is given the selection status of this option is reversed. I => Input number from file: The I command will use the last entered comment as a file name and read this file as a VPCalc formatted number and assign it to the current active item. It is assumed that the file was created by the W command. See the W command for the format of file names. If a comment has not been entered, the file name NoName.VPN is used. The VPNIn procedure can be used to give an override file name for the I command. As files are input by the I command, the most significant bit of each byte read is set to zero to allow the files to be created or modified by a text editor that uses these upper bits as flag bits. J => Run VPCalc code from file: The J command will use the last entered comment as a file name and read this file as a text file. Each line of the file will be interpreted as a VPCalc command line and executed. If comment commands and J commands exist in the text file, these other referenced files will be opened and processed. The only limitation to this nesting of code files is the availability of memory and buffers. If a comment has not been entered, the file name NoName.VPC is used. The VPCIn procedure can be used to give an override file name for the J command. As files are input by the J command, the most significant bit of each byte read is set to zero to allow the files to be created or modified by a text editor that uses these upper bits as flag bits. K => Execute learn line x times: This will cause the learned line to be executed x time. x must be in the range 0 <= x <= 2,147,483,647 (2^31 - 1). The x referenced here is the current active item on the list of variables. If x is larger than this max, then the max will be used. A long repetition of a learned line can always be interrupted by using the ESC key. L => Reduce precision of x: This command removes or Lops off the least significant super-digit of x. If rounding is turned on, the removed super-digit is used to round into the new least significant super-digit. In VPCalc numbers are normalized from both sides. If a calculation results in a number with some trailing zero bytes, these bytes are removed, the count of the number of bytes in the mantissa is reduced and memory is reallocated. The L command can result in many bytes being removed if removing one byte results in many trailing zeros. M => Set digits in Mantissa: The M command will set the current value of the maximum number of decimal digits allowed in a floating point number to the current value of x. If there are items on the list containing more than this number of digits, they will be reduced to contain at most this number of digits. Some messages output by the calculator contain the name FMC. For example, the message "Error in Pi, FMC = 143" would be given if you were running at 1001 decimal digits of precision and the value if Pi stored in file "Pi.VPN" had less than 143 super-digits. FMC is the current max number of super-digits in a floating point number. If x is not a multiple of 7, when the M command is given, then the next higher multiple of 7 is used. If x is less than 14, it is set to 14. N => Generate a random number: The N command generates a random number between zero and 1.0 and assigns it to the current active item on the list. This number will never have more than 35 significant decimal digits. Theoreti- cally the random number generator will cycle after 10 ^ 35 numbers, but the earth will not last that long. The items RN, RNA, and RNC are put on the list by the random number command. The equation used is: x = RN = (RNA * RN * 10^35 + RNC) mod (10^35) / 10^35, where RNA and RNC are 35 digit integers. O => x = 1 / x: Replace x with 1.0 divided by x, error if x = 0. P => Compute Pi: If Pi is on the list, then x = Pi. If Pi is not on the list, the file Pi.VPN is read-in, Pi added to the list, and x = Pi. If the file Pi.VPN is not found, Pi is computed by algorithm b. Algorithm b is documented in Scientific American, Feb 1988, Ramanujan and Pi, by Jonathan M. Borwein and Peter B. Borwein. Pi = 3.14159,26535,89793,23846,26433,83279,50288 E+0 (36) [49] Q => Quit to end the program: The program exits back to the operating system with no questions asked. R => Square root of x: x is replaced with the positive square root of x, error if x < 0. S => Square x: x is replaced with the square of x. T => Set digits to truncate: The T command will set the number of decimal digits to truncate for display to the current value of x. The calculator is initialized with this set to 7 decimal digits. U => Set rounding mode: This command sets rounding on. When rounding is on, the results of all numerical operations are rounded to the maximum number of bytes in mantissa. When rounding is off, these results are truncated to the maximum number of bytes in mantissa. Use the M command to set the maximum number of bytes in mantissa. The IEEE standard of round to even is used, e.g., all numbers in the closed interval [11.5, 12.5] round to 12. V => Set non-rounding mode: This command sets rounding off. When rounding is off, the results of all numerical operations are truncated to the maximum number of bytes in mantissa. Use the M command to set the maximum number of bytes in mantissa. W => Write number to file: The W command will use the last entered comment as a file name and write register x into this file as a VPCalc formatted number. This number can be reread into x by the I command. If the file already exists, it will be erased and recreated. For example, the following are valid file names: "File.Ext" File.Ext is on default drive and directory "B:FileName.Ext" FileName.Ext is on B: drive, current B: directory "Pi.VPN" PI.VPN is on default drive and directory "C:\Direct\File.Ext" File.Ext is on C: drive, Direct directory If the file name does not have a period, the extension .VPN is added. If a comment has not been entered, the file name NoName.VPN is used. The VPNOut procedure can be used to give an override file name for the W command. The file written is a text file and can easily be browsed and read by other programs. The contents of the file for 1/7 is: <3 blank lines> OneOver7 = m.n E-1, m.n = 1. 42857 14285 71428 57142 85714 28571 42857 14285 71428 57142 85714 E-1 (56) <51 blank lines> Page 1 <4 blank lines> X => Learn, Execute: If this is the last command on a command line, then it caused the learned line to be executed once. If not the last command on the line, this command stores all the commands following on the same line as this one into the learned line. Execution of the current line is stopped. This line, like every command line, is limited to 250 characters. Type the learned line: X =0 Fact=1 X =X+1 Fact=Fact*X Z X and then do two separate X commands. You might want to key in an H command before the second X command to turn your printer on. This will print a table of factorials from 2! to (1.70854E+9)! or so, if you wait long enough. Hit the ESC key twice to interrupt and abort the operation if you get tired of waiting. After the X command is executed, the F3 and F4 keys will restore the input line to the contents of the learned line instead of the previously typed command line. Y => Delete (Yank) number from list: The Y command removes the currently active item from the list and makes the next older item the active item. The age of an item is judged by when it was created. X is always the oldest item and is never removed from the list. If the Y command is executed, when X is the active item, X is not removed, but the youngest item becomes the active item. Thus, a long string of Y commands will always remove all items from the list except X. Z => Output list: The Z command will display the name and value of all items on the list. Some items may be found on the list that were not explicitly put there. The item Pi is put on the list by the P command and when needed by the trig functions. The item Ln10 = Ln(10) is put on the list when needed by the exponential functions. The items RN, RNA, and RNC are put on the list by the random number command N. The items RNA and RNC are put on the list by the random number function RN(X). The item File: "comment" is put on the list by the "comment" command. The item Lrn: is put on the list by the X command. The items File: "comment" and the item Lrn: also have a value associated with them, normally = 0.0. This value has no meaning and is not used.