Chapter 15: Expressions and The Expression Stack
177
TI
-
89 / TI
-
92 Plus Developer Guide
Not for Distribution
Beta Version January 26, 2001
15.6.2. Estack Calculations
Now lets modify the example to perform the calculation on the estack rather than
in BCD16 variables. This extension will be necessary if the function must handle
arguments other than floating-point numbers. If the arguments to a function can
be floats, rationals, symbolic constants, variables, expressions, or lists of any of
these, then the computations are best done on the estack. The changes use the
following features.
•
EStackIndexes are declared to point to the arguments and temporary results.
•
The system function
push_arg_plus_1
is used to add one to an argument.
•
The system function
push_exponentiate
is used to raise a value to a power.
•
The system function
push_product
is used to multiply two values.
•
The system function
delete_between
is used to delete temporary results.
void fv (void)
{ EStackIndex pv, ir, np, tmp; /* argument pointers */
/* point to the present value argument */
pv = top_estack;
/* point to the interest rate argument */
ir = next_expression_index (pv);
/* point to the number of periods argument */
np = next_expression_index (ir);
/* perform the future value calculation */
/* add 1 to the interest rate */
push_arg_plus_1 (ir);
/* point to the temporary result */
tmp = top_estack;
/* raise (ir + 1) to the np power */
push_exponentiate (tmp, np);
/* point to the temporary result */
tmp = top_estack;
/* multiply by the present value */
push_product (tmp, pv);
/* now the future value is on top of the estack */
/* delete intermediate results */
delete_between (pv, tmp);
}
This version of the example is longer and more complicated than either of the
previous versions. Thus, an obvious question is “what has been gained?” The
answer is a great deal of power and flexibility. This latest version does not care
about the types of the arguments. If all of the arguments are rational numbers,
the result will be a rational number. If the arguments are symbolic, the result will
be symbolic. If the arguments are of valid but differing types, they will be
combined in an appropriate way. If the arguments are not valid for the specified
calculation, an appropriate error will be reported.