Post Reply 
(32S) Accurate TVM with direct solutions
01-01-2016, 02:11 PM (This post was last modified: 01-01-2016 06:03 PM by Dieter.)
Post: #12
RE: (32S) Accurate TVM with direct solutions
(12-31-2015 02:08 PM)Dave Britten Wrote:  Whoops, I mis-transcribed it in my haste. I'll correct it above.

It still isn't perfect. The ln(1+x) code does not work for very small arguments where 1+x rounds to 1. In this case x+1–1 becomes zero and the following division throws an error. That's why the original (Kahan) code included a x≠y? test.This consumes one more stack level, but it doesn't hurt as the initial calculation of 100/I + B can be done later so this value does not have to be saved on the stack.

In general, there is no need for any temporary registers (here T and L), all this can be done on the stack.

(12-31-2015 02:08 PM)Dave Britten Wrote:  The 100 vs. 10^2 thing is a peculiarity of the way the 32S stores numbers. Integers from 0-99 take up 1.5 bytes. Anything else is 9.5 bytes. So 100 is 9.5 bytes, whereas 2 10^x is only 3 bytes.

I see. But still 10 x^2 is faster than 2 10^x, and there also is a percent function that returns x/100 with a simple 1 %. ;-)

Edit:
I could not believe the 0...99 limit, so I wanted to know what the 32s II manual says. Here is what I found on page 12-20/21:
"Numbers use 9.5 bytes, except for integer numbers from 0 through 254 which use only 1.5 bytes".

There you are: you can safely use "100" and "200" in your program and they still won't require more than 1.5 bytes.

Addendum:
Here is what I got – I hope there are not too many errors. ;-)

Code:
LBL T
INPUT N
INPUT I
INPUT P
INPUT M
INPUT F
INPUT B
1
RCL I
%
+
LastX
x<>y
LN
x<>y
LastX
1
x≠y?
-
/
x
RCL* N   ' = n * ln(1+i)
2
/
e^x
LastX
SINH
x
ENTER
+         ' = e^(n * ln(1+i)) - 1  =  (1+i)^n - 1
ENTER
RCL* P
RCL+ P    ' = pv * [(1+i)^n - 1] + pv =  pv * (1+i)^n
x<>y
RCL* M    ' = pmt * [(1+i)^n - 1]
100
RCL/ I
RCL+ B
x         ' = pmt * [(1+i)^n - 1] * (1/i + b)
+         ' + pv * (1+i)^n
RCL+ F    ' + fv
RTN       ' = tvm

At least it's shorter than the previous version (42 lines) and does not require any additional registers.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 35s - TVM from Gene Wright - PedroLeiva - 12-03-2015, 12:39 PM
RE: (32S) Accurate TVM with direct solutions - Dieter - 01-01-2016 02:11 PM



User(s) browsing this thread: 1 Guest(s)