Yet another DIY RPN calculator
|
06-02-2021, 06:21 PM
(This post was last modified: 06-02-2021 06:29 PM by Albert Chan.)
Post: #19
|
|||
|
|||
RE: Yet another DIY RPN calculator
erfinv code had a hidden gem
With minor changes, adding a tail = 1 - |x|, we get *accurate* inverse erfc for free. Code: static double erfinv(double x, double tail) { Calling C from Lua, code is trivial Code: static int Lierf(lua_State *L) Note that tail is suggestive, throw away if x + tail ≠ 1 This make ierfc(x) easy to implement, even if x > 1 lua> for k, v in pairs(require'mathx') do _G[k]=v end -- get erf, erfc, ierf lua> ierfc = function(x) return ierf(1-x, x) end lua> x = erfc(5) lua> x, ierfc(x) 1.5374597944280351e-012 4.999999999999999 lua> x = erfc(10) lua> x, ierfc(x) 2.088487583762545e-045 10 lua> x = erfc(15) lua> x, ierfc(x) 7.212994172451206e-100 15 lua> x = erfc(20) lua> x, ierfc(x) 5.3958656116079005e-176 20 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)