Examples

The following examples are provided to illustrate the use of Accumath subroutines and functions in programs.

Future Value

This example computes future value based on present value, interest rate and time. The example uses the implicit precision mode BASIC subroutines. The entry, compilation and running of the program is shown below.

>ED BP FV
 Top
 001 * Calculate future value
 002 PRINT 'Enter present value : ':; INPUT PV
 003 PRINT 'Enter number of years : ':; INPUT T
 004 PRINT 'Enter annual percentage rate : ':; INPUT I
 005 * Calculate: FV = PV*(1+(I/100))^T
 006 CALL XDIV(I,'100.000000000000',W)  ;* sets precision to 12
 007 CALL XADD(W,1,X)                   ;* 1+(I/100)
 008 CALL XPWR(X,T,Y)                   ;* (1+(I/100))^T
 009 CALL XMUL(PV,Y,Z)                  ;* PV*(1+(I/100))^T
 010 CALL XPRC(Z,2,FV)                  ;* round to 2 places
 011 PRINT 'Future value = ':FV
 012 END
.FI
'FV' filed.
 
>BASIC BP FV
************
 
>RUN BP FV
Enter present value : ?10000
Enter number of years : ?5
Enter annual percentage rate : ?7.15102567111
Future value = 14124.78

Loan Amortization

This example uses the string math functions and the explicit precision mode (the string math functions by default use the explicit precision mode, and the BASIC subroutine XPWRX is the explicit precision version). Although the explicit precision mode is used, the precision is never explicitly specified, thus using the default precision (standard default precision is 14). In this example, the pre-compiler XP-BASIC is used to compile the program, rather than BASIC. The pre-compiler translates the string math functions into the appropriate OCONV() functions, and then enters the normal BASIC compiler.

>ED BP AMORT
 Top
 001 * Loan Amortization
 002 INCLUDE XP XPA.DEFS
 003 PRINT 'Enter principal: ':; INPUT PRINCIPAL
 004 PRINT 'Enter months   : ':; INPUT PERIODS
 005 PRINT 'Enter interest : ':; INPUT RATE
 006 RATE = SDIV(RATE,1200)
 007 CALL XPWRX(SADD(1,RATE),PERIODS,'',X)
 008 PAYMENT = SMUL(PRINCIPAL,SDIV(RATE,SSUB(1,SDIV(1,X))))
 009 PRINT 'Monthly payment = ':PAYMENT
 010 END
.FI
'AMORT' filed.
 
>XP-BASIC BP AMORT
**********
 
>RUN BP AMORT
Enter principal: ?250000
Enter months   : ?360
Enter interest : ?9.5
Monthly payment = 2102.1355179475