Looking for TVM contributions
|
05-24-2024, 03:04 PM
Post: #23
|
|||
|
|||
RE: Looking for TVM contributions
(05-15-2024 12:57 PM)dm319 Wrote: I had a go last night adapting the plus42 code into R and using the Rmpfr package which has arbitrary precision ... Plus42 algorithm to check Plus42 may not show numbers are accurate. Unless, of course, Rmpfr setup with much higher precisions to compensate. For better accuracy, we may apply time-symmetry. Plus42 core_commands9.cc Code: do_pv(): expm1(-n*log1p(i)) == (1+i)^-n - 1 The problem is with positive (n*i), and |n| is huge, expression approaches -1. Numerically, there are only so many representable numbers between -0.9 to -1.0 lua> expm1(-30), expm1(30) -0.9999999999999064 10686474581523.463 We may use time symmetry, turned n to -n: {n,i,pv,pmt,fv} --> {-n,i,fv,-pmt,pv} fv = -(-pmt * (-expm1(n * log1p(i)) / i) + pv * exp(n * log1p(i))) pv = -(fv - pmt * (-expm1(n * log1p(i)) / i)) / exp(n * log1p(i)) Plus42 core_commands9.cc Code: do_n(): do_n() is better if |fv| is small (best if fv=0) do_i_pct_yr() and do_pmt() is better if |pv| is small. (best if pv=0) Apply time-symmetry to reduce cancellation errors, we get tvm(n,i,pv,pmt,fv), and tvm_begin(n,i,pv,pmt,fv) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)