Announcing a Bison based utility that implements an infix calculator supporting all the one argument double precision C math functions.
To give you an idea of what this utility is capable of, here's the readme file:
This is an infix calculator supporting all the C math routines that take one double precision floating point number. These functions are: COS, SIN, TAN, ACOS, ASIN, ATAN, COSH, SINH, TANH, LN (natural logarithm), LOG (base 10 logarithm), EXP, SQRT, CEIL, FLOOR, and FABS. Standard maths symbols are used: +, -, *, /, and ^ (for x raised to the power y) The left hand side of equations will be a DCL symbol that will either be created if it doesn't exist, or overwritten if it does exist. The symbol's string value will be a string representation of the double precision floating point value of the right hand side of the equation. As mentioned, the RHS can contain infix notation. It may also contain constant floating point values such as 0.5. These values do not need to be quoted. Variables on the RHS are expected to be symbols containing a string representation of a double precision floating point value. Mathamatical range and domain errors cause the operation to abort, and the DCL symbol's value on LHS not to be set. References to non-existant DCL symbols on the RHS, or references to symbols with invalid string values also cause the operation to abort. DCL symbol substitution is honoured on both sides of the equation. Build the software with Bison or just compile and link the C file that was generated by Bison. Assuming you have Bison correctly installed: $ bison/token/output=math.c math.y ! Skip this step if you don't have Bison $ cc math.c $ link math.obj $ math :== $dev:[dir]math Now let's look at some examples: $ math a = 1 $ show sym a A = "1.0000000000" $ math b == 8 $ show sym b B == "8.0000000000" $ math c = a + b $ show sym c C = "9.0000000000" $ math d = 2 ^ (sqrt (c) + 1) $ show sym d D = "16.0000000000" $ cnt = 1 $ math e'cnt = sqrt (9.5 + cnt) $ sh sym e1 E1 = "3.2403703492" $ math a = sqrt (-1.5) Invalid argument for SQRT - results undefined: math argument $ sh sym a A = "1.0000000000" $ math a = x DCL symbol "X" undefined - calculation not done $ sh sym a A = "1.0000000000" $ x = "NaN" $ math a = x DCL symbol "X" has illegal chars - result may not be what you intended $ show sym a A = "0.0000000000" Note we can assign values to symbols at either local or global scope with the use of the single or double equals sign. Take note of the value of A. Note how after the illegal square root operation it's unchanged. It's also unchanged after the attempted assign to X, which is not a DCL symbol. However, after we assign a string value to X, the calculator honours the fact that X is a symbol, prints a warning, assigns a value of zero to X in the calculator's internal symbol table, and then assigns that value to A.
You can get a zip file containing full source code, and a binary compiled and linked on Alpha 8.2 from the MATH section on the downloads page.
Please let me know if you come across any bugs.
Enjoy.
Posted at April 1, 2009 2:01 PMGreat. I can now do math in DCL. You may just have removed my last real motivation for getting really good at 3GL programming on OpenVMS :)
Seriously, though, good stuff.
Posted by: Kel at April 4, 2009 2:00 PM
Comments are closed