RE: PC-1211, PC-1250, etc. TVM
Hi, robve
If you have good EXP, LN, you can build accurate EXPM1 LNP1
(02-04-2019 07:28 PM)Dieters formula Wrote: expm1(x) = (u-1) - (ln(u) - x) * u, where u = exp(x), rounded
log1p( x ) = ln(u) - ((u-1) - x) / u, where u = 1+x, rounded
And, many thanks to your examples.
I actually discovered a Plus42 bug, for rate very close to 0%.
Code:
10 INPUT "B,N,P,M,F? ";B,N,P,M,F @ B=B*M
15 DEF FNZ(I,A,B,C) @ D=(A+B)/2 @ B=C*A @ FNZ=A+M+(D+B)*I @ D=D+2*B @ END DEF
20 DEF FNF(I) @ IF 1+I=1 THEN FNF=FNZ(I,(P+F)/N,P-F+B+B,(N*N-1)/12*I) @ END
25 S=-EXPM1(LOGP1(I)*-N) @ D=(P+F)/S*(1-N*(1-S)/(S+S/I))+(B-F)
30 FNF=(P+F)*I/S+(B-F)*I+M @ END DEF
40 X=(ABS(P)<ABS(F))*(P+F)-B @ I=M/(X-P) ! edge rate
50 Y=FNF(I) @ DISP 100*I,Y @ H=-Y/D @ I=I+H @ IF I+H*H<>I THEN 50
60 DISP 100*I
With FNF(I ≈ 0) added, updated version handled all your examples.
Some F values adjusted to true 10 digits accuracy, to test for I round-trip
Code:
>run ! 1
B,N,P,M,F? 1,40,900,-40,-1000
4.16666666667 -5.1783387869
4.7524512828 -.0080716937
4.75336718645 -.0000000187
4.75336718857
>run ! 2
B,N,P,M,F? 1,40,900,-400,-1000
66.6666666667 -66.666666756
79.9999999644 -.000000183
80.000000001
>run ! 3
B,N,P,M,F? 0,365*24*60*60,0,-0.01,331667.0067
-3.01507228575E-6 6.2977646195E-3
-1.1099216591E-7 7.022277322E-4
3.07577857109E-7 1.52692722E-5
3.17093002072E-7 7.8839E-9
3.17097920053E-7
>res * n
10.0000000068
>run ! 4
B,N,P,M,F? 0,365*24*60,0,-0.01,5527.7829015
-1.80904354932E-4 6.2977549796E-3
-6.659604136E-6 7.022284099E-4
1.84546671658E-5 1.52693549E-5
1.90255801086E-5 .000000007884
1.90258751918E-5
>res * n
10.0000000008
>run ! 5
B,N,P,M,F? 0,365*24*60,0,-0.01,5260.382426
-1.90100247286E-4 .005827435363
-2.255093023E-5 6.131837705E-4
-1.23294301E-7 1.15811689E-5
3.16928063661E-7 4.4651E-9
3.17097921621E-7
>res * 60*n
10.0000000563
>run ! 6
B,N,P,M,F? 0,32,-999999,0,1000000
0 .03125
3.12500161133E-6 0
3.12500161133E-6
>run ! 7
B,N,P,M,F? 0,360,0,-1000,1000000
-.1 2306.3389698
.313028391458 504.47068745
.47127071031 62.96905733
.497374290777 1.51994785
.498036166886 .00095669
.498036584011
Update: Code showed initial edge rate as well (previously hidden)
|